Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2044629imm; Thu, 24 May 2018 05:02:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo9ylhaUOrMJNc+18N9NCSqpikATuIDEvBbAi+UwHvMz3bgeTsfMK+BU1N3DifUaK1y6twn X-Received: by 2002:a63:2485:: with SMTP id k127-v6mr5644946pgk.434.1527163342608; Thu, 24 May 2018 05:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163342; cv=none; d=google.com; s=arc-20160816; b=BvDJN3ugyf6pCzCVi6FOf+zZZGcohW2HusbD4e0seIv2uozg8Ww/1ef8BEXC24TAAy pOtJa9G0mMKczjv+tC85v88U3oUQFZH4QPeD0x6te2x+qDF+4ol4/w707m+NQoD+tlqa ZCEPcWzkrPAghfxsZxAgTtCENOzPFaTCQPZ/e+/us5t4dk+M3OGY7qzHAOWeQ0RQ8CpL TWYwUW8HTAWncfh2vYoOulzE2CHzH0smDCzMDctS5tvoDwAe7j+WBJJRc7PssWDPXU0B NdWkRAqvODy8z2ShIGxYYD2Hq9ozGuF5oCM86rJlks5IP5916ebYv/tNFj++ugk3Bk/3 d7BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=qoOBhIzX/RlSM+bPqdQQ3VgwmE7M/C8xxYwtqwNkrK0=; b=sOy3qn3NvIm1xeC2ThdhUW5X6ky9oNPqSNnJB1wQHKU4rkANbRHKVCGRIPbL/0cyRk 8UeotURyNAp0rJTFdvSO+TOSoFO7rlDeCq/FQENuR2PSw6KwDZlvscYXKw5teuEpjpmh IgjIO78jsVCTD0UU/Nx5ZTzM8ZAGGg1IlCGj/ATrGzCJb9oE9tcjRw4J8C7NZ+RXqwjv QJIdTdgSivNHAb/ebxagdnWG9kr7kw6MqkOj5N2NcEzVGp8AEyaVUBayr8a/6LNhG+Sw MBxOITauGhALWu7FGKrUbGfjizb3o18etgrex1iYsASpRqKXf79s994GB1Is1sgW1+t1 9ESw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mhnCOgFJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h185-v6si20565521pfe.332.2018.05.24.05.01.46; Thu, 24 May 2018 05:02:22 -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; dkim=pass header.i=@kernel.org header.s=default header.b=mhnCOgFJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969514AbeEXMAy (ORCPT + 99 others); Thu, 24 May 2018 08:00:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:56156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966098AbeEXJo7 (ORCPT ); Thu, 24 May 2018 05:44:59 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8C35E208C1; Thu, 24 May 2018 09:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155099; bh=g62CjgySOFhXbkqiqtoIndzl6clujUKX2W/ZQR7Q3kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mhnCOgFJKjVFFjbwShlHVquMQ6KRBDKmLlOTGBJQrccuiCSkYdQzqH2k9a7k4vx6L KHuMAHPQYjelT19i+nB08ADQcTHbcuqIuvOfiWAkT5aUv1W2S5W2fthdXm6zT8NQFs EWQ3SfuFfucRGJzvBovyueSzILULsBPjfrSJ7j4g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Janis Danisevskis , Kees Cook , Al Viro , Cyrill Gorcunov , Alexey Dobriyan , Colin Ian King , David Rientjes , Minfei Huang , John Stultz , Calvin Owens , Jann Horn , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 55/92] procfs: fix pthread cross-thread naming if !PR_DUMPABLE Date: Thu, 24 May 2018 11:38:32 +0200 Message-Id: <20180524093204.603778122@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Janis Danisevskis commit 1b3044e39a89cb1d4d5313da477e8dfea2b5232d upstream. The PR_DUMPABLE flag causes the pid related paths of the proc file system to be owned by ROOT. The implementation of pthread_set/getname_np however needs access to /proc//task//comm. If PR_DUMPABLE is false this implementation is locked out. This patch installs a special permission function for the file "comm" that grants read and write access to all threads of the same group regardless of the ownership of the inode. For all other threads the function falls back to the generic inode permission check. [akpm@linux-foundation.org: fix spello in comment] Signed-off-by: Janis Danisevskis Acked-by: Kees Cook Cc: Al Viro Cc: Cyrill Gorcunov Cc: Alexey Dobriyan Cc: Colin Ian King Cc: David Rientjes Cc: Minfei Huang Cc: John Stultz Cc: Calvin Owens Cc: Jann Horn Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/proc/base.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3083,6 +3083,44 @@ int proc_pid_readdir(struct file *file, } /* + * proc_tid_comm_permission is a special permission function exclusively + * used for the node /proc//task//comm. + * It bypasses generic permission checks in the case where a task of the same + * task group attempts to access the node. + * The rationale behind this is that glibc and bionic access this node for + * cross thread naming (pthread_set/getname_np(!self)). However, if + * PR_SET_DUMPABLE gets set to 0 this node among others becomes uid=0 gid=0, + * which locks out the cross thread naming implementation. + * This function makes sure that the node is always accessible for members of + * same thread group. + */ +static int proc_tid_comm_permission(struct inode *inode, int mask) +{ + bool is_same_tgroup; + struct task_struct *task; + + task = get_proc_task(inode); + if (!task) + return -ESRCH; + is_same_tgroup = same_thread_group(current, task); + put_task_struct(task); + + if (likely(is_same_tgroup && !(mask & MAY_EXEC))) { + /* This file (/proc//task//comm) can always be + * read or written by the members of the corresponding + * thread group. + */ + return 0; + } + + return generic_permission(inode, mask); +} + +static const struct inode_operations proc_tid_comm_inode_operations = { + .permission = proc_tid_comm_permission, +}; + +/* * Tasks */ static const struct pid_entry tid_base_stuff[] = { @@ -3100,7 +3138,9 @@ static const struct pid_entry tid_base_s #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif - REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations), + NOD("comm", S_IFREG|S_IRUGO|S_IWUSR, + &proc_tid_comm_inode_operations, + &proc_pid_set_comm_operations, {}), #ifdef CONFIG_HAVE_ARCH_TRACEHOOK ONE("syscall", S_IRUSR, proc_pid_syscall), #endif