From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764305AbcINTH4 (ORCPT ); Wed, 14 Sep 2016 15:07:56 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:54712 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760199AbcINTHs (ORCPT ); Wed, 14 Sep 2016 15:07:48 -0400 From: "Eric W. Biederman" To: Greg Kroah-Hartman , Jiri Slaby Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Linux Containers , "Eric W. Biederman" Date: Wed, 14 Sep 2016 13:53:38 -0500 Message-Id: <20160914185338.15126-6-ebiederm@xmission.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160914185338.15126-1-ebiederm@xmission.com> References: <87sht25n73.fsf@x220.int.ebiederm.org> <20160914185338.15126-1-ebiederm@xmission.com> X-XM-SPF: eid=1bkFX9-0000r5-E3;;;mid=<20160914185338.15126-6-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.119.97.64;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18GEA2iS0JkGxg+Lus4vg0JhwyBCKy6ByA= X-SA-Exim-Connect-IP: 97.119.97.64 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.3 TooManyTo_001 Multiple "To" Header Recipients 2x (uncommon) * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5001] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Greg Kroah-Hartman , Jiri Slaby X-Spam-Relay-Country: X-Spam-Timing: total 212 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 12 (5.7%), b_tie_ro: 11 (5.1%), parse: 0.93 (0.4%), extract_message_metadata: 13 (6.0%), get_uri_detail_list: 1.42 (0.7%), tests_pri_-1000: 6 (2.7%), tests_pri_-950: 1.14 (0.5%), tests_pri_-900: 0.96 (0.5%), tests_pri_-400: 22 (10.4%), check_bayes: 21 (9.9%), b_tokenize: 6 (2.6%), b_tok_get_all: 6 (2.8%), b_comp_prob: 1.61 (0.8%), b_tok_touch_all: 4.2 (2.0%), b_finish: 0.76 (0.4%), tests_pri_0: 148 (69.9%), check_dkim_signature: 0.46 (0.2%), check_dkim_adsp: 2.9 (1.3%), tests_pri_500: 5 (2.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH tty-next 6/6] devpts: Change the owner of /dev/pts/ptmx to the mounter of /dev/pts X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In 99.99% of the cases only root in a user namespace can mount /dev/pts and in those cases the owner of /dev/pts/ptmx will remain root.root In the oddball case where someone else has CAP_SYS_ADMIN this code modifies the /dev/pts mount code to use current_fsuid and current_fsgid as the values to use when creating the /dev/ptmx inode. As is done when any other file is created. This is a code simplification, and it allows running without a root user entirely. Signed-off-by: "Eric W. Biederman" --- fs/devpts/inode.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 17593d3fcdbe..442d1a7e671b 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -272,13 +272,8 @@ static int mknod_ptmx(struct super_block *sb) struct dentry *root = sb->s_root; struct pts_fs_info *fsi = DEVPTS_SB(sb); struct pts_mount_opts *opts = &fsi->mount_opts; - kuid_t root_uid; - kgid_t root_gid; - - root_uid = make_kuid(current_user_ns(), 0); - root_gid = make_kgid(current_user_ns(), 0); - if (!uid_valid(root_uid) || !gid_valid(root_gid)) - return -EINVAL; + kuid_t ptmx_uid = current_fsuid(); + kgid_t ptmx_gid = current_fsgid(); inode_lock(d_inode(root)); @@ -309,8 +304,8 @@ static int mknod_ptmx(struct super_block *sb) mode = S_IFCHR|opts->ptmxmode; init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); - inode->i_uid = root_uid; - inode->i_gid = root_gid; + inode->i_uid = ptmx_uid; + inode->i_gid = ptmx_gid; d_add(dentry, inode); -- 2.8.3