public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Daniel Zahka <daniel.zahka@gmail.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Andrew Lunn <andrew+netdev@lunn.ch>,
	 "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	 Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: netdev@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 3/3] netdevsim: psp: rcu protect psp_dev reference
Date: Wed, 06 May 2026 15:34:42 -0400	[thread overview]
Message-ID: <willemdebruijn.kernel.173236793ca@gmail.com> (raw)
In-Reply-To: <20260505-psd-rcu-v1-3-a8f69ec1ab96@gmail.com>

Daniel Zahka wrote:
> There are two issues with the way psp_dev is used in nsim_do_psp():
> 
> 1. There is no check for IS_ERR() on the peers psp_dev, before
>    dereferencing.
> 2. The refcount on this psp_dev can be dropped by
>    nsim_psp_rereg_write()
> 
> To fix this, we can make netdevsim's reference to its psp_dev an rcu
> reference, and then nsim_do_psp() can read the fields it needs from an
> rcu critical section.
> 
> Fixes: f857478d6206 ("netdevsim: a basic test PSP implementation")
> Assisted-by: Claude:claude-opus-4.6
> Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>

>  static ssize_t
> @@ -228,16 +237,23 @@ nsim_psp_rereg_write(struct file *file, const char __user *data, size_t count,
>  		     loff_t *ppos)
>  {
>  	struct netdevsim *ns = file->private_data;
> -	int err;
> +	struct psp_dev *psd;
> +	ssize_t ret;
>  
>  	mutex_lock(&ns->psp.rereg_lock);
> -	__nsim_psp_uninit(ns);
> +	__nsim_psp_uninit(ns, false);
> +
> +	psd = psp_dev_create(ns->netdev, &nsim_psp_ops, &nsim_psp_caps, ns);
> +	if (IS_ERR(psd)) {
> +		ret = PTR_ERR(psd);
> +		goto out;
> +	}

Do you want to create the new device first and only delete the old
state if that succeeds? To avoid a netdevsim in state without dev.

>  
> -	ns->psp.dev = psp_dev_create(ns->netdev, &nsim_psp_ops,
> -				     &nsim_psp_caps, ns);
> -	err = PTR_ERR_OR_ZERO(ns->psp.dev);
> +	rcu_assign_pointer(ns->psp.dev, psd);
> +	ret = count;
> +out:
>  	mutex_unlock(&ns->psp.rereg_lock);
> -	return err ?: count;
> +	return ret;
>  }
>  


  reply	other threads:[~2026-05-06 19:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05 10:42 [PATCH net 0/3] netdevsim: psp: fix init and uninit bugs Daniel Zahka
2026-05-05 10:42 ` [PATCH net 1/3] netdevsim: psp: only call nsim_psp_uninit() on PFs Daniel Zahka
2026-05-06 19:30   ` Willem de Bruijn
2026-05-05 10:42 ` [PATCH net 2/3] netdevsim: psp: serialize calls to nsim_psp_uninit() Daniel Zahka
2026-05-06 19:31   ` Willem de Bruijn
2026-05-05 10:42 ` [PATCH net 3/3] netdevsim: psp: rcu protect psp_dev reference Daniel Zahka
2026-05-06 19:34   ` Willem de Bruijn [this message]
2026-05-06 20:14     ` Daniel Zahka
2026-05-06 20:43       ` Willem de Bruijn
2026-05-07  0:50 ` [PATCH net 0/3] netdevsim: psp: fix init and uninit bugs patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=willemdebruijn.kernel.173236793ca@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=daniel.zahka@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox