From: Borislav Petkov <bp@alien8.de>
To: Weilin Tong <tongweilin@linux.alibaba.com>
Cc: Yazen Ghannam <yazen.ghannam@amd.com>,
Tony Luck <tony.luck@intel.com>,
linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Qinyun Tan <qinyuntan@linux.alibaba.com>
Subject: Re: [PATCH] EDAC/amd64: Fix double free of private data on registration failure
Date: Thu, 5 Nov 2026 16:02:05 -0800 [thread overview]
Message-ID: <20261106000205.GBau0Y_faMvFp2_fM6@fat_crate.local> (raw)
In-Reply-To: <20261021062925.1838750-1-tongweilin@linux.alibaba.com>
On Wed, Oct 21, 2026 at 02:29:20PM +0800, Weilin Tong wrote:
> If edac_mc_add_mc_with_groups() fails, init_one_instance() calls
> edac_mc_free(), which frees mci->pvt_info. probe_one_instance() then
> accesses and frees the same private data, causing a use-after-free
> and a double free.
>
> Clear mci->pvt_info before calling edac_mc_free() to leave the cleanup
> to probe_one_instance(). The normal remove path already clears it.
>
> Fixes: 0bbb265f7089 ("EDAC/mc: Get rid of silly one-shot struct allocation in edac_mc_alloc()")
> Cc: stable@vger.kernel.org
Stable because?
Are you triggering this or some tool/AI caught it?
> Reported-by: Qinyun Tan <qinyuntan@linux.alibaba.com>
> Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
> ---
> drivers/edac/amd64_edac.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
> index 0c0d11c72925..edced7cbe83f 100644
> --- a/drivers/edac/amd64_edac.c
> +++ b/drivers/edac/amd64_edac.c
> @@ -3975,6 +3975,7 @@ static int init_one_instance(struct amd64_pvt *pvt)
> ret = -ENODEV;
> if (edac_mc_add_mc_with_groups(mci, amd64_edac_attr_groups)) {
What a mess this code is with passing pvt up and down the chain and making it
so easy for people to mess up the responsibilities of who is supposed to free
allocated memory... :-\
> edac_dbg(1, "failed edac_mc_add_mc()\n");
In any case, this line needs a comment explaining why this ptr is getting
cleared because it is not trivial just from staring at it.
Something about probe_one_instance() as the one who allocates the memory, how
that one should be the only one which frees that same memory.
> + mci->pvt_info = NULL;
> edac_mc_free(mci);
> return ret;
> }
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2026-11-06 0:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 6:29 Weilin Tong
2026-10-24 15:09 ` Yazen Ghannam
2026-11-06 0:02 ` Borislav Petkov [this message]
2026-11-06 3:44 ` [PATCH v2] " Weilin Tong
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=20261106000205.GBau0Y_faMvFp2_fM6@fat_crate.local \
--to=bp@alien8.de \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qinyuntan@linux.alibaba.com \
--cc=stable@vger.kernel.org \
--cc=tongweilin@linux.alibaba.com \
--cc=tony.luck@intel.com \
--cc=yazen.ghannam@amd.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
all inboxes | Powered by JetHome®