mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Weilin Tong <tongweilin@linux.alibaba.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Yazen Ghannam <yazen.ghannam@amd.com>,
	Tony Luck <tony.luck@intel.com>,
	linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	Qinyun Tan <qinyuntan@linux.alibaba.com>
Subject: [PATCH v2] EDAC/amd64: Fix double free of private data on registration failure
Date: Fri,  6 Nov 2026 11:44:37 +0800	[thread overview]
Message-ID: <20261106034449.1659689-1-tongweilin@linux.alibaba.com> (raw)
In-Reply-To: <20261106000205.GBau0Y_faMvFp2_fM6@fat_crate.local>

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()")
Reported-by: Qinyun Tan <qinyuntan@linux.alibaba.com>
Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
v2:
- Explain why probe_one_instance() retains ownership of pvt on failure.
- Drop the stable Cc.
- Add Yazen's Reviewed-by.
- Rebase onto ras/edac-for-next (28f141ff14c48).

v1: https://lore.kernel.org/linux-edac/20261021062925.1838750-1-tongweilin@linux.alibaba.com/

 drivers/edac/amd64_edac.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index a8e76a79833b..d4abc5200ea1 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -3973,6 +3973,11 @@ static int init_one_instance(struct amd64_pvt *pvt)
 	ret = -ENODEV;
 	if (edac_mc_add_mc_with_groups(mci, amd64_edac_attr_groups)) {
 		edac_dbg(1, "failed edac_mc_add_mc()\n");
+		/*
+		 * probe_one_instance() allocates pvt and frees it on failure.
+		 * Keep edac_mc_free() from freeing it here.
+		 */
+		mci->pvt_info = NULL;
 		edac_mc_free(mci);
 		return ret;
 	}

base-commit: 28f141ff14c48abd38518a87d1026851dd12717e
-- 
2.43.7


      reply	other threads:[~2026-11-06  3:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  6:29 [PATCH] " Weilin Tong
2026-10-24 15:09 ` Yazen Ghannam
2026-11-06  0:02 ` Borislav Petkov
2026-11-06  3:44   ` Weilin Tong [this message]

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=20261106034449.1659689-1-tongweilin@linux.alibaba.com \
    --to=tongweilin@linux.alibaba.com \
    --cc=bp@alien8.de \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qinyuntan@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®