Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp497764pxf; Wed, 10 Mar 2021 10:22:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYbsw2DclrXO9rnxclWaWyWfOV5rn83x9YsQ1C8qnNf4qOzUrzIXx/skxacEDrtJw/cZ5h X-Received: by 2002:aa7:ce16:: with SMTP id d22mr4781897edv.95.1615400528261; Wed, 10 Mar 2021 10:22:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615400528; cv=none; d=google.com; s=arc-20160816; b=bbIGsiR7GOYT3CV3YQ8daRqgr14RmU/K4FAD/CBEwl4CMPrHTrNNevP2+WF3Gdyfs9 hjVFfNUCpKMWCAbkRGhrTs/lo03y/FMugKYsRct9+wxrqYLhX7zl7O7hSvaYf0SIxltc MiNoQfR//hnYEFI9vmXdCT+eJsE+/YdFY+hmw4NEKs46/9DYzVP6gLgCeKnsTopCFe7S 1riZ/jnUKPjYCY85WuUHGXJqizG61bcOwlP+P/WBjAkErMJ+1zwtzGk38Hh59IhNyVbi qp351amTfkHrRhsztuPA46bd41HDPeguyJnVxp6xfaz6OfrLHhcP4Xb/PDCiZ5heq+sI iVMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JZEwaJav+ojSky+amPqY/OKy4E2Gj/SJUvodFmzMwGU=; b=jLe0SP2EN0+PSYZGoULLQ/EsPyvdNry/6VmX1GMNzT/4Plh+i86jiSkhzr/tWZaZPp 655UzlruUVuhRft79lyyRe+iHfEbZVD5ZG80YhgSONbVUiSGnT2RexUjWUjjmgAQDuye QLKGJZxVwr6gwKYrOpW3NX5CRnyoEfLZAmoC80Z8CdmxS4bJCUzx4u9Y55B2/o5k+XCU hmids9PZMwvYcDy1/MMR+BRc1blqQnUJRXrhqEooefhMa8N48Wi9T4VFRUl1sPEKl791 GHOpl+cnCxU2yl+2+K4iu0MiMPEzSmHmLkWz7UliaHAK6ZzfjNJNXKn84zme9Ldfnl3p xARA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si151677ede.102.2021.03.10.10.21.46; Wed, 10 Mar 2021 10:22:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233722AbhCJSUs (ORCPT + 99 others); Wed, 10 Mar 2021 13:20:48 -0500 Received: from raptor.unsafe.ru ([5.9.43.93]:56494 "EHLO raptor.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233336AbhCJSUV (ORCPT ); Wed, 10 Mar 2021 13:20:21 -0500 Received: from comp-core-i7-2640m-0182e6.redhat.com (ip-94-113-225-162.net.upcbroadband.cz [94.113.225.162]) by raptor.unsafe.ru (Postfix) with ESMTPSA id 0196541758; Wed, 10 Mar 2021 18:20:20 +0000 (UTC) From: Alexey Gladkov To: LKML , "Eric W . Biederman" Cc: Alexey Gladkov , Alexander Viro , Kees Cook , Linux Containers , Linux FS Devel Subject: [PATCH v5 2/5] proc: Show /proc/self/net only for CAP_NET_ADMIN Date: Wed, 10 Mar 2021 19:19:57 +0100 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (raptor.unsafe.ru [0.0.0.0]); Wed, 10 Mar 2021 18:20:20 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cache the mounters credentials and make access to the net directories contingent of the permissions of the mounter of proc. Show /proc/self/net only if mounter has CAP_NET_ADMIN and if proc is mounted with subset=pid option. Signed-off-by: Alexey Gladkov --- fs/proc/proc_net.c | 8 ++++++++ fs/proc/root.c | 5 +++++ include/linux/proc_fs.h | 1 + 3 files changed, 14 insertions(+) diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c index 18601042af99..a198f74cdb3b 100644 --- a/fs/proc/proc_net.c +++ b/fs/proc/proc_net.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "internal.h" @@ -259,6 +260,7 @@ static struct net *get_proc_task_net(struct inode *dir) struct task_struct *task; struct nsproxy *ns; struct net *net = NULL; + struct proc_fs_info *fs_info = proc_sb_info(dir->i_sb); rcu_read_lock(); task = pid_task(proc_pid(dir), PIDTYPE_PID); @@ -271,6 +273,12 @@ static struct net *get_proc_task_net(struct inode *dir) } rcu_read_unlock(); + if (net && (fs_info->pidonly == PROC_PIDONLY_ON) && + security_capable(fs_info->mounter_cred, net->user_ns, CAP_NET_ADMIN, CAP_OPT_NONE) < 0) { + put_net(net); + net = NULL; + } + return net; } diff --git a/fs/proc/root.c b/fs/proc/root.c index 5e444d4f9717..6a75ac717455 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -171,6 +171,7 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) return -ENOMEM; fs_info->pid_ns = get_pid_ns(ctx->pid_ns); + fs_info->mounter_cred = get_cred(fc->cred); proc_apply_options(fs_info, fc, current_user_ns()); /* User space would break if executables or devices appear on proc */ @@ -220,6 +221,9 @@ static int proc_reconfigure(struct fs_context *fc) sync_filesystem(sb); + put_cred(fs_info->mounter_cred); + fs_info->mounter_cred = get_cred(fc->cred); + proc_apply_options(fs_info, fc, current_user_ns()); return 0; } @@ -274,6 +278,7 @@ static void proc_kill_sb(struct super_block *sb) kill_anon_super(sb); put_pid_ns(fs_info->pid_ns); + put_cred(fs_info->mounter_cred); kfree(fs_info); } diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index 000cc0533c33..ffa871941bd0 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -64,6 +64,7 @@ struct proc_fs_info { kgid_t pid_gid; enum proc_hidepid hide_pid; enum proc_pidonly pidonly; + const struct cred *mounter_cred; }; static inline struct proc_fs_info *proc_sb_info(struct super_block *sb) -- 2.29.2