af_unix: read UNIX_DIAG_VFS data under unix_state_lock
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 af_unix: read UNIX_DIAG_VFS data under unix_state_lock
From: Jiexun Wang <[email protected]>
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.
--- net/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
net/unix/diag.c +13 -8
@@ -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)
Signature · 1 line
2.34.1
Kuniyuki Iwashima
maintainerQuoted 31 lines · Ren Wei
From: Jiexun Wang <[email protected]>
Exact UNIX diag lookups hold a reference to the socket, but not to
u->path. Meanwhile,unix_release_sock()clearsu->pathunderunix_state_lock()and drops the path reference after unlocking.Read the inode and device numbers for
UNIX_DIAG_VFSwhile holdingunix_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 <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ren Wei <[email protected]>Signed-off-by Jiexun Wang <[email protected]>Signed-off-by Ren Wei <[email protected]>--- net/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)net/unix/diag.c +0
-0
net/unix/diag.c static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb) · line 33
Quoted 7 lines
net/unix/diag.c +3
-1@@ -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
Quoted 27 lines
net/unix/diag.c +10
-8+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
PATCH v2 1/1 af_unix: read UNIX_DIAG_VFS data under unix_state_lock
In reply to a message not in the archiveFrom: Jiexun Wang <[email protected]>
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.
---
Changes in v2:
- reorder local variables in reverse xmas tree order
net/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
net/unix/diag.c +13 -8
@@ -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)
Signature · 1 line
2.34.1
Quoted 13 lines · Ren Wei
From: Jiexun Wang <[email protected]>
Exact UNIX diag lookups hold a reference to the socket, but not to
u->path. Meanwhile,unix_release_sock()clearsu->pathunderunix_state_lock()and drops the path reference after unlocking.Read the inode and device numbers for
UNIX_DIAG_VFSwhile holdingunix_state_lock(), then emit the netlink attribute after dropping the lock.This keeps the VFS data stable while the reply is being built.
Quoted 9 lines
Fixes 5f7b0569460b ("unix_diag: Unix inode info NLA")Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ren Wei <[email protected]>Signed-off-by Jiexun Wang <[email protected]>Signed-off-by Ren Wei <[email protected]>
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
Quoted 13 lines · Ren Wei
From: Jiexun Wang <[email protected]>
Exact UNIX diag lookups hold a reference to the socket, but not to
u->path. Meanwhile,unix_release_sock()clearsu->pathunderunix_state_lock()and drops the path reference after unlocking.Read the inode and device numbers for
UNIX_DIAG_VFSwhile holdingunix_state_lock(), then emit the netlink attribute after dropping the lock.This keeps the VFS data stable while the reply is being built.
Quoted 9 lines
Fixes 5f7b0569460b ("unix_diag: Unix inode info NLA")Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ren Wei <[email protected]>Signed-off-by Jiexun Wang <[email protected]>Signed-off-by Ren Wei <[email protected]>
Looks good, thanks !
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)
Quoted 46 lines
---
Changes in v2:
- reorder local variables in reverse xmas tree ordernet/unix/diag.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)net/unix/diag.c +13
-9@@ -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
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Tue, 7 Apr 2026 16:00:14 +0800 you wrote:
From: Jiexun Wang <[email protected]>
Exact UNIX diag lookups hold a reference to the socket, but not to
u->path. Meanwhile,unix_release_sock()clearsu->pathunderunix_state_lock()and drops the path reference after unlocking.Read the inode and device numbers for
UNIX_DIAG_VFSwhile holdingunix_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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 21 lines · Ren Wei
From: Jiexun Wang <[email protected]>
Exact UNIX diag lookups hold a reference to the socket, but not to
u->path. Meanwhile,unix_release_sock()clearsu->pathunderunix_state_lock()and drops the path reference after unlocking.Read the inode and device numbers for
UNIX_DIAG_VFSwhile holdingunix_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 <[email protected]>Reported-by Juefei Pu <[email protected]>Co-developed-by Yuan Tan <[email protected]>Signed-off-by Yuan Tan <[email protected]>Suggested-by Xin Liu <[email protected]>Tested-by Ren Wei <[email protected]>Signed-off-by Jiexun Wang <[email protected]>Signed-off-by Ren Wei <[email protected]>
Quoted 1 line
---
Seems good, thanks.