From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6E4C4CCDCD for ; Mon, 31 Aug 2026 18:40:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788201609; cv=none; b=LSXp0rQfPcg5cb1t7TD8NHt/ZUBhRKT7o++rSQdXggVqbbF9Savpd+SwOOjIHgx+bjnMUMfPceSwrSFiSSfS1Eq1pQ3/mgpxm/pbGPUZCbydYfCSE0PT/D7giLUTgYiXVcCzuj5llZQc2l2fJnUibGwUMrT+n/8tP7QHcTH7rcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788201609; c=relaxed/simple; bh=aewfOdf/3WAUvkkFdDrIdOFI2f7ZAM15rd2oXKGgb4I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BGYuGkUkevaAT1BEm7CqtSdewT5FTb6eKipSxDhNFbN7G7lgIHAnFT6E7hj3+JRQOoJ1q6Ims+BUDsOK0Xh+g9xc4LDvBxrj629HSV3siPsumxiXxFsv9lzaR9fLdX9qmegzedtgqjCZELFNwMwr2OA92Rf6+BULvl4ApBS2aWI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eFakrzFf; arc=none smtp.client-ip=209.85.217.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eFakrzFf" Received: by mail-vs1-f51.google.com with SMTP id ada2fe7eead31-783d429d0cfso2558904137.3 for ; Mon, 31 Aug 2026 11:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788201606; x=1788806406; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=GbhZLTo9aV7ORbQe8pCNK+Oy/E8FGCzgPkcrwk0Y9GE=; b=eFakrzFfV0IJubLDxmDE453rSE/2KSryDLxvTR+E4gakW62mr3xDO2rfh9gK6guRiZ n68vIqpPvFrYWTCbDiZMxvgOnVGBQRreYlq/awGF/LrqTqVlm70kmWMW5jh0L5blbkOw qRk7ArZmAlFzUfq0dqyy8S7IcTrPQ2RAnZc65oBZVCoqGZW0Tif9iLAp8bp7nHB7i51N qwZey+mrT+jhAYmnqAJd3di9G6VbYmO+5RSE66rBhWRncGIHbpXjUH3dx9GnB4uzAlM3 2IzyhfFqYaUdIgUWmt53iB5e01HuyKJNrHf8MSRDoJ6c0pOUUgORccN2XELadT48qrjp Yv9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788201606; x=1788806406; h=content-transfer-encoding:mime-version: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=GbhZLTo9aV7ORbQe8pCNK+Oy/E8FGCzgPkcrwk0Y9GE=; b=Pyqe7maX62PdILgUTQnXNBbp0dN18heAs349JQWaS6h8WtAWmz6Jj07UJQnRuDbi6g JRwz8/NtNUG0qSUL5ELoA8TiQNaCUK3pfHaOCtP7j69LpOcMeDoHW79DhIPqOObTdsLs 5nglkbOfxNqlopdgxEaSaZUtfzPZ/GHYqq7U26E5yyjQLTF+VzexRGDIvEfihS4J+LQz C7w6JZORxHmDRQdFIzqzMLVjQbZXWki5EuPCJKgX9Msr49nZTT5uSg5DUlLMvbJlmLqV 5nhU4TLP36cK3Ydf4PnyQeU8noSaJfhPRzWjA1uPSTvJ2Smn7mQOmwjWoJesup9wHH2k 3uaA== X-Forwarded-Encrypted: i=1; AHgh+RodDHxKPd85NKg0bYkNEMVai6rtBy2LG8jG8rP2G/9SUURNMx8RXofsqc/bTBfAbnmr2e+HQJq1g1IJwFc=@vger.kernel.org X-Gm-Message-State: AFuF++l+MNvxDxOV8q6GgCCclReSaYpgLjcztbskR9uLhlyJPDkGAmb6 bm6qjbN2bcsrZOcmFnMzL/It79/UiKEQMV3APo1Bnd7XiEVgfdSOyijA X-Gm-Gg: AR+sD107S2BSmQ2aXZonrupWRHYD4VRZDqNMFo2QM7NsUlNPnqJBe3oSHI7uNXckFHG V3GdK2qaxfDIiCkPmdvlIPPsB8StCeJJXwu8AKdNpCNj8U7l6CQRVjsg6neNgP+t2XRaQKoCoFo +JewvcN1+ibVdKYXbnvvIRsfLF4TLcYgevEYaEwS+SA+47BETL7QTF6kfvpdnjCO4YUalSkUAo2 lo948u2NB79zTdOHDXBxLceaHf5wXZz24Z7ZwaVLV5xscGQ+Zb9EM3W/xfjQD+piqn+IubwjwsH pVPNXhQ6ynXMuKZkPmU+f4lvnF5crPE3/OoUhSzFUbZkm8z3ZeV55NKLNAoyu5BqH4+kQyxgUi4 cq4C0W2e/T4YWXU6ilve02+5mRQdOomAXoCmSmA+Uxe1SuoNUg1/oIudM04a7vc8drbXAkzPcZg G32RgKLrWPSYR/i2YaBMkXPt1eIQHv+53PIzt6n4BClDLG0R9RahUkhugi0PBBzss= X-Received: by 2002:a05:6102:424d:b0:789:3f43:6455 with SMTP id ada2fe7eead31-7893f43668emr6870967137.0.1788201606502; Mon, 31 Aug 2026 11:40:06 -0700 (PDT) Received: from adriano ([190.215.95.120]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-97e847c49ebsm8747242241.0.2026.08.31.11.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2026 11:40:06 -0700 (PDT) From: Adriano Cordova To: Jakub Kicinski , netdev@vger.kernel.org Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, Adriano Cordova , syzbot+989ff6506f5c6d1ff56b@syzkaller.appspot.com Subject: [PATCH net] netdevsim: take bus device refcount before registering device Date: Mon, 31 Aug 2026 14:39:52 -0400 Message-ID: <20260831183952.1345042-1-adrianox@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit nsim_bus_dev_release() drops nsim_bus_devs when a device is freed, but the matching increment was done in new_device_store() only after nsim_bus_dev_new() returned successfully. When device_register() failed inside nsim_bus_dev_new(), put_device() invoked the release callback and decremented nsim_bus_devs without the increment, driving the refcount to zero. A later successful device creation then incremented from zero and triggered: refcount_t: addition on 0; use-after-free. Increment nsim_bus_devs in nsim_bus_dev_new() before device_register() so the release callback's decrement is balanced on both the success and error paths. Reported-by: syzbot+989ff6506f5c6d1ff56b@syzkaller.appspot.com Closes: https://syzkaller.appspot.com/bug?extid=989ff6506f5c6d1ff56b Fixes: 6aff7cbfe7bfa ("netdevsim: Block until all devices are released") Signed-off-by: Adriano Cordova --- drivers/net/netdevsim/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index 5c55c308487b..426fb438b922 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -194,7 +194,6 @@ new_device_store(const struct bus_type *bus, const char *buf, size_t count) goto err; } - refcount_inc(&nsim_bus_devs); /* Allow using nsim_bus_dev */ smp_store_release(&nsim_bus_dev->init, true); @@ -465,6 +464,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count, unsigned int num_queu /* Disallow using nsim_bus_dev */ smp_store_release(&nsim_bus_dev->init, false); + refcount_inc(&nsim_bus_devs); err = device_register(&nsim_bus_dev->dev); if (err) goto err_nsim_bus_dev_id_free; -- 2.51.0