lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fa9efc8c4c0cb3dd3b0bba153b4b368e64ff06c3.camel@kernel.org>
Date:   Mon, 11 Jan 2021 15:46:32 -0800
From:   Saeed Mahameed <saeed@...nel.org>
To:     Vladimir Oltean <olteanv@...il.com>,
        "David S . Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>
Cc:     netdev@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
        Florian Fainelli <f.fainelli@...il.com>,
        Cong Wang <xiyou.wangcong@...il.com>,
        Stephen Hemminger <stephen@...workplumber.org>,
        Eric Dumazet <edumazet@...gle.com>,
        George McCollister <george.mccollister@...il.com>,
        Oleksij Rempel <o.rempel@...gutronix.de>,
        Jay Vosburgh <j.vosburgh@...il.com>,
        Veaceslav Falico <vfalico@...il.com>,
        Andy Gospodarek <andy@...yhouse.net>,
        Arnd Bergmann <arnd@...db.de>, Taehee Yoo <ap420073@...il.com>,
        Jiri Pirko <jiri@...nulli.us>, Florian Westphal <fw@...len.de>,
        Nikolay Aleksandrov <nikolay@...dia.com>,
        Pravin B Shelar <pshelar@....org>,
        Sridhar Samudrala <sridhar.samudrala@...el.com>
Subject: Re: [PATCH v6 net-next 03/15] net: procfs: hold netif_lists_lock
 when retrieving device statistics

On Sat, 2021-01-09 at 19:26 +0200, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@....com>
> 
> In the effort of making .ndo_get_stats64 be able to sleep, we need to
> ensure the callers of dev_get_stats do not use atomic context.
> 
> The /proc/net/dev file uses an RCU read-side critical section to
> ensure
> the integrity of the list of network interfaces, because it iterates
> through all net devices in the netns to show their statistics.
> 
> To offer the equivalent protection against an interface registering
> or
> deregistering, while also remaining in sleepable context, we can use
> the
> netns mutex for the interface lists.
> 
> Cc: Cong Wang <xiyou.wangcong@...il.com>
> Cc: Eric Dumazet <edumazet@...gle.com>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
> ---
> Changes in v6:
> None.
> 
> Changes in v5:
> None.
> 
> Changes in v4:
> None.
> 
> Changes in v3:
> None.
> 
> Changes in v2:
> None.
> 
>  net/core/net-procfs.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
> index c714e6a9dad4..4784703c1e39 100644
> --- a/net/core/net-procfs.c
> +++ b/net/core/net-procfs.c
> @@ -21,7 +21,7 @@ static inline struct net_device
> *dev_from_same_bucket(struct seq_file *seq, loff
>  	unsigned int count = 0, offset = get_offset(*pos);
>  
>  	h = &net->dev_index_head[get_bucket(*pos)];
> -	hlist_for_each_entry_rcu(dev, h, index_hlist) {
> +	hlist_for_each_entry(dev, h, index_hlist) {
>  		if (++count == offset)
>  			return dev;
>  	}
> @@ -51,9 +51,11 @@ static inline struct net_device
> *dev_from_bucket(struct seq_file *seq, loff_t *p
>   *	in detail.
>   */
>  static void *dev_seq_start(struct seq_file *seq, loff_t *pos)
> -	__acquires(RCU)
>  {
> -	rcu_read_lock();
> +	struct net *net = seq_file_net(seq);
> +
> +	netif_lists_lock(net);
> +

This can be very costly, holding a mutex while traversing the whole
netedv lists and reading their stats, we need to at least allow
multiple readers to enter as it was before, so maybe you want to use
rw_semaphore instead of the mutex.

or just have a unified approach of rcu+refcnt/dev_hold as you did for
bonding and failover patches #13..#14, I used the same approach to
achieve the same for sysfs and procfs more than 2 years ago, you are
welcome to use my patches:
https://lore.kernel.org/netdev/4cc44e85-cb5e-502c-30f3-c6ea564fe9ac@gmail.com/


>  	if (!*pos)
>  		return SEQ_START_TOKEN;
>  
> @@ -70,9 +72,10 @@ static void *dev_seq_next(struct seq_file *seq,
> void *v, loff_t *pos)
>  }
>  
>  static void dev_seq_stop(struct seq_file *seq, void *v)
> -	__releases(RCU)
>  {
> -	rcu_read_unlock();
> +	struct net *net = seq_file_net(seq);
> +
> +	netif_lists_unlock(net);
>  }
>  
>  static void dev_seq_printf_stats(struct seq_file *seq, struct
> net_device *dev)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