Article View: linux.kernel.netdev
Article #25597[PATCH net] devlink: fix bus name copy size in notify filter set
From: Anh Nguyen Hoang via B4 Relay
Date: Wed, 02 Dec 2026 03:43
Date: Wed, 02 Dec 2026 03:43
79 lines
13771 bytes
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>
Technical Details
Message-ID:
<20261201-kbug-l1233-v1-1-e42766f6d4d9@gmail.com>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375530-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375530-linux-kernel-netdev=dewy.ru From: devnull+anhnh.4work.gmail.com@kernel.org (Anh Nguyen Hoang via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net] devlink: fix bus name copy size in notify filter set Date: Tue, 01 Dec 2026 21:43:25 -0600 Organization: Usenet Network Message-ID: <20261201-kbug-l1233-v1-1-e42766f6d4d9@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1880119"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:jLQaajhHrjoRzJswNfxXnv6iPnQ= sha256:9oqrG1ypaeyvkGHsH4qUPyKGGJZYoDTVy4q+uYcg/Z0= sha1:wJHNeH9l66tknyetzjsI3O8WUls= sha256:+FO9vrf1Jopa9Wn1un+diQoNYtJYcvoDeVM3hPmT+cw= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id F3C46117549; Wed, 2 Dec 2026 06:43:45 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -0.401 X-Spam-Status: No, score=-0.401 tagged_above=-9999 required=6.31 tests=[BIGNUM_EMAILS_FREEM=2.999, DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CQ9dzTgLMFNZ; Wed, 2 Dec 2026 06:43:43 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375530-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id AC3E5117547; Wed, 2 Dec 2026 06:43:33 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 4BD1E2984B; Wed, 2 Dec 2026 03:43:32 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796183012; b=b54YZEmVBvynk3hZfhsRxzTMNHkM7KHol2RrV6Uqb46GpVXoudRZQMXMN5jQmN3CeDLa SbagXEoqfSV0anTYkjfEwW8xqsr8TpKUGPVaB1uRjMh9BckI8ZcgBAXXl+TV6eiDdvbtg W5KPKNNZKpkotAo4JANEgAIdHQKgKSFj6aopJf4CHhI6I9E45/pShKjWsWsEV5Kyp5paO ysl/OqPbA2ehUayWiTFxovL3ydmX3vQXy3Pgne0bKokhHuWiMJammrqxFRrxbf2JUZWZE 2/HmbEoNI5G6qtM/pdMfjXwr9+oVVqRx08ioXiIEFTYcTDABbVpH/+NjzufqUGpOdVA== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796183012; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+PgY5XeRMiNcxqUNhqwVcqh3EvCzpGENnF4ujh/QegY=; b=EDI8GKZyBDWZ40pcga0aVsjC2jPWxLqCVmSDgkQDvO+WBFl32yp20JxKvGDpG2yczpqI Ywlh84nMcQgh61Vn1RfLIH57t76W/I2YPv0e0Jnz6/Lfyc35csJvPxP1FiirLrgeLQRrb pRlFi5sKVmEZlwSX0PwrDvVdnRZHmpu0mFyFG9y4omXrB44lVKbrY+3DPLHv9BrT1Whjo 4JLk4vRXhdgTskilx+MVYNi8VwQByth8X1nrnh4xN42+P+H8QlinFi6ojKkiy+2d0ugYv c00qVFlErx3bnc9YOHz69uDRMr3y3xo9nxioQI7Ou06e0FCladBl2oCojRk559ZTnnA== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="aPJ/J4vp"; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22F77606A32A; Wed, 2 Dec 2026 03:43:32 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aPJ/J4vp X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796183006; b=N9OCdaYfi5+u6xr+S9es7EETgNRP8voc17xHnVR2y8NdjEiI5lee6ZOS8Z+KiWQZ1boB Rop4f5xcztIgf31edx4ewJol5jrHqbXien0q44Zk+ZghNiiwVPH6RdjpjniFOVmD7cWm7 MUyYYbePNwfx5+sEAVGo0QYUEDnx4wHCOkEDVzxCP11GAXc4tWrznQkvyL3KewxGf9nXf iim7jEMO7/S0KGaTojH3oppcIvojVFaFI8dsrpmp8IavIXqmaVq16bwZs+gmwBLoXomYP QOQy+Ii73+ZL0BTOYsUAQECu8dJJADUGvEFnHChIswdyTU90o/GmXIEa1Gnu0gSukiA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796183006; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+PgY5XeRMiNcxqUNhqwVcqh3EvCzpGENnF4ujh/QegY=; b=wr6eMKLEqVtMceonfDGdf9ud2N0nFWYdzBa4kmz8VpP9YfsTkLmRXJYKFvx2a7UUFTPT vWJX0D0djV/94JuqkmbxnZYa/x3MwJI05M+k6k0Uwb2ELF9pW2jAqNeNA5Kfr2DgT2E1i WRdUtknLT8bqSCC6g9GlgEv5KaFp1hgq1wFcwjAOnY+MGYtuHNjSh0iEOdgban5p1ZlI9 D7YGbpn7g7A3JG6HrVcVIeBC/qqDpRtVN2G+Av0sSkBPTfM/+alqm2sBw/nTMtQewZzH0 zteIeHZo45e9b6RcBHcOn7jY56WJGiHy1RxLJRLRuMNLpKhuDH0ZJD2X48Oe+laFHgg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="aPJ/J4vp"; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CB27606A31A; Wed, 2 Dec 2026 03:43:25 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796183005; b=i3lt5N1oLQCzoh5hRK7DGLEv38HY2IrXF1Y08v5ifelTZC/oyUvv5/aeqZeToeKJs7W5 Rf+MfPkMpGkyg7jNDnzUmWCHm3wUVpx7RVKQ2Lf3boHLszUMi4J7fHYgshbiDDeah2/cv TKgc44p6DrkY9Wv3g4rC7IPNR1GmAQTGcuMOSZcXCDRm9kbCgCTWA5RRTyj9vpcsLKdm+ xGKWimyOas6Cy16ODweYdk7mLGT/7PFI25o3RFuhdmtu6MsZi7ap1eWlWoSTtusz26QwW aimC5HVnv7QsT3FYYt6kQMsXUibpHaKFa8TAKm3/ifSN3zMqR7TopjXryhgdi2MJbjA== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796183005; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+PgY5XeRMiNcxqUNhqwVcqh3EvCzpGENnF4ujh/QegY=; b=JzGPCI8Iy5fbykwarc7B1CkYKMSFzSpatH/5RiiMjfnPz2z+k6zjZPo4HIWlovl1kk1U jk8VQA3yg2wf9UCbkhTph6lUM7JWkJBq65AGAxFVnHzh/ziTcS1Xu8c6uac9dbl1owBZC rNiI6aXl67R+Ie/yXd9fv/K2D65nIC9X9vhP6jXLT9v4j3tyn+6p96g4Zbei65axV2u6z PjTFo9G+2Cb5Gijy6JDvF4+0DDt+IUpniPXclsE66RWLeaYsycVQcD153p+dvouSnhlWO 3xEXYYUGyFhc3fjSO7+ECiOP0M/jeOu8ODsYX4WcdR34Huk9dsTio08VSZO+TAWaBRQ== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 30EFE1F00893; Wed, 2 Dec 2026 03:43:25 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796183005; bh=+PgY5XeRMiNcxqUNhqwVcqh3EvCzpGENnF4ujh/QegY=; h=From:Date:Subject:To:Cc:Reply-To; b=aPJ/J4vpyUkTdjGkMLQcWPaRO6IGP8l88Hnw2D5TLqLxdnlrWvFvhWtsAkvKN/+Ju vSR0D0X/8ozjIgbenv9VQTJY19vChZmfobnSK5a2Nx9ASxukHVAP0uu5TLJRuM3eVE n6HqB9wDf+paU++Ks26OEqWMwnMiOt83ky9MdZ6n/FseLn5YkfdKIwa6H9eGORB14k oFL+/YzyLFnItyfDKHdGC5+VuK++JpmVRl61NKua4a2DWhG+vIINJUWw6pojitRhnO XGmm2B7Ev3UAw/Es32BECaTp46J3H5N5OTBVfGXNilHBXw5wE2AcB1WGqE2/2/zJz+ vTXKVSJasv0Mg== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id AFFDA4F22B; Wed, 2 Dec 2026 03:43:24 +0000 (UTC) X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-B4-Tracking: v=1; b=H4sIANyTD2sC/yWMwQqDMBAFf0XeuQE3i6X0V6SHJK52W4kl0VIQ/ 91YjzMwsyJLUsm4VyuSfDXrFAvQpUJ4ujiI0a4wbG2vZGsyb78MZiTLbJrAHZNj7+iGEnyS9Pr 7z1pEmfE4ZV78S8J8bLBtO2xLbvdzAAAA X-Change-ID: 20261201-kbug-l1233-5c3d31a3ba18 X-Cc: Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, stable@vger.kernel.org, Anh Nguyen Hoang <anhnh.4work@gmail.com> X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796183004; l=3303; i=anhnh.4work@gmail.com; s=20261127; h=from:subject:message-id; bh=CEDQTCGFq+jCAuN4Rv5CMp3K+MBb6mT2C7XFl1dbhIM=; b=Yn6D02lh0VdxxCYX7hQTEByzJOFM0carsyoEGVw5yr5PLfJGy+683NSaaelOmK9Nvdl/0EiIB ahbvzug92teCNMAywS9Kyi2tvfRT+Yg7acQhRHCvcOCTImM9o6OtuYc X-Developer-Key: i=anhnh.4work@gmail.com; a=ed25519; pk=9NJ/0SKqaFZmt1/I5XY11TZSNY2ys6RWB3gvqzrLHmI= X-Endpoint-Received: by B4 Relay for anhnh.4work@gmail.com/20261127 with auth_id=1662 X-Original-From: Anh Nguyen Hoang <anhnh.4work@gmail.com> X-Reply-To: anhnh.4work@gmail.com