Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1406416yba; Thu, 16 May 2019 21:24:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzis1VYUJAswU4L91Lde7GMU4Ov55inX/V+AaF5lvMOXYCu1dFTiIYFhKL/fNkGDVObl2gE X-Received: by 2002:aa7:8e0d:: with SMTP id c13mr59704637pfr.193.1558067062106; Thu, 16 May 2019 21:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558067062; cv=none; d=google.com; s=arc-20160816; b=Fh5X67+/X7T2zRYUnef68FOEugJvI+qYJyGy/1uNZB1xGdXDu0364bMliDiJk31A5f 1midYSQZIIXyWdPWOkLBrdnqgZTNZzeoSY7wp1pln0mmBQ7yMeyO4Jz/gjoWrUPcKD0g /CVQhh+PZ++EWDnXM3qhVlOcL2gEvTsJutLnz0wUuCyp7alhkOVMeeZWwqB5wNM+z1bJ IJqx03kQHf0pW6a/RW21VIXr0VSBqWi93900BfAThEaBymFWBfTB4Rq8TZNNkRaVzdsB NaikgUgvxGBfW2zJk/BYYIaBHJizKgt6DCfQb18NUCfQeBks2TYWsCny+a0RjprvknSv nf7Q== 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:mime-version :message-id:date:subject:to:from:dkim-signature; bh=j63K5kt/+ZVwWL7v54vZ6nKLjjvImcbcZCJ95gUcFYo=; b=n8tzKQmcFhImllHvicO8fg0hw2cb3Be2L0fWEH7b026UCrKaaNj37ig1yAXCLLoF+v 6XC9gvshWmFNlmSRf48pRLIAvB+gH0ukfwjP/5NXdCUwl3+FlKB2gmc+SvLUgO7hHtcp JrU0RuD/6mS7Q5MKn+SePpgAa61Qm4Lz6q8IZvPcN7lv4MQWzFY/+v8KyOqrQMSHJTtV Dt2xXHvN+0mAlYBfdjgt6Acs6hw8GwKUAzQbwptc34jXwy2rPXNfjtFLQGXoJW/NtRFV 9jPW2/FOQwwPPqyLy0pLdKBYdgAExNPMq5QO/MpEHxSLnK4j5xcVUnwTbLECVsdJPV0E 2XlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@felipegasper.com header.s=default header.b=mhIVdWYF; 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 k69si7805523pfb.73.2019.05.16.21.24.07; Thu, 16 May 2019 21:24:22 -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=mhIVdWYF; 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 S1727649AbfEQDx1 (ORCPT + 99 others); Thu, 16 May 2019 23:53:27 -0400 Received: from web1.siteocity.com ([67.227.147.204]:43164 "EHLO web1.siteocity.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbfEQDx1 (ORCPT ); Thu, 16 May 2019 23:53:27 -0400 X-Greylist: delayed 1699 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 May 2019 23:53:26 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=felipegasper.com; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=j63K5kt/+ZVwWL7v54vZ6nKLjjvImcbcZCJ95gUcFYo=; b=mhIVdWYFz7zvgarpgJTIsHK+97 6+Nh7rY9O/brQjWXyQ+OooEg7lJD4E9RDd11r0v2mK+ItdCLV/4Kg9SzpGYdF/GVFH9KiCNQof/Mr AqbyWO9GzUvVdmYtzMzkhqdUwmM/H5BodILF3bEwxsDqpMYZuyFXRc4uy+UORbXzlvbouzw3kA1JT SI/Y82H5kiD1bB9+kpm9P9zYwOL0kRPVsRnN88K7we/dUoCst3KTemNsSHjwvHQPDmo9I5FaQNsO6 VRcQTS+SH++NNZgrMFsrnQd+dF2gRprnDRLLeglrsWrKxN0O7hw9RLh9eJRzneZW8JXghfc9ALN7w b0J3B3sQ==; Received: from fgasper by web1.siteocity.com with local (Exim 4.92) (envelope-from ) id 1hRTUX-0005Sf-Cv; Thu, 16 May 2019 22:25:06 -0500 From: Felipe To: davem@davemloft.net, felipe@felipegasper.com, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH] Add UNIX_DIAG_UID to Netlink UNIX socket diagnostics. Date: Thu, 16 May 2019 22:25:05 -0500 Message-Id: <20190517032505.19921-1-felipe@felipegasper.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OutGoing-Spam-Status: No, score=0.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 - [1438 994] / [47 12] X-AntiAbuse: Sender Address Domain - web1.siteocity.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 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’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 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;