From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796422848; b=Le4ALI+nfC8Lk10tAxeZvfjNJzeh3TvO6G6gJLywSs1GK3Qg0MD2wW0vwNbiBrabw58L r56tHpBRYweuP+tkBROmWZrIn/HBk5TucvwcARgdvKZHyLg6rj122ep3wnp6Y5Pti+Tr7 lT7uARR1eWTn+w25AAU3uTcdTEGLHJBra0WznPCCB9IIexN+TjuBUHECSj77eJJyGCmGc ITiouVUH+3CGlfoh2oTSRc9PxEjPxcVVd3i2SfuuiJsbhHMwAoCFYviqkrbIcyBJuqFXq YjaOv473U2xMGAmb+rnN4XwrMJM57DQRZ9kIHk3mNZm7D2iJs0LT8PBS224wA2830Pg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796422848; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=GWshcyLTniTVXhDuHDp+47NH9iBFBWAWDwPEe4CEa3c=; b=dVGiQ4e6h2kLDaFDWmpeyOEHpRz/f7bHY/diry6GSB/9IfgqMR7v8sK4WAJZwvetiBlQ JYbWaXfMi4igtxzwOysT1AF6uni+2dBv5XnkzLr8PGvJ/I8FZHNaChrXEfzWY7hy41NYU ppQNUBv+9YYifJIdDctgLN1Z+w2aHjrPKb2ZBFBaOs8BAyKEjbXP+LgfcBCm+fMNK6Qi+ EWG6bb3IKbrlvthdYv5KGfrn9e+TjPq2JqR+kfMLOeAtQwAz5oK1ogzSoUhj3TnP6FX6+ EojOoRk1lW5YKuVeDyhA6lCwPH9H+ImbGTul4V2CaK3u1kYEsTR62KKNQjHUjyuU8Ug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bairaktaris.de; spf=pass smtp.mailfrom=bairaktaris.de; dkim=pass header.d=bairaktaris.de header.i=@bairaktaris.de header.a=rsa-sha256 header.s=google header.b="XH/An/ca"; arc=none smtp.remote-ip=209.85.218.49 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E9DF606A33E for ; Fri, 4 Dec 2026 22:20:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E9DF606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bairaktaris.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bairaktaris.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bairaktaris.de header.i=@bairaktaris.de header.a=rsa-sha256 header.s=google header.b=XH/An/ca Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-c5255770bf8so282067166b.0 for ; Fri, 04 Dec 2026 14:20:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bairaktaris.de; s=google; t=1796422847; x=1797027647; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GWshcyLTniTVXhDuHDp+47NH9iBFBWAWDwPEe4CEa3c=; b=XH/An/caw2/P4jrWSTLNVfK6R67tjeDbbE3mk8bFC6XxFhbhy7pKpBA06ebbohrd9F gMGSKi/T5dRKPxpx7bIvWXD9AC/7Y0OpSnDWwJMzlH6/zn3KVoqJcMNe0vR7MFvY+1+c MdNThEIjK4wic3jv5I9nloCUAx8WxxgwZlElPNfZiqT4wgC2O3P2/IrwXnbHDKtqBNnD eon9buPB7ARfi/85BjB4YiJ+0rwstszQDTTBTUM9X5+NQZp+YTxEo47SEVgxHikkGKHC /NZX2bFnTUgYDbxnrL1R9cce2j1auuFjxh+m35KfkXBKLk3l8fpdw6fiwUqfy5elTxNB QK0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796422847; x=1797027647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GWshcyLTniTVXhDuHDp+47NH9iBFBWAWDwPEe4CEa3c=; b=fPH/PNgrTFeyuEH86D6B2V2B3FfYiI2z63YJaLYNmhiukRvMAHeLiQzYAabHQbt/sL kIVi8AGq7mziWym47KFrrhQy5Rn5XKOmTSxBRYT7jUBCX8GNB123pItgC4DiMxSd+13v UHAI8WIHVM0EtUAg2CcyMlziQerHuzxneEr9bReaxeKXiINPvAqvROQ+AEvBcZT43iaq RDBZIJdS2SL9nX/hZMTHXaCEsROFmfEwCvfspbQhl5KRVXoZhFXV6SD9vT9cTlJ97ngA qQmHaA0W+KweP/PBRVXQiIyZBE2T+0atzpggbhZ7QDTEDNcgWa1OE7E303+xg79FHMRQ yk8g== X-Gm-Message-State: APuU4Z8gH7sncYRLwxCvGzaRUEsjCDDLsW2nKwM3a5Uv6S+9D0HQ9RHR RUBhfrQx46MdzY3vo+Ndy4tqAmG/Z1JmMOZiyl/St1CSJ5NPTbxLG6+kA9xT9GDIlA== X-Gm-Gg: AZFdTZdIIqAZ7VMWIsGgxETFFzGE1hrykCXFd7E6qRj7zoqZXT0E7NOPek8C1GSAcOP tz8ANWJyDrlsGhpIVfooQ7t66DNpfuZ6Jjd0YEx8ludb6Pm7ogf6PmiEHY9R4NJipSy30mOTeqZ X428BeCFr0OF5pJDKvCK+QIervLIUWF1CcNftGHrDi9NYzDEDuyPM8Zj/D6OhPq9FK+kBp6MaKT WvFkp4FdqxvX8MmmzLvtlgO1vjXnli2ZKSOfCckLNAQLKfYmt71nOCB5xKQgMtF45SSbZyxifyp 0EwKtQtfNFkUooqUxkTPXDMVR8yfa3Zmi9kkKyZEqIOHwVC2+GR505LukpVZJZWPoCSA8/sbaBy gQ4L4U34Osmxc5/J2SDhPxRXRr5OG0CG4gxFuLz75YPHDp/x7bm8SZQfdIniW7sa/9DSVJL6Uai 95wxDuR9+GhkuCQCiel4KleJrYQb0sxb89XmAUOzW0twClE5MZNKa1xCGu6G3hOEVSamrKPz5+a tRYwdoeBQClJLzaJDQE4qQ5qsq3ClvMO/rePe9VTW/n6OJxk+jv3GfX89tm6YCEaRGCBRHfVkzJ +ennzyPFjTFZH+kskCsS9qP8VLduC32DDEthDvKkqTUJ3+NsQrwaiTAWAkHrk46RXpXSz622Qht YdyDxNAGZPPCG2g2A6BqlW2hR6F4y58EuTXoEamBk0EYjUA6Hz9O08rEZWJjciT6faa8N/2+v5u vAHFPIZN+n/ACZZOo9P/6D2mPsUOcKPw8ZQh/jXfWmIb31R2zEQPhZYE8BZBDYfAydoGiP7UoXF me1LfL0AdS7dTrCABL6reI1UtAHkEXARu8fzxBsTIELF6vQdngqTt1zKDqb140rKK5eRM0fKcjn UnDp6q8spLtiuuizgke0sx8QcnV0BpPechjx4632ng== X-Received: by 2002:a17:906:e290:b0:c52:7255:54b5 with SMTP id a640c23a62f3a-c5272555b0fmr113709766b.9.1796422846834; Fri, 04 Dec 2026 14:20:46 -0800 (PST) Received: from Desktop.tail070c67.ts.net (pd9513dea.dip0.t-ipconnect.de. [217.81.61.234]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b3ffac1sm170779166b.52.2026.12.04.14.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 14:20:46 -0800 (PST) From: Julius Bairaktaris To: Andrew Lunn , Vladimir Oltean Cc: netdev@vger.kernel.org, bridge@lists.linux.dev, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Nikolay Aleksandrov , Ido Schimmel , =?UTF-8?q?Alvin=20=C5=A0ipraga?= , Florian Fainelli , Tobias Waldekranz , Linus Walleij , Pawel Dembicki Subject: [PATCH net v3 2/3] net: dsa: hold the device a queued FDB event is reported to Date: Fri, 4 Dec 2026 23:20:44 +0100 Message-ID: <20261204222045.214014-3-julius@bairaktaris.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204222045.214014-1-julius@bairaktaris.de> References: <20261204222045.214014-1-julius@bairaktaris.de> 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-Transfer-Encoding: 8bit dsa_user_fdb_event() queues an FDB event on the DSA workqueue together with the device the event was emitted for (orig_dev), and dsa_user_switchdev_event_work() reports an added entry to that device with SWITCHDEV_FDB_OFFLOADED once the switch is programmed. No reference is held on orig_dev. It is a DSA user port only when the entry is on one: for an entry on another port of the bridge, which DSA installs as a host address, it is that port. DSA flushes its workqueue before one of its own ports leaves the bridge, but nothing waits for the queue when a foreign bridge port is unregistered, and a work that runs after the device was freed reads it in br_switchdev_event(): BUG: KASAN: slab-use-after-free in br_switchdev_event+0x41b/0x550 Read of size 8 at addr ffff888004d00000 by task kworker/u16:0/13 Workqueue: dsa_ordered dsa_user_switchdev_event_work Call Trace: br_switchdev_event+0x41b/0x550 notifier_call_chain+0x9a/0x2a0 atomic_notifier_call_chain+0x5a/0x110 dsa_user_switchdev_event_work+0x32c/0x4c0 process_one_work+0x8e1/0x1640 Freed by task 139: kfree+0x1b7/0x550 device_release+0xca/0x250 Hold a reference on orig_dev while the event is queued, as mlxsw, prestera, sparx5 and cpsw do for the device of their deferred FDB events. Unregistering the device then waits for the work, which does not take RTNL. DSA held the device until commit 425d19cedef8 ("net: dsa: stop calling dev_hold in dsa_slave_fdb_event"), when the report still went to the DSA user port. Fixes: 93c798230af5 ("net: dsa: call SWITCHDEV_FDB_OFFLOADED for the orig_dev") Signed-off-by: Julius Bairaktaris --- Found by an LLM review (Claude) of a DSA FDB change of mine. In QEMU with KASAN, with dsa_loop given FDB operations, assisted learning on the CPU port and a 500 ms delay in its FDB add (test-only changes), deleting a veth bridge port right after an address was learned on it gives the report above in 3 of 3 boots, and nothing with this change in 3 of 3 boots. v3: - No change; rebased on net e9d78fc6741a. v2: - Rebased on patch 1, which changes the same exit of dsa_user_switchdev_event_work(): its out: label is above the netdev_put() added here, so an event it drops still releases the device. NIPA could not apply v1 after patch 1. - The message says how the bug was found. v2: https://lore.kernel.org/all/20261128133503.3887987-3-julius@bairaktaris.de/ v1: https://lore.kernel.org/all/20261122173347.791590-1-julius@bairaktaris.de/ net/dsa/user.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/dsa/user.c b/net/dsa/user.c index 81f0d3901209..2073129b9f87 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -35,6 +35,7 @@ struct dsa_switchdev_event_work { struct net_device *dev; struct net_device *orig_dev; + netdevice_tracker orig_dev_tracker; struct work_struct work; unsigned long event; /* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and @@ -3697,6 +3698,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work) } out: + netdev_put(switchdev_work->orig_dev, &switchdev_work->orig_dev_tracker); kfree(switchdev_work); } @@ -3775,6 +3777,10 @@ static int dsa_user_fdb_event(struct net_device *dev, switchdev_work->event = event; switchdev_work->dev = dev; switchdev_work->orig_dev = orig_dev; + /* The work reports to orig_dev, which can be a foreign bridge port + * that is unregistered before the work runs + */ + netdev_hold(orig_dev, &switchdev_work->orig_dev_tracker, GFP_ATOMIC); ether_addr_copy(switchdev_work->addr, fdb_info->addr); switchdev_work->vid = fdb_info->vid; -- 2.53.0