* [PATCH net 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock [not found] <cover.1775207252.git.wangjiexun2025@gmail.com> @ 2026-04-06 13:53 ` Ren Wei 2026-04-07 4:17 ` Kuniyuki Iwashima 2026-04-07 8:00 ` [PATCH net v2 " Ren Wei 1 sibling, 1 reply; 6+ messages in thread From: Ren Wei @ 2026-04-06 13:53 UTC (permalink / raw) To: netdev Cc: kuniyu, davem, edumazet, kuba, pabeni, horms, xemul, yifanwucs, tomapufckgml, yuantan098, bird, enjou1224z, wangjiexun2025, n05ec From: Jiexun Wang <wangjiexun2025@gmail.com> Exact UNIX diag lookups hold a reference to the socket, but not to u->path. Meanwhile, unix_release_sock() clears u->path under unix_state_lock() and drops the path reference after unlocking. Read the inode and device numbers for UNIX_DIAG_VFS while holding unix_state_lock(), then emit the netlink attribute after dropping the lock. This keeps the VFS data stable while the reply is being built. Fixes: 5f7b0569460b ("unix_diag: Unix inode info NLA") Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Co-developed-by: Yuan Tan <yuantan098@gmail.com> Signed-off-by: Yuan Tan <yuantan098@gmail.com> Suggested-by: Xin Liu <bird@lzu.edu.cn> Tested-by: Ren Wei <enjou1224z@gmail.com> Signed-off-by: Jiexun Wang <wangjiexun2025@gmail.com> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> --- net/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/unix/diag.c b/net/unix/diag.c index ca3473026151..76b2c48137dd 100644 --- a/net/unix/diag.c +++ b/net/unix/diag.c @@ -28,18 +28,23 @@ static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) { - struct dentry *dentry = unix_sk(sk)->path.dentry; + struct dentry *dentry; + struct unix_diag_vfs uv; + bool have_vfs = false; + unix_state_lock(sk); + dentry = unix_sk(sk)->path.dentry; if (dentry) { - struct unix_diag_vfs uv = { - .udiag_vfs_ino = d_backing_inode(dentry)->i_ino, - .udiag_vfs_dev = dentry->d_sb->s_dev, - }; - - return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); + uv.udiag_vfs_ino = d_backing_inode(dentry)->i_ino; + uv.udiag_vfs_dev = dentry->d_sb->s_dev; + have_vfs = true; } + unix_state_unlock(sk); - return 0; + if (!have_vfs) + return 0; + + return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); } static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) -- 2.34.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock 2026-04-06 13:53 ` [PATCH net 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock Ren Wei @ 2026-04-07 4:17 ` Kuniyuki Iwashima 0 siblings, 0 replies; 6+ messages in thread From: Kuniyuki Iwashima @ 2026-04-07 4:17 UTC (permalink / raw) To: Ren Wei Cc: netdev, davem, edumazet, kuba, pabeni, horms, xemul, yifanwucs, tomapufckgml, yuantan098, bird, enjou1224z, wangjiexun2025 On Mon, Apr 6, 2026 at 6:53 AM Ren Wei <n05ec@lzu.edu.cn> wrote: > > From: Jiexun Wang <wangjiexun2025@gmail.com> > > Exact UNIX diag lookups hold a reference to the socket, but not to > u->path. Meanwhile, unix_release_sock() clears u->path under > unix_state_lock() and drops the path reference after unlocking. > > Read the inode and device numbers for UNIX_DIAG_VFS while holding > unix_state_lock(), then emit the netlink attribute after dropping the > lock. > > This keeps the VFS data stable while the reply is being built. > > Fixes: 5f7b0569460b ("unix_diag: Unix inode info NLA") > Reported-by: Yifan Wu <yifanwucs@gmail.com> > Reported-by: Juefei Pu <tomapufckgml@gmail.com> > Co-developed-by: Yuan Tan <yuantan098@gmail.com> > Signed-off-by: Yuan Tan <yuantan098@gmail.com> > Suggested-by: Xin Liu <bird@lzu.edu.cn> > Tested-by: Ren Wei <enjou1224z@gmail.com> > Signed-off-by: Jiexun Wang <wangjiexun2025@gmail.com> > Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> > --- > net/unix/diag.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/net/unix/diag.c b/net/unix/diag.c > index ca3473026151..76b2c48137dd 100644 > --- a/net/unix/diag.c > +++ b/net/unix/diag.c > @@ -28,18 +28,23 @@ static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) > > static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) > { > - struct dentry *dentry = unix_sk(sk)->path.dentry; > + struct dentry *dentry; > + struct unix_diag_vfs uv; > + bool have_vfs = false; nit: Please keep the reverse xmas order. https://www.kernel.org/doc/html/v6.6/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs > > + unix_state_lock(sk); > + dentry = unix_sk(sk)->path.dentry; > if (dentry) { > - struct unix_diag_vfs uv = { > - .udiag_vfs_ino = d_backing_inode(dentry)->i_ino, > - .udiag_vfs_dev = dentry->d_sb->s_dev, > - }; > - > - return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); > + uv.udiag_vfs_ino = d_backing_inode(dentry)->i_ino; > + uv.udiag_vfs_dev = dentry->d_sb->s_dev; > + have_vfs = true; > } > + unix_state_unlock(sk); > > - return 0; > + if (!have_vfs) > + return 0; > + > + return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); > } > > static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v2 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock [not found] <cover.1775207252.git.wangjiexun2025@gmail.com> 2026-04-06 13:53 ` [PATCH net 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock Ren Wei @ 2026-04-07 8:00 ` Ren Wei 2026-04-07 8:21 ` Jason Xing ` (2 more replies) 1 sibling, 3 replies; 6+ messages in thread From: Ren Wei @ 2026-04-07 8:00 UTC (permalink / raw) To: netdev Cc: kuniyu, davem, edumazet, kuba, pabeni, horms, xemul, yifanwucs, tomapufckgml, yuantan098, bird, enjou1224z, wangjiexun2025, n05ec From: Jiexun Wang <wangjiexun2025@gmail.com> Exact UNIX diag lookups hold a reference to the socket, but not to u->path. Meanwhile, unix_release_sock() clears u->path under unix_state_lock() and drops the path reference after unlocking. Read the inode and device numbers for UNIX_DIAG_VFS while holding unix_state_lock(), then emit the netlink attribute after dropping the lock. This keeps the VFS data stable while the reply is being built. Fixes: 5f7b0569460b ("unix_diag: Unix inode info NLA") Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Co-developed-by: Yuan Tan <yuantan098@gmail.com> Signed-off-by: Yuan Tan <yuantan098@gmail.com> Suggested-by: Xin Liu <bird@lzu.edu.cn> Tested-by: Ren Wei <enjou1224z@gmail.com> Signed-off-by: Jiexun Wang <wangjiexun2025@gmail.com> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> --- Changes in v2: - reorder local variables in reverse xmas tree order net/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/unix/diag.c b/net/unix/diag.c index ca3473026151..c9c1e51c4419 100644 --- a/net/unix/diag.c +++ b/net/unix/diag.c @@ -28,18 +28,23 @@ static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) { - struct dentry *dentry = unix_sk(sk)->path.dentry; + struct unix_diag_vfs uv; + struct dentry *dentry; + bool have_vfs = false; + unix_state_lock(sk); + dentry = unix_sk(sk)->path.dentry; if (dentry) { - struct unix_diag_vfs uv = { - .udiag_vfs_ino = d_backing_inode(dentry)->i_ino, - .udiag_vfs_dev = dentry->d_sb->s_dev, - }; - - return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); + uv.udiag_vfs_ino = d_backing_inode(dentry)->i_ino; + uv.udiag_vfs_dev = dentry->d_sb->s_dev; + have_vfs = true; } + unix_state_unlock(sk); - return 0; + if (!have_vfs) + return 0; + + return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); } static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) -- 2.34.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock 2026-04-07 8:00 ` [PATCH net v2 " Ren Wei @ 2026-04-07 8:21 ` Jason Xing 2026-04-08 1:41 ` Kuniyuki Iwashima 2026-04-09 2:50 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 6+ messages in thread From: Jason Xing @ 2026-04-07 8:21 UTC (permalink / raw) To: Ren Wei Cc: netdev, kuniyu, davem, edumazet, kuba, pabeni, horms, xemul, yifanwucs, tomapufckgml, yuantan098, bird, enjou1224z, wangjiexun2025 On Tue, Apr 7, 2026 at 4:01 PM Ren Wei <n05ec@lzu.edu.cn> wrote: > > From: Jiexun Wang <wangjiexun2025@gmail.com> > > Exact UNIX diag lookups hold a reference to the socket, but not to > u->path. Meanwhile, unix_release_sock() clears u->path under > unix_state_lock() and drops the path reference after unlocking. > > Read the inode and device numbers for UNIX_DIAG_VFS while holding > unix_state_lock(), then emit the netlink attribute after dropping the > lock. > > This keeps the VFS data stable while the reply is being built. > > Fixes: 5f7b0569460b ("unix_diag: Unix inode info NLA") > Reported-by: Yifan Wu <yifanwucs@gmail.com> > Reported-by: Juefei Pu <tomapufckgml@gmail.com> > Co-developed-by: Yuan Tan <yuantan098@gmail.com> > Signed-off-by: Yuan Tan <yuantan098@gmail.com> > Suggested-by: Xin Liu <bird@lzu.edu.cn> > Tested-by: Ren Wei <enjou1224z@gmail.com> > Signed-off-by: Jiexun Wang <wangjiexun2025@gmail.com> > Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Next time, please, you should obey the submission rules. One of them is to at least wait ~24 hours before posting a new version, which makes reviewers from all over the world have a chance to take a look at your patch. Thanks, Jason ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock 2026-04-07 8:00 ` [PATCH net v2 " Ren Wei 2026-04-07 8:21 ` Jason Xing @ 2026-04-08 1:41 ` Kuniyuki Iwashima 2026-04-09 2:50 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 6+ messages in thread From: Kuniyuki Iwashima @ 2026-04-08 1:41 UTC (permalink / raw) To: Ren Wei Cc: netdev, davem, edumazet, kuba, pabeni, horms, xemul, yifanwucs, tomapufckgml, yuantan098, bird, enjou1224z, wangjiexun2025 On Tue, Apr 7, 2026 at 1:00 AM Ren Wei <n05ec@lzu.edu.cn> wrote: > > From: Jiexun Wang <wangjiexun2025@gmail.com> > > Exact UNIX diag lookups hold a reference to the socket, but not to > u->path. Meanwhile, unix_release_sock() clears u->path under > unix_state_lock() and drops the path reference after unlocking. > > Read the inode and device numbers for UNIX_DIAG_VFS while holding > unix_state_lock(), then emit the netlink attribute after dropping the > lock. > > This keeps the VFS data stable while the reply is being built. > > Fixes: 5f7b0569460b ("unix_diag: Unix inode info NLA") > Reported-by: Yifan Wu <yifanwucs@gmail.com> > Reported-by: Juefei Pu <tomapufckgml@gmail.com> > Co-developed-by: Yuan Tan <yuantan098@gmail.com> > Signed-off-by: Yuan Tan <yuantan098@gmail.com> > Suggested-by: Xin Liu <bird@lzu.edu.cn> > Tested-by: Ren Wei <enjou1224z@gmail.com> > Signed-off-by: Jiexun Wang <wangjiexun2025@gmail.com> > Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Looks good, thanks ! Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Next time your team post patches, please make sure to follow this guideline: Documentation/process/maintainer-netdev.rst (e.g. post a next revision as a separate thread, etc) > --- > Changes in v2: > - reorder local variables in reverse xmas tree order > > net/unix/diag.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/net/unix/diag.c b/net/unix/diag.c > index ca3473026151..c9c1e51c4419 100644 > --- a/net/unix/diag.c > +++ b/net/unix/diag.c > @@ -28,18 +28,23 @@ static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) > > static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb) > { > - struct dentry *dentry = unix_sk(sk)->path.dentry; > + struct unix_diag_vfs uv; > + struct dentry *dentry; > + bool have_vfs = false; > > + unix_state_lock(sk); > + dentry = unix_sk(sk)->path.dentry; > if (dentry) { > - struct unix_diag_vfs uv = { > - .udiag_vfs_ino = d_backing_inode(dentry)->i_ino, > - .udiag_vfs_dev = dentry->d_sb->s_dev, > - }; > - > - return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); > + uv.udiag_vfs_ino = d_backing_inode(dentry)->i_ino; > + uv.udiag_vfs_dev = dentry->d_sb->s_dev; > + have_vfs = true; > } > + unix_state_unlock(sk); > > - return 0; > + if (!have_vfs) > + return 0; > + > + return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv); > } > > static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb) > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v2 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock 2026-04-07 8:00 ` [PATCH net v2 " Ren Wei 2026-04-07 8:21 ` Jason Xing 2026-04-08 1:41 ` Kuniyuki Iwashima @ 2026-04-09 2:50 ` patchwork-bot+netdevbpf 2 siblings, 0 replies; 6+ messages in thread From: patchwork-bot+netdevbpf @ 2026-04-09 2:50 UTC (permalink / raw) To: Ren Wei Cc: netdev, kuniyu, davem, edumazet, kuba, pabeni, horms, xemul, yifanwucs, tomapufckgml, yuantan098, bird, enjou1224z, wangjiexun2025 Hello: This patch was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Tue, 7 Apr 2026 16:00:14 +0800 you wrote: > From: Jiexun Wang <wangjiexun2025@gmail.com> > > Exact UNIX diag lookups hold a reference to the socket, but not to > u->path. Meanwhile, unix_release_sock() clears u->path under > unix_state_lock() and drops the path reference after unlocking. > > Read the inode and device numbers for UNIX_DIAG_VFS while holding > unix_state_lock(), then emit the netlink attribute after dropping the > lock. > > [...] Here is the summary with links: - [net,v2,1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock https://git.kernel.org/netdev/net/c/39897df38637 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-09 2:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1775207252.git.wangjiexun2025@gmail.com>
2026-04-06 13:53 ` [PATCH net 1/1] af_unix: read UNIX_DIAG_VFS data under unix_state_lock Ren Wei
2026-04-07 4:17 ` Kuniyuki Iwashima
2026-04-07 8:00 ` [PATCH net v2 " Ren Wei
2026-04-07 8:21 ` Jason Xing
2026-04-08 1:41 ` Kuniyuki Iwashima
2026-04-09 2:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox