Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9940347ybi; Wed, 24 Jul 2019 12:42:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfgEamLkY9DugLhCAxRaAb0LVhqzUaiQ/895frcIac5QivDBX1vg+RKVB9ufBEHrhJtLaz X-Received: by 2002:a17:902:b702:: with SMTP id d2mr90158891pls.259.1563997371494; Wed, 24 Jul 2019 12:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563997371; cv=none; d=google.com; s=arc-20160816; b=cIdIPi46T6vt8OYIljWRmO7wUqpQfR5uzU21UA4tOU1fH95bsfahnYM6mxO6zLSjRg ByWJverMBqxBRGrmU8EEyAZuqUh/JE8FyBuaALPXpj9k94r35iD98gsqmoHDjHG4Cfjj epHISUW7LA000/Ggmq4hhFHTpUQnZ6p9j3cox1SDUgr35ZP1tAln2l8WxyuUwZFVIRhj kpaWH8bpQr1825Weiond0uq95/av0cCvMA1y2fw32TzYydUcIOu/4jUJnCvKSnj4glmn Cd9a5PpUcuG79hncalmyPUTGz/GhT+l0pdqsmlq2JhMlrGW2gJTehxvtsWqRMvwr7jiJ IWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kUu+q0D1n4sQTU1V0Sp/nBnxgQslHGWNDN8rtYIEdJs=; b=c+q0swww+ggtppiptcg2LdZ+5l7qqlm8JokwI15YuUn3RIWefYeU7GfkdIj3QPpY/T 7yNSJrRWZNgT1lRHei2ho02tluE7ENClJW7sn1sBZqdz6kfG7K+tsOI+Hwdii2iE5PVU HwFm1YGDzsGguHJ/S05ayu+1Tsdwsx/fk+8WOC8rY2VMRrz+W87cUtKGbw492roVh2t+ sZ6adlHVRNYU+tm2v5pnJwCblA8gUedJNsK/YyAfUwibsnY4hQS9i/Io+XterbGiNP37 +/3C81C9b7phsxLuB3oaJ2R/T3fb3lG6WXmmqJ1H5T78j9lvrg2aAZTiWed5q6GmaCj8 OiQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DwUeanH0; 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 g9si14417698plm.207.2019.07.24.12.42.36; Wed, 24 Jul 2019 12:42:51 -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=DwUeanH0; 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 S2389984AbfGXTkP (ORCPT + 99 others); Wed, 24 Jul 2019 15:40:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:41370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389969AbfGXTkL (ORCPT ); Wed, 24 Jul 2019 15:40:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 5B9E420665; Wed, 24 Jul 2019 19:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997209; bh=g5ew0x0ljJATRm5obPC6TA3B7KaerKkAGjb4EczNsmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DwUeanH0l7Lkk/wNwufCOIRvulH9IIoaucFzDV8xhTcxenhmcJP6pAPCtUnJqa1+9 nkuJ7fL4UlfcjylKmPBHn2yacZvpWNTcqdzostdiyO+FG10BFyUgYQOyuQTFncDuJT O8GyGjbwCgAr5nek38E9E4Iym7zez30+zrnz3NTI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Radoslaw Burny , Luis Chamberlain , Kees Cook , "Eric W . Biederman" , Seth Forshee , John Sperbeck , Alexey Dobriyan , Andrew Morton , Linus Torvalds Subject: [PATCH 5.2 342/413] fs/proc/proc_sysctl.c: fix the default values of i_uid/i_gid on /proc/sys inodes. Date: Wed, 24 Jul 2019 21:20:33 +0200 Message-Id: <20190724191800.293586504@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Radoslaw Burny commit 5ec27ec735ba0477d48c80561cc5e856f0c5dfaf upstream. 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 Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/proc/proc_sysctl.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/proc/proc_sysctl.c +++ b/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; }