Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp557916imm; Fri, 11 May 2018 02:47:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoXb5CQXzpUvAZvKg0xWsUC2bAbdt7qgOSzVfBsRzfYl6a6hfM0lojcWwTdoe91hczme0Tr X-Received: by 2002:a63:8348:: with SMTP id h69-v6mr3857296pge.378.1526032075929; Fri, 11 May 2018 02:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526032075; cv=none; d=google.com; s=arc-20160816; b=FLDEAZcozDNwLKBFQ4ePGlOR12KwX269zmiXaw06FscvgYdZqYnxtOGSCBAf2q/xqm bE34jMAAQFI18IzOnGAMUEm8SvC7QYzQdgTAQQUpY2P04sok39LjSsDEStLIrbf47PKQ drMLMD3AV2oYQJbXKewL4hLa6TcdKWFyuJOeFfSpb9XrUydmlwyP9kV+DePSby3Pdy/M upX0cmIxNvXrgA6vaCv3HsZzHUSD3+q0/PYoYnsj8dwfXckKKQ+OIjdpwY142eeoAGbW VP0wypsbnHz/HM1Pe/EFD4V5PAS4wGmp9zdtLgX8y/Qt7iJq+hwbpq/yppCTUrPAJgrx y5Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:arc-authentication-results; bh=4Fegy7ceB6y5NBC8dhXD0OAc4Q7a0UlJaGg9yQBqJsg=; b=TLE6L6IEwmmdrkitWDRHa+MTw3ntRWibwAbXBRblpUudCJ4w2sMqqYLXXoSbs8Q4kM 1bkZ6xc45Gu6kh2ymRUmLTGiEojCxRcu+rn4YfHRRtlusXZhSd+YgMTbelyzXe/Wa1KZ quXac7eO4WhGeNp8kQSThivp5e/jn9UBRTOVTI0f5g5MEFhNxOVhBPd74TJl7DrFgTd4 1EDiIpqAHfbPEKmQ4JzhFLMtJ9Pfqn4pCJqo79VfaXopz3POnBupQ6SqZyl9vFtIL71K lnNE0CnHUUbTdKHJHDdXUK+TPXDIuMFoYgPCm9lTC5zTa9/77Ka7axP+V0+Mua9RIWaF FUvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b7-v6si2342003pgu.482.2018.05.11.02.47.41; Fri, 11 May 2018 02:47:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1752874AbeEKJqR (ORCPT + 99 others); Fri, 11 May 2018 05:46:17 -0400 Received: from monster.unsafe.ru ([5.9.28.80]:54912 "EHLO mail.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751406AbeEKJqN (ORCPT ); Fri, 11 May 2018 05:46:13 -0400 Received: from comp-core-i7-2640m-0182e6 (nat-pool-brq-t.redhat.com [213.175.37.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.unsafe.ru (Postfix) with ESMTPSA id 4E6BCC61A9D; Fri, 11 May 2018 09:46:11 +0000 (UTC) Date: Fri, 11 May 2018 11:36:14 +0200 From: Alexey Gladkov To: Kees Cook , Andy Lutomirski , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org Cc: Greg Kroah-Hartman , Alexander Viro , Akinobu Mita , Oleg Nesterov , Jeff Layton , Ingo Molnar , Alexey Dobriyan , "Eric W. Biederman" , Linus Torvalds , aniel Micay , Jonathan Corbet , bfields@fieldses.org, Stephen Rothwell , solar@openwall.com, "Dmitry V. Levin" , Djalal Harouni Subject: [PATCH v5 5/7] proc: instantiate only pids that we can ptrace on 'limit_pids=1' mount option Message-ID: <20180511093613.GA1330@comp-core-i7-2640m-0182e6> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Djalal Harouni 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 6f084344..31baeef 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3187,6 +3187,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) @@ -3200,7 +3201,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.5