From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752186Ab1LKSbb (ORCPT ); Sun, 11 Dec 2011 13:31:31 -0500 Received: from mail-bw0-f46.google.com ([209.85.214.46]:50650 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752048Ab1LKSb2 (ORCPT ); Sun, 11 Dec 2011 13:31:28 -0500 Date: Sun, 11 Dec 2011 22:28:21 +0400 From: Vasiliy Kulikov To: Andrew Morton Cc: Al Viro , Alexey Dobriyan , kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, Hugh Dickins Subject: [PATCH -next] proc: fix task_struct infoleak Message-ID: <20111211182821.GA2853@albatros> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org proc_pid_permission() doesn't put task_struct on every /proc/$pid/ access. A demo from Hugh Dickins: while :; do ps; grep KernelStack /proc/meminfo; sleep 1; done Reported-by: Hugh Dickins Signed-off-by: Vasiliy Kulikov --- This is a patch against a hidepid patchset from -mm. fs/proc/base.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 8caf5cb..0e5c577 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -646,9 +646,14 @@ static bool has_pid_permissions(struct pid_namespace *pid, static int proc_pid_permission(struct inode *inode, int mask) { struct pid_namespace *pid = inode->i_sb->s_fs_info; - struct task_struct *task = get_proc_task(inode); + struct task_struct *task; + int has_perms; + + task = get_proc_task(inode); + has_perms = has_pid_permissions(pid, task, 1); + put_task_struct(task); - if (!has_pid_permissions(pid, task, 1)) { + if (!has_perms) { if (pid->hide_pid == 2) { /* * Let's make getdents(), stat(), and open() -- 1.7.0.4