🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9438

Re: [PATCH net] netdevsim: check the driver is bound in new_port/del_port

#9438
From: Hangbin Liu
Date: Mon, 02 Nov 2026 02:19
84 lines
11352 bytes
Hi Nguyen,
On Sun, Nov 01, 2026 at 08:58:24PM +0700, Nguyen Ngoc Thang wrote:
> new_port and del_port are attributes of the bus device, so they stay
> reachable after the driver is unbound. nsim_drv_remove() clears
> drvdata, yet both handlers pass it straight to priv_to_devlink() and
> devl_lock(), which faults on a small negative pointer:
> 
>   BUG: unable to handle page fault for address: fffffffffffffeb0
>   RIP: 0010:__lock_acquire+0x41/0x2de0 kernel/locking/lockdep.c:5140
>   Call Trace:
>    lock_acquire+0x115/0x350
>    mutex_lock_nested+0x55/0x1d0
>    nsim_drv_port_add+0x5a/0x140 drivers/net/netdevsim/dev.c:1760
>    new_port_store+0x1a5/0x280 drivers/net/netdevsim/bus.c:96
>    kernfs_fop_write_iter+0x3a5/0x540
> 
> The nsim_bus_dev->init check does not help: it is only cleared when
> the whole device is deleted, not on unbind.
> 
> Do what sriov_numvfs already does: take device_lock() so the driver
> cannot be unbound underneath us, and return -ENOENT if drvdata is
> NULL.
> 
> Fixes: 794b2c05ca1c ("netdevsim: extend device attrs to support port addition and deletion")
> Reported-by: syzbot+b3fca27eb4005f0111f4@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b3fca27eb4005f0111f4
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>

FYI, Jiacheng already posted a same fix for this issue.

https://lore.kernel.org/netdev/4fe1dcd1.16124.1a01a660a42.Coremail.stitch@zju.edu.cn/

Thanks
Hangbin

> ---
> Reproduced in QEMU (x86_64, KASAN + lockdep) with the syzbot C repro:
> the unpatched kernel oopses in nsim_drv_port_add() right after unbind.
> With the patch, the write to new_port returns -ENOENT, a 40s stress of
> bind/unbind + new_device/del_device racing with new_port/del_port/
> sriov_numvfs runs clean (no splat, no lockdep report, no hung task),
> and new_port/del_port still work as before on a bound device.
>  drivers/net/netdevsim/bus.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
> index 5c55c308487b..d843b3c985cf 100644
> --- a/drivers/net/netdevsim/bus.c
> +++ b/drivers/net/netdevsim/bus.c
> @@ -93,8 +93,13 @@ new_port_store(struct device *dev, struct device_attribute *attr,
>  		return -EINVAL;
>  	}
>  
> -	ret = nsim_drv_port_add(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index,
> -				addr_set ? eth_addr : NULL);
> +	device_lock(dev);
> +	ret = -ENOENT;
> +	if (dev_get_drvdata(dev))
> +		ret = nsim_drv_port_add(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF,
> +					port_index, addr_set ? eth_addr : NULL);
> +	device_unlock(dev);
> +
>  	return ret ? ret : count;
>  }
>  
> @@ -115,7 +120,13 @@ del_port_store(struct device *dev, struct device_attribute *attr,
>  	if (ret)
>  		return ret;
>  
> -	ret = nsim_drv_port_del(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index);
> +	device_lock(dev);
> +	ret = -ENOENT;
> +	if (dev_get_drvdata(dev))
> +		ret = nsim_drv_port_del(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF,
> +					port_index);
> +	device_unlock(dev);
> +
>  	return ret ? ret : count;
>  }
>  
> -- 
> 2.43.0
> 
Technical Details
Message-ID: <aufzJYquZBEcCKqP@fedora>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354430-linux-kernel-netdev=dewy.ru
References: <20261101135824.24484-1-ngocthang2710.1999@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354430-linux-kernel-netdev=dewy.ru
From: hangbin.liu@linux.dev (Hangbin Liu)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] netdevsim: check the driver is bound in
 new_port/del_port
Date: Mon, 2 Nov 2026 10:19:17 +0800
Organization: Usenet Network
Message-ID: <aufzJYquZBEcCKqP@fedora>
References: <20261101135824.24484-1-ngocthang2710.1999@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="2827233"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/NkimRXJ3J3RcIMLRHO+amrtsrU= sha256:dsXomb+Pmwu3A83tCxD0vt+ClLiQn8Sb8dQL3uLgKkM=
	sha1:PL79m0EbpLjQAy+lenECFx1S2YA= sha256:0aQqdT0zszm5GYmhBhk/IELgafoWx6H9cw2ADfMxKGo=
