Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FEB8C7618F for ; Wed, 17 Jul 2019 19:33:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 212822173E for ; Wed, 17 Jul 2019 19:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563392012; bh=WS33NPlvxJvqZHbC2fPXhsVNPmdIkQO0/SHKfwWVJpc=; h=Date:From:To:Subject:List-ID:From; b=tKyHzcNO8n8KBVJRqqVk1Nbv+YUqNtKtnSi+IwpbdPaNSi7l2YuM7b5ZSobUrc7z+ q0hLU34diD+xV227MXT5SwU8LiD1hdsaB8bcYtxBeXCIFxnLaROiHZbGgV2AO949gc NKxU1oH4Y7JaAG09hu2rSDZ8bAXnvss/zq2ZAxKU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727399AbfGQTdb (ORCPT ); Wed, 17 Jul 2019 15:33:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727315AbfGQTdb (ORCPT ); Wed, 17 Jul 2019 15:33:31 -0400 Received: from localhost.localdomain (c-71-198-47-131.hsd1.ca.comcast.net [71.198.47.131]) (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 C42EA21743; Wed, 17 Jul 2019 19:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563392010; bh=WS33NPlvxJvqZHbC2fPXhsVNPmdIkQO0/SHKfwWVJpc=; h=Date:From:To:Subject:From; b=EEyvFUr5pCtEzp+4rzKvikBzFPew2fNvNtCTd+pMNzd4wOJ84e7Lvjw8XYPG3xdqD spY/eFSxvBpHCrO5Kk2Tc1WJ6oPihMQwmsmmpgmaum7Q4Kr+7wZtzhARUwOJhjl6Nw xAzAp4M1sRYkXeR5QOl84WYW9zQNeXKDurmJUdYk= Date: Wed, 17 Jul 2019 12:33:29 -0700 From: akpm@linux-foundation.org To: adobriyan@gmail.com, ebiederm@xmission.com, jsperbeck@google.com, keescook@chromium.org, mcgrof@kernel.org, mm-commits@vger.kernel.org, rburny@google.com, seth.forshee@canonical.com, stable@vger.kernel.org Subject: [merged] fs-fix-the-default-values-of-i_uid-i_gid-on-proc-sys-inodes.patch removed from -mm tree Message-ID: <20190717193329.ALVxVeaqq%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: fs/proc/proc_sysctl.c: fix the default values of i_uid/i_gid on /proc/sys inodes. has been removed from the -mm tree. Its filename was fs-fix-the-default-values-of-i_uid-i_gid-on-proc-sys-inodes.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Radoslaw Burny Subject: fs/proc/proc_sysctl.c: fix the default values of i_uid/i_gid on /proc/sys inodes. Normally, the inode's i_uid/i_gid are translated relative to s_user_ns, but this is not a correct behavior for proc. Since sysctl permission check in test_perm is done against GLOBAL_ROOT_[UG]ID, it makes more sense to use these values in u_[ug]id of proc inodes. In other words: although uid/gid in the inode is not read during test_perm, the inode logically belongs to the root of the namespace. I have confirmed this with Eric Biederman at LPC and in this thread: https://lore.kernel.org/lkml/87k1kzjdff.fsf@xmission.com Consequences ============ Since the i_[ug]id values of proc nodes are not used for permissions checks, this change usually makes no functional difference. However, it causes an issue in a setup where: * a namespace container is created without root user in container - hence the i_[ug]id of proc nodes are set to INVALID_[UG]ID * container creator tries to configure it by writing /proc/sys files, e.g. writing /proc/sys/kernel/shmmax to configure shared memory limit Kernel does not allow to open an inode for writing if its i_[ug]id are invalid, making it impossible to write shmmax and thus - configure the container. Using a container with no root mapping is apparently rare, but we do use this configuration at Google. Also, we use a generic tool to configure the container limits, and the inability to write any of them causes a failure. History ======= The invalid uids/gids in inodes first appeared due to 81754357770e (fs: Update i_[ug]id_(read|write) to translate relative to s_user_ns). However, AFAIK, this did not immediately cause any issues. The inability to write to these "invalid" inodes was only caused by a later commit 0bd23d09b874 (vfs: Don't modify inodes with a uid or gid unknown to the vfs). Tested: Used a repro program that creates a user namespace without any mapping and stat'ed /proc/$PID/root/proc/sys/kernel/shmmax from outside. Before the change, it shows the overflow uid, with the change it's 0. The overflow uid indicates that the uid in the inode is not correct and thus it is not possible to open the file for writing. Link: http://lkml.kernel.org/r/20190708115130.250149-1-rburny@google.com Fixes: 0bd23d09b874 ("vfs: Don't modify inodes with a uid or gid unknown to the vfs") Signed-off-by: Radoslaw Burny Acked-by: Luis Chamberlain Cc: Kees Cook Cc: "Eric W . Biederman" Cc: Seth Forshee Cc: John Sperbeck Cc: Alexey Dobriyan Cc: [4.8+] Signed-off-by: Andrew Morton --- fs/proc/proc_sysctl.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/proc/proc_sysctl.c~fs-fix-the-default-values-of-i_uid-i_gid-on-proc-sys-inodes +++ a/fs/proc/proc_sysctl.c @@ -499,6 +499,10 @@ static struct inode *proc_sys_make_inode if (root->set_ownership) root->set_ownership(head, table, &inode->i_uid, &inode->i_gid); + else { + inode->i_uid = GLOBAL_ROOT_UID; + inode->i_gid = GLOBAL_ROOT_GID; + } return inode; } _ Patches currently in -mm which might be from rburny@google.com are