From: Chris Mason <clm@meta.com>
To: Donet Tom <donettom@linux.ibm.com>
Cc: Chris Mason <clm@meta.com>, David Hildenbrand <david@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>, Zi Yan <ziy@nvidia.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ritesh Harjani <ritesh.list@gmail.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Alison Schofield <alison.schofield@intel.com>,
Yury Norov <yury.norov@gmail.com>,
Dave Jiang <dave.jiang@intel.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Subject: Re: [PATCH v2] drivers/base/node: Handle error properly in register_one_node()
Date: Wed, 17 Sep 2025 06:45:56 -0700 [thread overview]
Message-ID: <20250917134604.2149316-1-clm@meta.com> (raw)
In-Reply-To: <20250822084845.19219-1-donettom@linux.ibm.com>
On Fri, 22 Aug 2025 14:18:45 +0530 Donet Tom <donettom@linux.ibm.com> wrote:
> If register_node() returns an error, it is not handled correctly.
> The function will proceed further and try to register CPUs under the
> node, which is not correct.
>
> So, in this patch, if register_node() returns an error, we return
> immediately from the function.
>
> Fixes: 76b67ed9dce6 ("[PATCH] node hotplug: register cpu: remove node struct")
> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> ---
> v1 -> v2
> Made the changes based on Oscar’s review comments.
>
> v1 - https://lore.kernel.org/all/20250702112856.295176-1-donettom@linux.ibm.com/
> ---
> drivers/base/node.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index c65b4917794e..1608816de67f 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -883,6 +883,11 @@ int register_one_node(int nid)
> node_devices[nid] = node;
>
> error = register_node(node_devices[nid], nid);
> + if (error) {
> + node_devices[nid] = NULL;
> + kfree(node);
> + return error;
> + }
Can this cause a double-free? Looking at register_node(), when
device_register() fails, it calls put_device(&node->dev). The put_device()
call triggers node_device_release() which does kfree(to_node(dev)), freeing
the entire node structure. So when register_node() returns an error, the
node memory is already freed, but this code calls kfree(node) again on the
same memory.
The call chain is: register_node()->device_register() fails->
put_device()->node_device_release()->kfree(to_node(dev)).
[ This came from automated patch review, but it looks real to me ]
-chris
next prev parent reply other threads:[~2025-09-17 14:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 8:48 Donet Tom
2025-08-22 9:48 ` David Hildenbrand
2025-09-17 13:45 ` Chris Mason [this message]
2025-09-17 14:55 ` Donet Tom
2025-09-17 21:48 ` Andrew Morton
2025-09-18 4:49 ` Donet Tom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250917134604.2149316-1-clm@meta.com \
--to=clm@meta.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=alison.schofield@intel.com \
--cc=dakr@kernel.org \
--cc=dave.jiang@intel.com \
--cc=david@redhat.com \
--cc=donettom@linux.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=rafael@kernel.org \
--cc=ritesh.list@gmail.com \
--cc=yury.norov@gmail.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox