linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics.
@ 2019-05-17  3:25 Felipe
  2019-05-17  4:59 ` Andy Lutomirski
  0 siblings, 1 reply; 3+ messages in thread
From: Felipe @ 2019-05-17  3:25 UTC (permalink / raw)
  To: davem, felipe, viro, linux-kernel, netdev, linux-api

Author: Felipe Gasper <felipe@felipegasper.com>
Date:   Thu May 16 12:16:53 2019 -0500

    Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics.
    
    This adds the ability for Netlink to report a socket’s UID along with the
    other UNIX socket diagnostic information that is already available. This will
    allow diagnostic tools greater insight into which users control which socket.
    
    Signed-off-by: Felipe Gasper <felipe@felipegasper.com>

diff --git a/include/uapi/linux/unix_diag.h b/include/uapi/linux/unix_diag.h
index 5c502fd..a198857 100644
--- a/include/uapi/linux/unix_diag.h
+++ b/include/uapi/linux/unix_diag.h
@@ -20,6 +20,7 @@ struct unix_diag_req {
 #define UDIAG_SHOW_ICONS	0x00000008	/* show pending connections */
 #define UDIAG_SHOW_RQLEN	0x00000010	/* show skb receive queue len */
 #define UDIAG_SHOW_MEMINFO	0x00000020	/* show memory info of a socket */
+#define UDIAG_SHOW_UID		0x00000040	/* show socket's UID */
 
 struct unix_diag_msg {
 	__u8	udiag_family;
@@ -40,6 +41,7 @@ enum {
 	UNIX_DIAG_RQLEN,
 	UNIX_DIAG_MEMINFO,
 	UNIX_DIAG_SHUTDOWN,
+	UNIX_DIAG_UID,
 
 	__UNIX_DIAG_MAX,
 };
diff --git a/net/unix/diag.c b/net/unix/diag.c
index 3183d9b..011f56c 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -110,6 +110,11 @@ static int sk_diag_show_rqlen(struct sock *sk, struct sk_buff *nlskb)
 	return nla_put(nlskb, UNIX_DIAG_RQLEN, sizeof(rql), &rql);
 }
 
+static int sk_diag_dump_uid(struct sock *sk, struct sk_buff *nlskb)
+{
+	return nla_put(nlskb, UNIX_DIAG_UID, sizeof(kuid_t), &(sk->sk_uid));
+}
+
 static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_req *req,
 		u32 portid, u32 seq, u32 flags, int sk_ino)
 {
@@ -156,6 +161,10 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_r
 	if (nla_put_u8(skb, UNIX_DIAG_SHUTDOWN, sk->sk_shutdown))
 		goto out_nlmsg_trim;
 
+	if ((req->udiag_show & UDIAG_SHOW_UID) &&
+	    sk_diag_dump_uid(sk, skb))
+		goto out_nlmsg_trim;
+
 	nlmsg_end(skb, nlh);
 	return 0;
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-17 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-17  3:25 [PATCH] Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics Felipe
2019-05-17  4:59 ` Andy Lutomirski
2019-05-17 14:11   ` Felipe Gasper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).