🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Anh Nguyen Hoang via B4 Relay Wed, 02 Dec 2026 03:43
[PATCH net] devlink: fix bus name copy size in notify filter set
#25597
Author: Anh Nguyen Hoang via B4 Relay
Date: Wed, 02 Dec 2026 03:43
79 lines
13771 bytes
From: Anh Nguyen Hoang <anhnh.4work@gmail.com>

devlink_nl_notify_filter_set_doit() stores the bus name and the device
name in one buffer of data_size bytes, the sum of both attribute lengths
plus their terminators. The bus name is copied with nla_strscpy() using
the whole data_size as the destination size, and the return value plus
one is added to data_offset without checking it.

The policy does not limit the length of either string, so the sum can
exceed U16_MAX. nla_strscpy() then triggers WARN_ON_ONCE() and returns
-E2BIG without copying. Adding -E2BIG + 1 to data_offset, a size_t,
makes pos point 6 bytes before flt->data, inside the filter header. The
device name copy fails the same way and flt->dev_name is set to the bad
pos. The command still returns 0 and attaches the broken filter. It
does not require any capability, so an unprivileged user can trigger:

  WARNING: lib/nlattr.c:779 at nla_strscpy
  Call Trace:
  devlink_nl_notify_filter_set_doit

Pass the size of the bus name's own part of the buffer to nla_strscpy()
and advance by that size. Each copy is now bounded by one attribute
length plus one, which never exceeds U16_MAX, so nla_strscpy() cannot
fail.

Found by an automated code-checking tool. The warning was reproduced
in QEMU with an unmodified kernel by sending the command with two 40000
byte names as an unprivileged user. With the fix the same request
returns 0 without a warning or KASAN report, and filtering of netdevsim
notifications by bus and device name works as before.

Fixes: 13b127d25784 ("devlink: add a command to set notification filter and use it for multicasts")
Cc: stable@vger.kernel.org
Signed-off-by: Anh Nguyen Hoang <anhnh.4work@gmail.com>
---
An alternative is to limit DEVLINK_ATTR_BUS_NAME and DEVLINK_ATTR_DEV_NAME
in the notify-filter-set policy. That changes the netlink spec and starts
rejecting requests accepted today, so the copy is fixed locally instead.

Tested on net 250b42eb17b7, x86_64 defconfig + NETDEVSIM + KASAN, in QEMU:
as uid 1000, two 40000 byte names gave the nla_strscpy warning before the
patch and none after. Sockets filtered to netdevsim10 and netdevsim99 got
2 and 0 notifications for netdevsim10 add/del, before and after the patch.

Testing:
- Compile-tested on x86_64 (allmodconfig, W=1): net/devlink/netlink.o;
  no new warnings.
- checkpatch.pl --strict: no errors or warnings.

This patch was drafted with AI assistance (Claude, claude-fable-5-2).
---
 net/devlink/netlink.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index a8eda727bff1..75fe1074609c 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -62,9 +62,8 @@ int devlink_nl_notify_filter_set_doit(struct sk_buff *skb,
 
 	pos = (char *) flt->data;
 	if (attrs[DEVLINK_ATTR_BUS_NAME]) {
-		data_offset += nla_strscpy(pos,
-					   attrs[DEVLINK_ATTR_BUS_NAME],
-					   data_size) + 1;
+		data_offset = nla_len(attrs[DEVLINK_ATTR_BUS_NAME]) + 1;
+		nla_strscpy(pos, attrs[DEVLINK_ATTR_BUS_NAME], data_offset);
 		flt->bus_name = pos;
 		pos += data_offset;
 	}

---
base-commit: 250b42eb17b7986e9a2cf7f1de6142aced72b64f
change-id: 20261201-kbug-l1233-5c3d31a3ba18

Best regards,
--  
Anh Nguyen Hoang <anhnh.4work@gmail.com>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads