From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755358AbbKCQmj (ORCPT ); Tue, 3 Nov 2015 11:42:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45640 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752641AbbKCQmh (ORCPT ); Tue, 3 Nov 2015 11:42:37 -0500 Date: Tue, 3 Nov 2015 18:38:51 +0100 From: Oleg Nesterov To: Andrew Morton Cc: "Jin, Yihua" , "Eric W. Biederman" , linux-kernel@vger.kernel.org Subject: [PATCH] proc: actually make proc_fd_permission() thread-friendly Message-ID: <20151103173851.GA4468@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit 96d0df79f264 ("proc: make proc_fd_permission() thread-friendly") fixed the access to /proc/self/fd from sub-threads, but introduced another problem: a sub-thread can't access /proc//fd/ or /proc/thread-self/fd if generic_permission() fails. Change proc_fd_permission() to check same_thread_group(pid_task(), current). Reported-by: "Jin, Yihua" Signed-off-by: Oleg Nesterov Cc: stable@vger.kernel.org --- fs/proc/fd.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/proc/fd.c b/fs/proc/fd.c index 6e5fcd0..3c2a915 100644 --- a/fs/proc/fd.c +++ b/fs/proc/fd.c @@ -291,11 +291,19 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry, */ int proc_fd_permission(struct inode *inode, int mask) { - int rv = generic_permission(inode, mask); + struct task_struct *p; + int rv; + + rv = generic_permission(inode, mask); if (rv == 0) - return 0; - if (task_tgid(current) == proc_pid(inode)) + return rv; + + rcu_read_lock(); + p = pid_task(proc_pid(inode), PIDTYPE_PID); + if (p && same_thread_group(p, current)) rv = 0; + rcu_read_unlock(); + return rv; } -- 1.5.5.1