From patchwork Wed Jan 15 16:53:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1223722 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=E2x/KAve; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yYM11ZKyz9sR0 for ; Thu, 16 Jan 2020 03:54:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version: Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=xLut+7XE5zdcTxO4fRNDneLEYGs2xSiAH7syN/ruX/s=; b=E2x/KAveBma6F9 AsqW4NEdH5b2K79sCOXMssSxNuthbXw2/vzxZo2lknGxjNkRFojDaHXkHcMaXQdmDzLTVjdapXpOU tQrXtdFaXoN4qVRFat89XL3oOaQlNBKE0wsJnqMYgVKSRglQU+SqeLS5UeNMqWhkRJ9SKKJzN+CJg r4Ip4AsPSo2WJCQCOjXE7HKSFJktMnJOlL+LBPPcBNvu0g9MqTSA5fwxVnU1aFzVESFqQxhzkGV2m X846Qn6OusojC0no4sbRdwAjZhz1OPeRkPVWbfrekXNd7cWZ7CnUiW+fE5y/twTDk4j+NB7mEjTXz K9bWqud21V7izFpQr/sg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1irlvZ-0007pS-5D; Wed, 15 Jan 2020 16:53:57 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1irlvT-0007oc-MG for openwrt-devel@lists.openwrt.org; Wed, 15 Jan 2020 16:53:56 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id A81B46D1F; Wed, 15 Jan 2020 17:53:47 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 2a2795d1; Wed, 15 Jan 2020 17:53:37 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 15 Jan 2020 17:53:44 +0100 Message-Id: <20200115165344.27358-1-ynezz@true.cz> MIME-Version: 1.0 In-Reply-To: <20200115110333.GA2350@makrotopia.org> For-Header-Readers: Hi! X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200115_085351_873493_26A0C4AD X-CRM114-Status: UNSURE ( 8.92 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH procd v2] instance: fix pidfile attribute double free crash X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= , Daniel Golle Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Commit a5af33ce9a16 ("instance: strdup string attributes") has introduced duplication of various string attributes in order to fix use-after-free, but missed handling of `pidfile` and `seccomp` attribute cases in instance_config_move() where the new value of `pidfile` or `seccomp` is being copied/assigned. Source of this values is then free()d in subsequent call to instance_free() and then again for 2nd time during the service stop command handling, leading to double free crash: #0 unmap_chunk at src/malloc/malloc.c:515 #1 free at src/malloc/malloc.c:526 #2 instance_free (in=0xd5e300) at instance.c:1100 #3 instance_delete (in=0xd5e300) at instance.c:559 #4 instance_stop (in=0xd5e300, halt=true) at instance.c:611 Ref: FS#2723 Cc: Daniel Golle Fixes: a5af33ce9a16 ("instance: strdup string attributes") Signed-off-by: Petr Štetiar --- changes since v1: * added missed fix for `seccomp` attribute (Daniel) service/instance.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/service/instance.c b/service/instance.c index ce5233807dbb..8fd44a80d6e5 100644 --- a/service/instance.c +++ b/service/instance.c @@ -1031,17 +1031,23 @@ instance_config_move(struct service_instance *in, struct service_instance *in_sr blobmsg_list_move(&in->jail.mount, &in_src->jail.mount); in->trigger = in_src->trigger; in->command = in_src->command; - in->pidfile = in_src->pidfile; in->respawn = in_src->respawn; in->respawn_retry = in_src->respawn_retry; in->respawn_threshold = in_src->respawn_threshold; in->respawn_timeout = in_src->respawn_timeout; in->name = in_src->name; in->trace = in_src->trace; - in->seccomp = in_src->seccomp; in->node.avl.key = in_src->node.avl.key; in->syslog_facility = in_src->syslog_facility; + free(in->pidfile); + if (in_src->pidfile) + in->pidfile = strdup(in_src->pidfile); + + free(in->seccomp); + if (in_src->seccomp) + in->seccomp = strdup(in_src->seccomp); + free(in->config); in->config = in_src->config; in_src->config = NULL;