From patchwork Wed Jan 3 15:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1881983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xr2qq1hD; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=By9e61su; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4v2v6ZN3z1ydb for ; Thu, 4 Jan 2024 02:36:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=eYN5hBRGlct6h2Ilxhbh7bXGjtiSIuCJHT/WnGaT+gw=; b=xr2qq1hDDEwshF KrvUVtKzcVgu/ErqbuBSXdQllT4wSBS/8v2/WvNetu0MT7Hf7+YQx0mkywYn0eqbvDToJsa2ZBTdK wS8C2dlG4uB/4/QA4SBn96J0zk418EYpuD0fxcPcGolTO3+/7D8I9cF1mipXahJwLCyxiE1KFpZJD tSFJlJtD6bWJqRIPUZvVF+Ml7sIj5G4KsLKvGLZ+RUxQYobj2F5J9iSkqsIMGcVJ3aFBjN3+wmHVB MC535+hwEJky/lrF1lQ0maecVGrTlvwLbs5ISJ48ZLY6r87n0d5qWadjRktnlOuRzjGt+q14KT6WA P/PMhpKsiu0Xrk3R7Bqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rL3Hi-00BGzw-32; Wed, 03 Jan 2024 15:35:58 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rL3Hg-00BGz8-0w for linux-mtd@lists.infradead.org; Wed, 03 Jan 2024 15:35:58 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 8B96360010; Wed, 3 Jan 2024 15:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1704296150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PiImE412lJQgqtEGLZrMYE42Z6p53awQ3y9c75mFNDQ=; b=By9e61sulWU151JLCX9Kf4WXZbx2KAgoCAaK6j41OOUEZrL5RhL+b74NyQcjZN8q0KdT27 QsHKGXuhWfborC4k9I2AAhUuXruwdlSFdnPyeBOHYH+fS2rkTOCp3x1c/0A2t4hY7oCI4d uyu5OotSq+ZtavdbIRyKEoXhyKfoquyNKUYvLjqvkGtwAddge/DcSsg8w09xOyavO71oDc q0WvYUQrg87a1aVIZZIRcwvBsRyL8mw2oihp1g/DUfMIqMVz3dcwRaUM8UG27/siytwV4k 8ZN84WT/dp+MHgRK6gs5cq9Yd7nE7o2ymR6tXJVXAFyGkVdFHOEjxO2xUcXbAg== From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Pratyush Yadav , Michael Walle , Cc: Miquel Raynal , kernel test robot , Julia Lawall , Christian Marangi , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH] mtd: Fix possible refcounting issue when going through partition nodes Date: Wed, 3 Jan 2024 16:35:49 +0100 Message-Id: <20240103153549.106681-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240103_073556_633225_72886591 X-CRM114-Status: GOOD ( 12.48 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Under "normal" conditions, the loop goes over all the partitions, and 'breaks' when the relevant partition is found. After the break and outside the loop, of_node_put() is called to release the 'parti [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.195 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [217.70.183.195 listed in wl.mailspike.net] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Under "normal" conditions, the loop goes over all the partitions, and 'breaks' when the relevant partition is found. After the break and outside the loop, of_node_put() is called to release the 'partitions' of_node. However if no partition matches (I'm not sure this is a real-world use case), the loop terminates normally and of_node_put() gets called on the head of the list, meaning of_node_put() will be called twice on the loop header, which is not appropriate. Reported-by: kernel test robot Reported-by: Julia Lawall Closes: https://lore.kernel.org/r/202312250546.ISzglvM2-lkp@intel.com/ Cc: Christian Marangi Cc: Rafał Miłecki Signed-off-by: Miquel Raynal --- This is compile-tested only. --- drivers/mtd/mtdcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index bb0759ca12f1..1049d8223898 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -620,11 +620,11 @@ static void mtd_check_of_node(struct mtd_info *mtd) if (plen == mtd_name_len && !strncmp(mtd->name, pname + offset, plen)) { mtd_set_of_node(mtd, mtd_dn); + of_node_put(partitions); break; } } - of_node_put(partitions); exit_parent: of_node_put(parent_dn); }