From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 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== 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== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 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) 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== 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) From: Anh Nguyen Hoang via B4 Relay Date: Tue, 01 Dec 2026 21:43:25 -0600 Subject: [PATCH net] devlink: fix bus name copy size in notify filter set X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-kbug-l1233-v1-1-e42766f6d4d9@gmail.com> X-B4-Tracking: v=1; b=H4sIANyTD2sC/yWMwQqDMBAFf0XeuQE3i6X0V6SHJK52W4kl0VIQ/ 91YjzMwsyJLUsm4VyuSfDXrFAvQpUJ4ujiI0a4wbG2vZGsyb78MZiTLbJrAHZNj7+iGEnyS9Pr 7z1pEmfE4ZV78S8J8bLBtO2xLbvdzAAAA X-Change-ID: 20261201-kbug-l1233-5c3d31a3ba18 To: Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Simon Horman , netdev@vger.kernel.org, stable@vger.kernel.org, Anh Nguyen Hoang 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 Reply-To: anhnh.4work@gmail.com Content-Transfer-Encoding: 7bit From: Anh Nguyen Hoang 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 --- 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