Skip to content

Commit ac02be8

Browse files
xemuldavem330
authored andcommitted
unix_diag: Unix peer inode NLA
Report the peer socket inode ID as NLA. With this it's finally possible to find out the other end of an interesting unix connection. Signed-off-by: Pavel Emelyanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5f7b056 commit ac02be8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/linux/unix_diag.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct unix_diag_req {
1313

1414
#define UDIAG_SHOW_NAME 0x00000001 /* show name (not path) */
1515
#define UDIAG_SHOW_VFS 0x00000002 /* show VFS inode info */
16+
#define UDIAG_SHOW_PEER 0x00000004 /* show peer socket info */
1617

1718
struct unix_diag_msg {
1819
__u8 udiag_family;
@@ -27,6 +28,7 @@ struct unix_diag_msg {
2728
enum {
2829
UNIX_DIAG_NAME,
2930
UNIX_DIAG_VFS,
31+
UNIX_DIAG_PEER,
3032

3133
UNIX_DIAG_MAX,
3234
};

net/unix/diag.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb)
4343
return -EMSGSIZE;
4444
}
4545

46+
static int sk_diag_dump_peer(struct sock *sk, struct sk_buff *nlskb)
47+
{
48+
struct sock *peer;
49+
int ino;
50+
51+
peer = unix_peer_get(sk);
52+
if (peer) {
53+
unix_state_lock(peer);
54+
ino = sock_i_ino(peer);
55+
unix_state_unlock(peer);
56+
sock_put(peer);
57+
58+
RTA_PUT_U32(nlskb, UNIX_DIAG_PEER, ino);
59+
}
60+
61+
return 0;
62+
rtattr_failure:
63+
return -EMSGSIZE;
64+
}
65+
4666
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req,
4767
u32 pid, u32 seq, u32 flags, int sk_ino)
4868
{
@@ -69,6 +89,10 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_r
6989
sk_diag_dump_vfs(sk, skb))
7090
goto nlmsg_failure;
7191

92+
if ((req->udiag_show & UDIAG_SHOW_PEER) &&
93+
sk_diag_dump_peer(sk, skb))
94+
goto nlmsg_failure;
95+
7296
nlh->nlmsg_len = skb_tail_pointer(skb) - b;
7397
return skb->len;
7498

0 commit comments

Comments
 (0)