X86 platform drivers
 help / color / mirror / Atom feed
From: yahia <yahia.a.abdrabou@gmail.com>
To: W_Armin@gmx.de
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	yahia ahmed <yahia.a.abdrabou@gmail.com>
Subject: [PATCH v2] wmi/core: fix use-after-free in wmi_add_device()
Date: Mon, 22 Jun 2026 22:04:09 +0300	[thread overview]
Message-ID: <20260622190409.17268-1-yahia.a.abdrabou@gmail.com> (raw)
In-Reply-To: <8b505aea-2c76-4868-b30c-be34ce0eb761@gmx.de>

From: yahia ahmed <yahia.a.abdrabou@gmail.com>

Hi Armin,

You are correct about kzalloc_obj overriding wblock and
I apologize, However there is a different use-after-free
specifically in wmi_add_device() function, where if device_add()
fails, the function forwards the return code, then the caller
function parse_wdg() frees wblock from memory, but doesnt remove
wblock from pdev's list, thus if pdev calls wblock for any reason
like suspendension or similar activities, it will call freed memory,
hence the use-after-free.

I propose to fix this by adding device_link_del() function
if device_add() function fails, remove wblock from pdev's
list, thus avoiding a possible use-after-free.

Signed-off-by: yahia ahmed <yahia.a.abdrabou@gmail.com>
---
 drivers/platform/wmi/core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/wmi/core.c b/drivers/platform/wmi/core.c
index 5a2ffcbab6af..8c9b7ac2e5d8 100644
--- a/drivers/platform/wmi/core.c
+++ b/drivers/platform/wmi/core.c
@@ -1261,6 +1261,7 @@ static int wmi_create_device(struct device *wmi_bus_dev,
 static int wmi_add_device(struct platform_device *pdev, struct wmi_device *wdev)
 {
 	struct device_link *link;
+	int ret;
 
 	/*
 	 * Many aggregate WMI drivers do not use -EPROBE_DEFER when they
@@ -1275,7 +1276,11 @@ static int wmi_add_device(struct platform_device *pdev, struct wmi_device *wdev)
 	if (!link)
 		return -EINVAL;
 
-	return device_add(&wdev->dev);
+	ret = device_add(&wdev->dev);
+	
+	if (ret)
+		device_link_del(link);
+	return ret;
 }
 
@@ -1418,7 +1424,7 @@ static int wmi_notify_device(struct device *dev, void *data)
 		return 0;
 
 	/* The ACPI WMI specification says that _WED should be
-	 * evaluated every time an notification is received, even
+	 * evaluated every time a notification is received, even
 	 * if no consumers are present.
 	 *
 	 * Some firmware implementations actually depend on this
-- 
2.54.0


  reply	other threads:[~2026-06-22 19:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22  0:02 [PATCH] wmi/core Fix use-after-free in parse_wdg() yahia
2026-06-22 14:45 ` Armin Wolf
2026-06-22 19:04   ` yahia [this message]
2026-06-22 19:18     ` [PATCH v3] wmi/core: fix use-after-free in wmi_add_device() yahia
2026-06-22 19:45       ` Armin Wolf
2026-06-22 20:25         ` Re " yahia
2026-06-22 20:45           ` Armin Wolf
2026-06-22 20:57             ` yahia
2026-06-22 21:19               ` Armin Wolf
2026-06-23  0:12                 ` yahia
2026-07-01  4:19                   ` Armin Wolf
2026-07-01  9:42                     ` yahia
2026-07-03 12:28       ` Ilpo Järvinen
2026-07-03 16:45         ` yahia

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=20260622190409.17268-1-yahia.a.abdrabou@gmail.com \
    --to=yahia.a.abdrabou@gmail.com \
    --cc=W_Armin@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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