Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946853AbdDYMZm (ORCPT ); Tue, 25 Apr 2017 08:25:42 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35990 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1947456AbdDYMYa (ORCPT ); Tue, 25 Apr 2017 08:24:30 -0400 From: Djalal Harouni To: Linux Kernel Mailing List , Andy Lutomirski , Kees Cook , Andrew Morton , linux-fsdevel@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-security-module@vger.kernel.org Cc: Linux API , Dongsu Park , Casey Schaufler , James Morris , , Jeff Layton , , Alexander Viro , Alexey Dobriyan , Ingo Molnar , , Oleg Nesterov , Michal Hocko , Jonathan Corbet , Djalal Harouni Subject: [PATCH RFC v2 5/6] proc: instantiate only pids that we can ptrace on 'limit_pids=1' mount option Date: Tue, 25 Apr 2017 14:23:57 +0200 Message-Id: <1493123038-30590-6-git-send-email-tixxdz@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1493123038-30590-1-git-send-email-tixxdz@gmail.com> References: <1493123038-30590-1-git-send-email-tixxdz@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1290 Lines: 41 If "limit_pids=1" mount option is set then do not instantiate pids that we can not ptrace. "limit_pids=1" means that procfs should only contain pids that the caller can ptrace. Cc: Kees Cook Cc: Andy Lutomirski Signed-off-by: Djalal Harouni --- fs/proc/base.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index 2e0f661..a663284 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3149,6 +3149,7 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign unsigned tgid; struct proc_fs_info *fs_info = proc_sb(dir->i_sb); struct pid_namespace *ns = fs_info->pid_ns; + int limit_pids = proc_fs_limit_pids(fs_info); tgid = name_to_int(&dentry->d_name); if (tgid == ~0U) @@ -3162,7 +3163,15 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign if (!task) goto out; + /* Limit procfs to only ptracable tasks */ + if (limit_pids == PROC_LIMIT_PIDS_PTRACE) { + cond_resched(); + if (!has_pid_permissions(fs_info, task, HIDEPID_NO_ACCESS)) + goto out_put_task; + } + result = proc_pid_instantiate(dir, dentry, task, NULL); +out_put_task: put_task_struct(task); out: return ERR_PTR(result); -- 2.10.2