Content-Disposition: inline
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 4828C114004; Mon,  2 Nov 2026 05:20:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
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 xwpDswfgy7Us;
	Mon,  2 Nov 2026 05:20:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354430-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id A3986C72C6; Mon,  2 Nov 2026 05:19:55 +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 1D1032C17E; Mon,  2 Nov 2026 02:19: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=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793585971;
	b=HZGvjtlHS9ws9iNtYuGp3YeVFyTyZzfz/Dj8mBklfLf8GJwZ04UnnfsD+h/+gVdrUbIx
	 9KQQ17WBUXIipp69uBmacFIf+ibDTV1QBFwuu5euuryJaEBGVs1ePM1AKia92T5IzoVKK
	 8APrnB1ZJH3/oGDJlIDmE581yKl9wX6NXchPKJsM2nPdLr5NmNcCBTHIvFkk6n/8DmmLo
	 C16ySKuOo5o3MWRpQt3TyM/QjDLB8ZO/EFGfUyycCNY9fbx05ixc8KCGXgiq/GbC/XYK4
	 RaM5NVQijPu3VxuWZWtXe2NXVm0bbKgQlJz3SLbzC5vJLAyoZ2MRA+ItJwWIdPFkRBw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793585971;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=oWiK3tLwJTeoCwTM/EhaJi6Xwbpz4rsT5Fj18q9ROlE=;
	b=bGpdLORJSALrVtOlCLSkF/23qGlz/oEwaS2Rmw8vCSk1qqKVujEzcPmU/kuRsNjnyqe4
	 S9qNZLGbShJpAVxbcA83509VX/X1ehFwF/nDfx2MMaAVwIDU5kxbFEZJP2ZPHHuLIBx1f
	 AK2sQvbxGDKvbAkGlT3s1tJjXAGQZ3FQJX5huNeJ15z2jdC0DKbny+dORzuBaODwngk5G
	 M5fZ75phTl6tiVpSA/z8MBlz5IMvTaoSFVwYJGkTwuRa/htMf3FABHsqmd3HpoHTDW+cK
	 aBoyn21fre6a62VJkLpIfQ1ispxLqrTUC6OhdyKtkTw19AhI+3NtyqmsaX9SQoKVOPg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="FSquQ9/f";
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 A10CD606A339;
	Mon,  2 Nov 2026 02:19:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FSquQ9/f
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.32
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793585970;
	b=KiKr0p8epsqTJ45IXYBcs7wDkrsfDpav25jFsYpcMUlrOuMe6hLkuLE4K3pET2r/6JwC
	 yW7CKYo9RsYE2WkINffKg6prVbVKAcfJD0hPqno/OS6ka89pWN5rucYEfTTIy54NrYSlH
	 WGZm/2Lc7cFcblCZTB/heWywSXrjWgkNfknWNuVQcDAVlLhj9fHKtwihT6kmx3fODSAfd
	 Y2LE4u7P6MJ8FKwqa+uRZfWO2EdW6xhoHORULsqi/WWcNnmMl7UokgATnWzfeP/ljRp4H
	 CxWzevgxtHGO21OxvfVBGM+qbpvoB5uXQN5orWga4jO56LNMbSvw6LSc8r1+qyiiZNA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793585970;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=oWiK3tLwJTeoCwTM/EhaJi6Xwbpz4rsT5Fj18q9ROlE=;
	b=raLVKR7R55ITLhqkQ49pPrw2via/5WZmqM/CjJZLLZj89GkFk+g+xuVf25EV7ocFDfdd
	 u/+Ef2DwnM7mwIs/6z4XBB3OJ74HLz+fYsVP66PKFfj7L192xkbV8j806d6/g5mtFsNVZ
	 Qj+9tyacxFeWAaB87ob//8qtqVbX2MMyUErU8CzZZfXSXa8OcYxi6QrYhS8WFw/g9vgO/
	 snXQtU+KBTpVV0QsuvovpzrvCb7bbjNtGaj+KFm2SAl8X/AD2DDfO7RU5XKf0+aWYYccV
	 SVQhO9GrCDzlONCXTUvqBltqrV0xmeEYfUER6S1BG4gzvddc+XtrS9+hB1amaZ47Hyw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="FSquQ9/f";
	arc=none smtp.remote-ip=91.218.175.32
X-Received: from mta0.migadu.com (out-32.mta0.migadu.com [91.218.175.32])
	(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 A2AFE606A327
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 02:19:29 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A2AFE606A327
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=Nr34wUCDOVsABZdnNKfDCH6g7tuffGciV7ziRLOLpgQ=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1793585967; v=1; x=1794190767;
 b=FSquQ9/fJeXA3NtxEtP/zeIl/jyojlmD7MTXI2uQTWcuLp+zNMJzTEGiXP+ThnKcL7bvxmol
 Wp67/5vaXaodDuC3J9g787OH9k3egEhriYFfLIsUHZoU1lZ9B2nAYMYdj9gLCiM91tjNkUFJQlO
 y7g0CjBpjq0sM1O66nzVk5Ps=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by mta10.migadu.com with ESMTPS id 7eb5af2a8e588f47;
	Mon, 02 Nov 2026 02:19:27 +0000
X-Mizu-Trace-ID: 7eb5af2a8e588f47
X-Migadu-Flow: FLOW_OUT
X-Cc: kuba@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	syzbot+b3fca27eb4005f0111f4@syzkaller.appspotmail.com
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-In-Reply-To: <20261101135824.24484-1-ngocthang2710.1999@gmail.com>