From patchwork Wed Jan 15 10:30:57 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: 1223292 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=uSFh79iC; 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 47yNsJ6s68z9sNx for ; Wed, 15 Jan 2020 21:31:16 +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:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xRAra2ow4ESgMm/0twaIqzss9h6jaBdaXzrSsBAsyNc=; b=uSFh79iC+j/0cw azcOg0szo1M2IU2BrQNal7EK0iWO2DHredj7NhxFR+q3Q481875c85pu80omCfHewdQpeQf0ZseyX jKdt+UhBDwPdm5dA4s9GAnag93K75yq+ACn3uTLcVkJNDivPQkhpSh1uA80LJfmc3q2oCYJJnlUWc 5+ygLq1grPbs+aEOxqY8HwSgfVBhwZGyFIS2yvtD7JIBIxc9r4meu4k8FxcCn99kOFsHHYRihs76h LHMnpkbRln9xVZ6z40iwoxeVnlmPLta1dqbFtVJFJ+smV9gndmUl/Ir4MZlWsmfPbCsVr46OOnWw/ EwtDk7YuJikoTLb4+XfA==; 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 1irfxB-0008Hw-8v; Wed, 15 Jan 2020 10:31:13 +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 1irfx5-00089W-OP for openwrt-devel@lists.openwrt.org; Wed, 15 Jan 2020 10:31:12 +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 6A967690A; Wed, 15 Jan 2020 11:31:06 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id af2aa80f; Wed, 15 Jan 2020 11:30:56 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Wed, 15 Jan 2020 11:30:57 +0100 Message-Id: <20200115103057.7665-2-ynezz@true.cz> In-Reply-To: <20200115103057.7665-1-ynezz@true.cz> References: <20200115103057.7665-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200115_023107_943682_90B3C7C8 X-CRM114-Status: UNSURE ( 9.07 ) 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 2/2] 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 one `pidfile` attribute case in instance_config_move() where the new value of `pidfile` is being copied/assigned. Source of this value is then free()d in following 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 --- service/instance.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/instance.c b/service/instance.c index ce5233807dbb..245b9629d99a 100644 --- a/service/instance.c +++ b/service/instance.c @@ -1031,7 +1031,6 @@ 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; @@ -1042,6 +1041,10 @@ instance_config_move(struct service_instance *in, struct service_instance *in_sr 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->config); in->config = in_src->config; in_src->config = NULL;