Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1403176pxf; Fri, 12 Mar 2021 08:43:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUfo3uT6ynC1mpliZhiz1JSNtDxj/63/kWNJwsWrlASkXk8YZDgyAQu4KPXllFRmpmYir9 X-Received: by 2002:aa7:c496:: with SMTP id m22mr15032026edq.292.1615567437442; Fri, 12 Mar 2021 08:43:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615567437; cv=none; d=google.com; s=arc-20160816; b=sCYmqhebsOhetIIk5yqW0phzHdtggcav20TYUvee9fFCX83/Af38oudjFLPO4F9/+R NKN3Ebh5LHQD6Ppn7rawaMMW4hF76dU5PLSQOLgU9reh23GOWuJSHgH8M9ttNAA3Lfi7 tzFNyGY6a8d5QUCQpP3aqNGInl/MoVBHbFpR4JR/AnKSAKuaKFiJIAd5jYCzRCEsOqsj T22LT1EdVY5CMn/r4pnqftv+tsq1B3nTS59k2spQC9lOx4CaQ7RTE/yxWPd+zvtp/agP S6E2wqgfB0jX1fFmKuDPRMIEY9FtdsC8GS5A7gvt6u5wuBPhnyf/XYwoFzCVxdl8nIst lBsA== 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=LlgPc1QEjh1meQFEybknHdl6puzut6qTvK7Ls5E3Y5g=; b=ESPt+zYdsw7Fqcvx+zEHSBIh7Q/O5gb1YjpTMHoTgLChrTuZ3S5WDoGMvUzcY8/o7Y WjcUoDvPqkrl9DCXtgYhMcTgD8wlS/D2XoY/2Cuk5E9kTKN6Yu+TZJrK2D2tM3GikYUk kf2dtE4+KUfWTob4ZJVbrK6Fkx7t8g/teLXw1Dq3yLCiCiRdAwUlxltJ4eyg1v5tkmrf qX5HJnwAewe4C0MuIV/nrDfGgxFlafOe0rqT2Qyzn3PwE+BHAqnNZkXKP+N9mT0xA1C2 1dyUwtuvzYW163Cr1GfEjnYqrTxF79ahfYmUHzqmpYU5efjlISjKGTQ46YVLjxbysf8i LmbA== 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 yd6si4367276ejb.302.2021.03.12.08.43.34; Fri, 12 Mar 2021 08:43:57 -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 S232984AbhCLQml (ORCPT + 99 others); Fri, 12 Mar 2021 11:42:41 -0500 Received: from raptor.unsafe.ru ([5.9.43.93]:49790 "EHLO raptor.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232950AbhCLQmE (ORCPT ); Fri, 12 Mar 2021 11:42:04 -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 2FBDB40CA0; Fri, 12 Mar 2021 16:42:02 +0000 (UTC) From: Alexey Gladkov To: LKML , "Eric W . Biederman" Cc: Alexey Gladkov , Alexander Viro , Kees Cook , Linux Containers , Linux FS Devel Subject: [PATCH v6 2/5] proc: subset=pid: Show /proc/self/net only for CAP_NET_ADMIN Date: Fri, 12 Mar 2021 17:41:45 +0100 Message-Id: X-Mailer: git-send-email 2.29.3 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]); Fri, 12 Mar 2021 16:42:02 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cache the mounters credentials and allow access to the net directories contingent of the permissions of the mounter of proc. Do not show /proc/self/net when proc is mounted with subset=pid option and the mounter does not have CAP_NET_ADMIN. 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.3