Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH rtw-next] wifi: rtw89: debug: return the error when a read handler fails
@ 2026-10-15 18:11 Devin Wittmayer
  2026-10-19  5:49 ` Ping-Ke Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Devin Wittmayer @ 2026-10-15 18:11 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless, stable

I hit this while testing an RTL8922AU patch. Reading read_reg in debugfs
before choosing a register set off a kernel BUG that killed the reader.
It does the same every time on an RTL8852BU:

  rtw89_8852bu 2-1:1.0: invalid read reg len 0
  usercopy: Kernel memory exposure attempt detected from SLUB object 'kmalloc-8k' (offset 56, size 262144)!
  kernel BUG at mm/usercopy.c:102!

After that the driver cannot be unloaded, and on my test box network
configuration hung until a power cycle. Without hardened usercopy the
reads return kernel memory instead, and cat kept reading until I
stopped it.

The read path passes the handler's error to the copy as a length, and
saves it for reads at a later offset. Return the error before the copy.

  RTL8852BU over USB                 before    after
  read_reg, nothing chosen
    6.18.52                          BUG       -EINVAL
    7.2.6                            BUG       -EINVAL
    6.18.52, hardened usercopy off   256 KB    -EINVAL
  mac_mem_dump at offset 1,
  after a failed read
    6.18.52                          BUG       -ENOENT
    7.2.6                            BUG       -ENOENT
    6.18.52, hardened usercopy off   256 KB    -ENOENT

  RTL8922AU over USB                 before    after
  read_reg, nothing chosen
    7.2.6                            BUG       -EINVAL
  mac_mem_dump at offset 1,
  after a failed read
    7.2.6                            BUG       -ENOENT

Fixes: 831cceed3baf ("wifi: rtw89: debugfs: implement file_ops::read/write to replace seq_file")
Cc: stable@vger.kernel.org
Signed-off-by: Devin Wittmayer <lucid_duck@justthetip.ca>
---
 drivers/net/wireless/realtek/rtw89/debug.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw89/debug.c b/drivers/net/wireless/realtek/rtw89/debug.c
index 3a430bd08..3b7f8a809 100644
--- a/drivers/net/wireless/realtek/rtw89/debug.c
+++ b/drivers/net/wireless/realtek/rtw89/debug.c
@@ -185,6 +185,9 @@ static ssize_t rtw89_debugfs_file_read(struct file *file, char __user *userbuf,
 	debugfs_priv->rused = n;
 
 out:
+	if (n < 0)
+		return n;
+
 	return simple_read_from_buffer(userbuf, count, ppos, buf, n);
 }
 
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-19  5:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15 18:11 [PATCH rtw-next] wifi: rtw89: debug: return the error when a read handler fails Devin Wittmayer
2026-10-19  5:49 ` Ping-Ke Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox