public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: nai lin <ayano2023th@gmail.com>
To: netdev@vger.kernel.org
Cc: nai lin <ayano2023th@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Anjali Kulkarni <anjali.k.kulkarni@oracle.com>,
	Li RongQing <lirongqing@baidu.com>,
	David Howells <dhowells@redhat.com>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] netlink: fix potential race issue in netlink_native_seq_show()
Date: Wed, 17 Jan 2024 16:37:13 +0800	[thread overview]
Message-ID: <20240117083715.7800-1-ayano2023th@gmail.com> (raw)

Access to the nlk group should be protected by netlink_lock_table() like
commit <f773608026ee> ("netlink: access nlk groups safely in netlink bind
and getname"), otherwise there will be potential race conditions.

Signed-off-by: nai lin <ayano2023th@gmail.com>
---
 net/netlink/af_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 4ed8ffd58ff3..61ad81fb80f5 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2693,6 +2693,7 @@ static int netlink_native_seq_show(struct seq_file *seq, void *v)
 		struct sock *s = v;
 		struct netlink_sock *nlk = nlk_sk(s);
 
+		netlink_lock_table();
 		seq_printf(seq, "%pK %-3d %-10u %08x %-8d %-8d %-5d %-8d %-8u %-8lu\n",
 			   s,
 			   s->sk_protocol,
@@ -2705,7 +2706,7 @@ static int netlink_native_seq_show(struct seq_file *seq, void *v)
 			   atomic_read(&s->sk_drops),
 			   sock_i_ino(s)
 			);
-
+		netlink_unlock_table();
 	}
 	return 0;
 }
-- 
2.25.1


             reply	other threads:[~2024-01-17  8:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17  8:37 nai lin [this message]
2024-01-17 10:28 ` [PATCH] netlink: fix potential race issue in netlink_native_seq_show() Eric Dumazet
2024-01-18  2:15   ` nai lin

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=20240117083715.7800-1-ayano2023th@gmail.com \
    --to=ayano2023th@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=anjali.k.kulkarni@oracle.com \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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