netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rémi Denis-Courmont" <remi@remlab.net>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH v1 net-next 5/9] phonet: Don't hold RTNL for getaddr_dumpit().
Date: Sat, 19 Oct 2024 10:48:57 +0300	[thread overview]
Message-ID: <12565887.O9o76ZdvQC@basile.remlab.net> (raw)
In-Reply-To: <20241018171629.92709-1-kuniyu@amazon.com>

Le perjantaina 18. lokakuuta 2024, 20.16.29 EEST Kuniyuki Iwashima a écrit :
> From: "Rémi Denis-Courmont" <remi@remlab.net>
> Date: Thu, 17 Oct 2024 21:49:18 +0300
> 
> > > diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
> > > index 5996141e258f..14928fa04675 100644
> > > --- a/net/phonet/pn_netlink.c
> > > +++ b/net/phonet/pn_netlink.c
> > > @@ -127,14 +127,17 @@ static int fill_addr(struct sk_buff *skb, u32
> > > ifindex, u8 addr,
> > > 
> > >  static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback
> > >  *cb)
> > > 
> > > {
> > > +	int addr_idx = 0, addr_start_idx = cb->args[1];
> > > +	int dev_idx = 0, dev_start_idx = cb->args[0];
> > > 
> > >  	struct phonet_device_list *pndevs;
> > >  	struct phonet_device *pnd;
> > > 
> > > -	int dev_idx = 0, dev_start_idx = cb->args[0];
> > > -	int addr_idx = 0, addr_start_idx = cb->args[1];
> > > +	int err = 0;
> > > 
> > >  	pndevs = phonet_device_list(sock_net(skb->sk));
> > > 
> > > +
> > > 
> > >  	rcu_read_lock();
> > >  	list_for_each_entry_rcu(pnd, &pndevs->list, list) {
> > > 
> > > +		DECLARE_BITMAP(addrs, 64);
> > > 
> > >  		u8 addr;
> > >  		
> > >  		if (dev_idx > dev_start_idx)
> > > 
> > > @@ -143,23 +146,26 @@ static int getaddr_dumpit(struct sk_buff *skb,
> > > struct
> > > netlink_callback *cb) continue;
> > > 
> > >  		addr_idx = 0;
> > > 
> > > -		for_each_set_bit(addr, pnd->addrs, 64) {
> > > +		memcpy(addrs, pnd->addrs, sizeof(pnd->addrs));
> > 
> > Is that really safe? Are we sure that the bit-field writers are atomic
> > w.r.t. memcpy() on all platforms? If READ_ONCE is needed for an integer,
> > using memcpy() seems sketchy, TBH.
> 
> I think bit-field read/write need not be atomic here because even
> if a data-race happens, for_each_set_bit() iterates each bit, which
> is the real data, regardless of whether data-race happened or not.

Err, it looks to me that a corrupt bit would lead to the index getting corrupt 
and addresses getting skipped or repeated. AFAICT, the RTNL lock is still 
needed here.

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/




  reply	other threads:[~2024-10-19 10:14 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 18:31 [PATCH v1 net-next 0/9] phonet: Convert all doit() and dumpit() to RCU Kuniyuki Iwashima
2024-10-17 18:31 ` [PATCH v1 net-next 1/9] phonet: Pass ifindex to fill_addr() Kuniyuki Iwashima
2024-10-23 15:24   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 2/9] phonet: Pass net and ifindex to phonet_address_notify() Kuniyuki Iwashima
2024-10-23 15:25   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 3/9] phonet: Convert phonet_device_list.lock to spinlock_t Kuniyuki Iwashima
2024-10-23 15:26   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 4/9] phonet: Don't hold RTNL for addr_doit() Kuniyuki Iwashima
2024-10-23 15:27   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 5/9] phonet: Don't hold RTNL for getaddr_dumpit() Kuniyuki Iwashima
2024-10-17 18:49   ` Rémi Denis-Courmont
2024-10-18 17:16     ` Kuniyuki Iwashima
2024-10-19  7:48       ` Rémi Denis-Courmont [this message]
2024-10-20  1:30         ` Kuniyuki Iwashima
2024-10-23 11:04         ` Paolo Abeni
2024-10-23 11:16           ` Paolo Abeni
2024-10-23 15:30   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 6/9] phonet: Pass ifindex to fill_route() Kuniyuki Iwashima
2024-10-23 15:30   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 7/9] phonet: Pass net and ifindex to rtm_phonet_notify() Kuniyuki Iwashima
2024-10-23 15:32   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 8/9] phonet: Convert phonet_routes.lock to spinlock_t Kuniyuki Iwashima
2024-10-23 15:33   ` Eric Dumazet
2024-10-17 18:31 ` [PATCH v1 net-next 9/9] phonet: Don't hold RTNL for route_doit() Kuniyuki Iwashima
2024-10-23 15:34   ` Eric Dumazet
2024-10-24 14:10 ` [PATCH v1 net-next 0/9] phonet: Convert all doit() and dumpit() to RCU 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=12565887.O9o76ZdvQC@basile.remlab.net \
    --to=remi@remlab.net \
    --cc=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).