Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1942590yba; Fri, 17 May 2019 07:56:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMPRE2kvUIx0pJDqGpfJkdjzllLbQBbTHZe+GlfxqaL+pfb/SON7BWpHRxeFTvxuAMHmhg X-Received: by 2002:a62:3381:: with SMTP id z123mr63167743pfz.42.1558104964373; Fri, 17 May 2019 07:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558104964; cv=none; d=google.com; s=arc-20160816; b=Gz7So670gRm6vYT2GBdlhnc4up7sp5iYEX7B+3t1ON33wdF/EsOz0dKgVdhNpbisVo 8NViFTGQA+qx9KOPOGOG56IGvpihihU5iMB9Tkp31p79mVr2TwGuGJcEfqn9T+nmiluL sByE6QVUzAdfSQCzqP6DwxlUvFHRavbqhnvksRFYf5cFSb+wDXXSx+SQDa+z8hOQFy8B cvTyCNKbQdXinVoTeYqdYOoLVVah8kgN4IkRjnAx3mYTqFupKkoJM9sxIFjjIeBb3PZc AwzjJpr0OBvIuYkgT1nZD5Z1sH1GTFcEJC8WWnrWvCK7WZzqTr4uMgFGWq9IJ2TvQ7WE wKsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=N6m8ItcPeAXtI74gTibpdhO9VtglXynz6qvN46c+wdE=; b=KN1BJcLKLOeY3yd33FR1BeIdQtuFlAb8aOGg5VmjFsDtkgHxP0hifUm328MfQUarAV nEDrxVUJGfhKYo03w8FHoPaW9G6XOywgeyQOabnzaIWZtdac40TrJ5tJ37dSl5KS5dih XfBnk7TbTQymldzJ4q2SeBybuHKSsTT5HavXXwQXIKBMBC9hKz9yogHOhy/57slTCxiS x6VETQjMf82eMegyYGMwahd/dcy/QGsfbtFCCMEVd8d6KnQHqMYhdY7Xh3OEmPJgIY0c Fp+fwoJb8F0dsxIMJq9IIj4WCLmgWUsq8kz0W0CoPFbM67rj8qjOjzuDxrU1U07+tOzw j80Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@felipegasper.com header.s=default header.b=PbLc3yPg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si6029230plc.152.2019.05.17.07.55.48; Fri, 17 May 2019 07:56:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@felipegasper.com header.s=default header.b=PbLc3yPg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729145AbfEQOxJ (ORCPT + 99 others); Fri, 17 May 2019 10:53:09 -0400 Received: from web1.siteocity.com ([67.227.147.204]:37842 "EHLO web1.siteocity.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728968AbfEQOxJ (ORCPT ); Fri, 17 May 2019 10:53:09 -0400 X-Greylist: delayed 2485 seconds by postgrey-1.27 at vger.kernel.org; Fri, 17 May 2019 10:53:07 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=felipegasper.com; s=default; h=To:References:Message-Id: Content-Transfer-Encoding:Cc:Date:In-Reply-To:From:Subject:Mime-Version: Content-Type:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=N6m8ItcPeAXtI74gTibpdhO9VtglXynz6qvN46c+wdE=; b=PbLc3yPgpUwo/2Tew4KztUm6S rZJmFRHIoU+mXUVUC8Ov5FFBXfUWtDM54nHWwDtTIUJJn+HMajz888QdKsY4VrA1A5L39+Jrqxu0z +FpipWyEUSj93ct8veIK7NeHbcP4Ww63H5533KcvSfbWJrR6r8KOO30yFmEiWm5M39Xo2zAgVt+39 8nZvmhDNgnrjPSQZ0aAR7nR8gx//oaRW2VxsnxYpZfWugiWZUXArBmBruHKZPToS1mq2ImRG567RX kYLoeZIBOeGnKZDrFlxd/qeuugysXejb5juPhbBGavctKePoxlRzLrGpFikzohTtPpvU2tsEnsGM9 0pL2zc1pA==; Received: from [149.248.87.38] (port=51684 helo=[192.168.86.41]) by web1.siteocity.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hRdaG-0000dd-AM; Fri, 17 May 2019 09:11:41 -0500 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: [PATCH] Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics. From: Felipe Gasper In-Reply-To: Date: Fri, 17 May 2019 10:11:38 -0400 Cc: "David S. Miller" , Al Viro , LKML , Network Development , Linux API Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190517032505.19921-1-felipe@felipegasper.com> To: Andy Lutomirski X-Mailer: Apple Mail (2.3445.104.11) X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - web1.siteocity.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - felipegasper.com X-Get-Message-Sender-Via: web1.siteocity.com: authenticated_id: fgasper/from_h X-Authenticated-Sender: web1.siteocity.com: felipe@felipegasper.com X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On May 17, 2019, at 12:59 AM, Andy Lutomirski wrote: >=20 >> On May 16, 2019, at 8:25 PM, Felipe wrote: >>=20 >> Author: Felipe Gasper >> Date: Thu May 16 12:16:53 2019 -0500 >>=20 >> Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics. >>=20 >> This adds the ability for Netlink to report a socket=E2=80=99s 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. >>=20 >> Signed-off-by: Felipe Gasper >>=20 >> 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 */ >>=20 >> struct unix_diag_msg { >> __u8 udiag_family; >> @@ -40,6 +41,7 @@ enum { >> UNIX_DIAG_RQLEN, >> UNIX_DIAG_MEMINFO, >> UNIX_DIAG_SHUTDOWN, >> + UNIX_DIAG_UID, >>=20 >> __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); >> } >>=20 >> +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)); >=20 > That type is called *k* uid_t because it=E2=80=99s internal to the = kernel. You > probably want from_kuid_munged(), which will fix it up for an > appropriate userns. Presumably you want sk=E2=80=99s netns=E2=80=99s = userns. Thank you for pointing this out. Would it suffice to get the userns as: =E2=80=9Csk_user_ns(sk)=E2=80=9D? 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=