Skip to content

Commit 5f7b056

Browse files
xemuldavem330
authored andcommitted
unix_diag: Unix inode info NLA
Actually, the socket path if it's not anonymous doesn't give a clue to which file the socket is bound to. Even if the path is absolute, it can be unlinked and then new socket can be bound to it. With this NLA it's possible to check which file a particular socket is really bound to. Signed-off-by: Pavel Emelyanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f5248b4 commit 5f7b056

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/linux/unix_diag.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct unix_diag_req {
1212
};
1313

1414
#define UDIAG_SHOW_NAME 0x00000001 /* show name (not path) */
15+
#define UDIAG_SHOW_VFS 0x00000002 /* show VFS inode info */
1516

1617
struct unix_diag_msg {
1718
__u8 udiag_family;
@@ -25,8 +26,14 @@ struct unix_diag_msg {
2526

2627
enum {
2728
UNIX_DIAG_NAME,
29+
UNIX_DIAG_VFS,
2830

2931
UNIX_DIAG_MAX,
3032
};
3133

34+
struct unix_diag_vfs {
35+
__u32 udiag_vfs_ino;
36+
__u32 udiag_vfs_dev;
37+
};
38+
3239
#endif

net/unix/diag.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ static int sk_diag_dump_name(struct sock *sk, struct sk_buff *nlskb)
2626
return -EMSGSIZE;
2727
}
2828

29+
static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb)
30+
{
31+
struct dentry *dentry = unix_sk(sk)->dentry;
32+
struct unix_diag_vfs *uv;
33+
34+
if (dentry) {
35+
uv = UNIX_DIAG_PUT(nlskb, UNIX_DIAG_VFS, sizeof(*uv));
36+
uv->udiag_vfs_ino = dentry->d_inode->i_ino;
37+
uv->udiag_vfs_dev = dentry->d_sb->s_dev;
38+
}
39+
40+
return 0;
41+
42+
rtattr_failure:
43+
return -EMSGSIZE;
44+
}
45+
2946
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req,
3047
u32 pid, u32 seq, u32 flags, int sk_ino)
3148
{
@@ -48,6 +65,10 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_r
4865
sk_diag_dump_name(sk, skb))
4966
goto nlmsg_failure;
5067

68+
if ((req->udiag_show & UDIAG_SHOW_VFS) &&
69+
sk_diag_dump_vfs(sk, skb))
70+
goto nlmsg_failure;
71+
5172
nlh->nlmsg_len = skb_tail_pointer(skb) - b;
5273
return skb->len;
5374

0 commit comments

Comments
 (0)