From patchwork Tue Apr 25 12:23:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Djalal Harouni X-Patchwork-Id: 9698073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD44B6020A for ; Tue, 25 Apr 2017 12:25:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9614728484 for ; Tue, 25 Apr 2017 12:25:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A6DE2858D; Tue, 25 Apr 2017 12:25:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id CD89128484 for ; Tue, 25 Apr 2017 12:25:11 +0000 (UTC) Received: (qmail 9328 invoked by uid 550); 25 Apr 2017 12:24:40 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 9274 invoked from network); 25 Apr 2017 12:24:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=APwCi6SJEyp5afC82X+CyM0m/JXnwnYSBRH01A/kLNE=; b=BpbtD7sTT2XS1kYVt7TLYqlWgWVLPa4FWDRpZ5E8MdF0uLkWttHSA7q4Y/TaLA66vi YjwmoxpV+Nj5UAQrmpuc7m2nR2pMxMXTc4HirA8hzY4rYDfny+quJ5XXXo86Fo7pONVm K/PsK/KdqUqWpyDRQyYyfdBTlN0H//Wk3U0B69O+ROY4ryjLNEAGyUN1KmKJpM1oBTFV tzBMHtIUehIjKOpG+DhgieH5iBJ5ky+QZwfE51uD/bH7vSqHHh7h6GiXbq2khEvokQrx cNdKoCKqtHrCIM6tzGsA2GUxrUjp3IBv8vkpgtzee4AbyjtrvGtdWVd9tl8Rm6qvFeWM idDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=APwCi6SJEyp5afC82X+CyM0m/JXnwnYSBRH01A/kLNE=; b=G5VI2NKaov5CkjHfXWV9ggZE3jOQ1iVrfIDjfp///aQbqvprYk66kOpREUMCHclIHQ 8NOLRYbJ47ZNfnvD9v07KkICcLWoRpAStglgWcxERqEeIwcpT8FOw3RuEE/eorEXnyYy XOVI21LTy1qJp2tx652PBtp001ehiW0P9G8gYRtlXjvNgR+NiKfYzSgwvDZibAhq6Lq6 fg16rolwUONQx+Gw+HCnJsNZmL/3tRzE8hLvk/DrWsJP0BoStOfsgliWr4Mt8Cd15iOf 3mp6UI21L3BF3IN/JSwgVGS6KlgpSAFp1VwhYFLqrb5q3QGBIYxcLo8WtWkJTVw++b7H 8SiA== X-Gm-Message-State: AN3rC/52AU7m4qIPIDloGgVigI7B2YFFCLyOR8zPfC+0kZMmsGILix/S 95Kr/gVFNUXGqAek9jTIuQ== X-Received: by 10.80.181.113 with SMTP id z46mr4923418edd.6.1493123067994; Tue, 25 Apr 2017 05:24:27 -0700 (PDT) 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 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> Subject: [kernel-hardening] [PATCH RFC v2 5/6] proc: instantiate only pids that we can ptrace on 'limit_pids=1' mount option X-Virus-Scanned: ClamAV using ClamSMTP 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);