[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <AF68C2F5-1E59-44D4-BC63-9C988C278174@felipegasper.com>
Date: Fri, 17 May 2019 10:11:38 -0400
From: Felipe Gasper <felipe@...ipegasper.com>
To: Andy Lutomirski <luto@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Al Viro <viro@...iv.linux.org.uk>,
LKML <linux-kernel@...r.kernel.org>,
Network Development <netdev@...r.kernel.org>,
Linux API <linux-api@...r.kernel.org>
Subject: Re: [PATCH] Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics.
> On May 17, 2019, at 12:59 AM, Andy Lutomirski <luto@...nel.org> wrote:
>
>> On May 16, 2019, at 8:25 PM, Felipe <felipe@...ipegasper.com> wrote:
>>
>> Author: Felipe Gasper <felipe@...ipegasper.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@...ipegasper.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));
>
> That type is called *k* uid_t because it’s internal to the kernel. You
> probably want from_kuid_munged(), which will fix it up for an
> appropriate userns. Presumably you want sk’s netns’s userns.
Thank you for pointing this out.
Would it suffice to get the userns as: “sk_user_ns(sk)”?
Or would it be better to pass struct netlink_callback *cb from unix_diag_dump() to sk_diag_dump() to sk_diag_fill(), then to the new function to add the UID?
cheers,
-Felipe Gasper
Powered by blists - more mailing lists