Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23FEE2E5415 for ; Wed, 1 Oct 2025 11:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759319718; cv=none; b=arh1+EtYrxC/a8ICQc5drrwVq92lnTHvXEMXpIX3gyS7lb0T7zLmwSGQCMj9dmknmi5lfrCbCjt2n8kwMISs3pnM0fhlzzkX3YRYk9neU3otyirQIOlmgX7M8BQlnw9yZVTub30RhEq0HaKj/aKgNrvBAq25x91erkqNvWPO2Uc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759319718; c=relaxed/simple; bh=ScTJB0hT7dqI+ID7ebQcWmGZrbAwKJNaYji+uI5POy4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JKXmZUHnwt3QmaWr9xk/Lf/8idyXwBHsd/zu4tg71af4ow4ApqhBSKkV/dElCiYCtEFmwWRJSa8NIMZ0nHrbiF1/haQJUnfOhPUQlUQRRFATtb7SmsqSbeEenOazgnH0EFn1kdiuvqrdJOsv5VWwBuXH6qaimwu/q5UmDRamjC4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MSaZSFua; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MSaZSFua" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87991C4CEF4; Wed, 1 Oct 2025 11:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759319718; bh=ScTJB0hT7dqI+ID7ebQcWmGZrbAwKJNaYji+uI5POy4=; h=From:To:Cc:Subject:Date:Reply-to:From; b=MSaZSFuaFMsB/yiYe60GMix8zZWHxtZnVPBHbDZJrN2UTk/5WE3i7cRkJHiJCgqnc +10expMpGPQ5pgbhM4barXqvYJFU50czOaZ7XUR4YEXb7D2Qs1DRYML4vEQmZjquaD QmUjfMBI0wa4heGRz4Hg13z56l6iNK4vKZkqZyT4= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50457: mtd: core: Fix refcount error in del_mtd_device() Date: Wed, 1 Oct 2025 13:45:27 +0200 Message-ID: <2025100118-CVE-2022-50457-da35@gregkh> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3619; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=8fvIXp7Icd4SLy/4b3GeovnoHQA0yEVwwSyAhrdyhLo=; b=owGbwMvMwCRo6H6F97bub03G02pJDBl3Rfx5gw4t2/8lVqjKZs2lyunrf5ef3y5pOTF3ucz75 Rn7bYrNOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAi744wzLO/3OpkYS9f/01i W6mMuFr9y8Of3BgW9JR7P+KqfXPMw9Wgu/7sQruNfe1+AA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: mtd: core: Fix refcount error in del_mtd_device() del_mtd_device() will call of_node_put() to mtd_get_of_node(mtd), which is mtd->dev.of_node. However, memset(&mtd->dev, 0) is called before of_node_put(). As the result, of_node_put() won't do anything in del_mtd_device(), and causes the refcount leak. del_mtd_device() memset(&mtd->dev, 0, sizeof(mtd->dev) # clear mtd->dev of_node_put() mtd_get_of_node(mtd) # mtd->dev is cleared, can't locate of_node # of_node_put(NULL) won't do anything Fix the error by caching the pointer of the device_node. OF: ERROR: memory leak, expected refcount 1 instead of 2, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node /spi/spi-sram@0 CPU: 3 PID: 275 Comm: python3 Tainted: G N 6.1.0-rc3+ #54 0d8a1edddf51f172ff5226989a7565c6313b08e2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: dump_stack_lvl+0x67/0x83 kobject_get+0x155/0x160 of_node_get+0x1f/0x30 of_fwnode_get+0x43/0x70 fwnode_handle_get+0x54/0x80 fwnode_get_nth_parent+0xc9/0xe0 fwnode_full_name_string+0x3f/0xa0 device_node_string+0x30f/0x750 pointer+0x598/0x7a0 vsnprintf+0x62d/0x9b0 ... cfs_overlay_release+0x30/0x90 config_item_release+0xbe/0x1a0 config_item_put+0x5e/0x80 configfs_rmdir+0x3bd/0x540 vfs_rmdir+0x18c/0x320 do_rmdir+0x198/0x330 __x64_sys_rmdir+0x2c/0x40 do_syscall_64+0x37/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd [: Light reword of the commit log] The Linux kernel CVE team has assigned CVE-2022-50457 to this issue. Affected and fixed versions =========================== Issue introduced in 5.17 with commit 00596576a05145a1b5672897a82ef87af00becf4 and fixed in 6.0.16 with commit f6016557f1ef7735963bd8691592d2797bbf91d2 Issue introduced in 5.17 with commit 00596576a05145a1b5672897a82ef87af00becf4 and fixed in 6.1.2 with commit 616dc895d982026f41f500c88d1bfea004938cc8 Issue introduced in 5.17 with commit 00596576a05145a1b5672897a82ef87af00becf4 and fixed in 6.2 with commit 56570bdad5e31c5c538cd6efff5c4510256e1bb4 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-50457 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: drivers/mtd/mtdcore.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/f6016557f1ef7735963bd8691592d2797bbf91d2 https://git.kernel.org/stable/c/616dc895d982026f41f500c88d1bfea004938cc8 https://git.kernel.org/stable/c/56570bdad5e31c5c538cd6efff5c4510256e1bb4