Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1499005yba; Thu, 16 May 2019 23:37:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYo4ObQQAGAOvV4SuO8tWrT/mh5iMsMoqQ3bkY1k59uMVvm8wmISFtANkm+P6XgZBECANW X-Received: by 2002:a63:ea42:: with SMTP id l2mr54469086pgk.19.1558075071402; Thu, 16 May 2019 23:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558075071; cv=none; d=google.com; s=arc-20160816; b=vGw0q0Oc6IDJI6HIrozvAjyF9U1vjNfbcpYK0d9ComP+9SHQENaPoUqY/4m9NF3Axt mBAc5mY5tQG9b75p6GCyqSqF2hHTxiJYbwH00rMjbCnOFo8n1owECvxIawz83PUN7T9t pK1l0E7uvrtqMu2E6+Ic42KeMUcOzUXRPW6a1ORaIr9YJQ5Xs1cF0p7NhEFh9rRf+SQW A5M7w9lNfZgC2dH/DAfqfXG3vlZxl0z0Ns/KYBTymh6fGL8P5CnzPDZXk82uU1H+v48F 9gTOQGKVFS9y/MPbzOkzET6qHUqL9hP74nzAnl6ZW58zGBPAsUuUP4atNyc4Xw2MOGBo hdoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BNlmfuhyNuMlhHEbub+opzxZxKqWna36Ivkw2FozHFo=; b=lUQGD0mt8kCd6YwmSsQouSZcm9uPab+Nrh7TUVqqxlqQ64SKqHv4qRaakn8XeEf8WO M6CLfiEmJRYLNNoz4+nR2lBG9noOCKp52blFZeBiY/huLFxFy8JWFfJSqwAkjp6qQLPl 5972jQFkdONGWzaf6MK2hyZv50xdDR9jffkOf7WX1IqIGmonVgHRRSiFU8WpJIXglS6D tDxBL+MqcUBt4vt5ABp8331HwzPq2CQLmAGpWhRWXmbTft6/Qy7fipAV11wq6jOZZV8H ErL+/UOj6rdnJ93ap2ejwN8IlOicTp0AC54i0r+UCHmHK1NihQWM3kB56BBk/L+wyTZs 3MYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eaIpNd90; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r15si7910212pfq.169.2019.05.16.23.37.35; Thu, 16 May 2019 23:37:51 -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=pass header.i=@kernel.org header.s=default header.b=eaIpNd90; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbfEQE7S (ORCPT + 99 others); Fri, 17 May 2019 00:59:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:37026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbfEQE7R (ORCPT ); Fri, 17 May 2019 00:59:17 -0400 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6E8C120879 for ; Fri, 17 May 2019 04:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558069156; bh=wn472IRdgwSTmAQxOlJ/TuR65yPV4PLu1QbTI1KzXZU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eaIpNd90DK2//QGPdxnHMx1w5XMd4XWQJk+S1SkUSgByFc2xJxya9zH2K8syt32kw ymb32N0jsurDwfDLWZDy9zKPpg/BPMGVQHilwhl9u/YZ4d0JAOeHVucEhsWufCrOrX 1vVYJNl6eVnliev49liAwN5dHKRQIvQgFJldG67s= Received: by mail-wr1-f51.google.com with SMTP id b18so5554996wrq.12 for ; Thu, 16 May 2019 21:59:16 -0700 (PDT) X-Gm-Message-State: APjAAAWCLg2yuVCZ1MOGLXh/O60MhwuWiIoT272IwMqm2bwk3NKxZ7pE Tx2syZ3y/5qe8Q7jmruF/Fuz7lw+YM2JYR/rhJQpZg== X-Received: by 2002:adf:dc4b:: with SMTP id m11mr2344176wrj.66.1558069155028; Thu, 16 May 2019 21:59:15 -0700 (PDT) MIME-Version: 1.0 References: <20190517032505.19921-1-felipe@felipegasper.com> In-Reply-To: <20190517032505.19921-1-felipe@felipegasper.com> From: Andy Lutomirski Date: Thu, 16 May 2019 21:59:03 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics. To: Felipe Cc: "David S. Miller" , Al Viro , LKML , Network Development , Linux API Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On May 16, 2019, at 8:25 PM, Felipe wrote: > > Author: Felipe Gasper > 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=E2=80=99s UID alo= ng with the > other UNIX socket diagnostic information that is already available. Th= is will > allow diagnostic tools greater insight into which users control which = socket. > > Signed-off-by: Felipe Gasper > > diff --git a/include/uapi/linux/unix_diag.h b/include/uapi/linux/unix_dia= g.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 sock= et */ > +#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, struc= t 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=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 usern= s.