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: 9698071 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 9501E6020A for ; Tue, 25 Apr 2017 12:25:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC2828484 for ; Tue, 25 Apr 2017 12:25:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 746952858D; Tue, 25 Apr 2017 12:25:09 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7526328484 for ; Tue, 25 Apr 2017 12:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947520AbdDYMZD (ORCPT ); Tue, 25 Apr 2017 08:25:03 -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 Received: by mail-wm0-f68.google.com with SMTP id u65so24542301wmu.3; Tue, 25 Apr 2017 05:24:28 -0700 (PDT) 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=ai7txqxhkD54zVHfa8+d2dwhcZvfhTX7rJS2l0DD2j3WKj5qON1IDsoTvVvcGnPnC7 QWJG8aNzBmeMVFEpSvOgP5Oht5sR31cmvMMkFOa+GlfibLKTQZilDKFlgsEdUZY21YiP Vx+h8mD0foy/zJdmLMZQFUuWv00BrD1V2TT7SobnE3vCokQForHnUjlAyX/015zVJdjb ZhKDbigPmWuGkiC0PierWNEJL4Ukx9XhYyK+8G24swXm4FXwcCYP/soG50OtWU3ENNv0 4dhrwD+IwOLx2bk4G3D4j6FY3XyMwzHcEyoz12PVevdsDgyp/rVhJNHNvXX/nqhvgRRB sQjA== X-Gm-Message-State: AN3rC/5Lrl90PjLwZDAgn2HlnXCrV1iBapFJl+ogZOFubktZeNpX+1jY 1oZjKHY2ltFvAQ== X-Received: by 10.80.181.113 with SMTP id z46mr4923418edd.6.1493123067994; Tue, 25 Apr 2017 05:24:27 -0700 (PDT) Received: from dztty2.localdomain ([2a02:8109:a4bf:e114:7e7a:91ff:fe9c:44e2]) by smtp.gmail.com with ESMTPSA id g12sm5037865eda.37.2017.04.25.05.24.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); 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 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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);