From patchwork Thu May 28 19:42:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 6501471 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C605DC0020 for ; Thu, 28 May 2015 19:49:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F2E920767 for ; Thu, 28 May 2015 19:48:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F190E20765 for ; Thu, 28 May 2015 19:48:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754159AbbE1Tr2 (ORCPT ); Thu, 28 May 2015 15:47:28 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:33950 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754026AbbE1Tr0 (ORCPT ); Thu, 28 May 2015 15:47:26 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1Yy3m1-0001hI-9p; Thu, 28 May 2015 13:47:25 -0600 Received: from 67-3-205-90.omah.qwest.net ([67.3.205.90] helo=x220.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1Yy3lw-0006Px-Ip; Thu, 28 May 2015 13:47:25 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Andy Lutomirski Cc: Alexander Larsson , James Bottomley , gnome-os-list@gnome.org, Linux Containers , "linux-kernel\@vger.kernel.org" , mclasen@redhat.com, Linux FS Devel References: <1427447013.2250.9.camel@HansenPartnership.com> <1427788642.4411.12.camel@redhat.com> <1427807248.2117.117.camel@HansenPartnership.com> <1427808184.2117.122.camel@HansenPartnership.com> <1427810118.2117.126.camel@HansenPartnership.com> <1427810886.2117.129.camel@HansenPartnership.com> <1427811444.4411.20.camel@redhat.com> <1427969525.3559.120.camel@HansenPartnership.com> <1427984969.13651.11.camel@redhat.com> <87zj6qs7v8.fsf@x220.int.ebiederm.org> <87oal4odne.fsf@x220.int.ebiederm.org> <1432832511.21304.6.camel@redhat.com> Date: Thu, 28 May 2015 14:42:22 -0500 In-Reply-To: (Andy Lutomirski's message of "Thu, 28 May 2015 10:30:39 -0700") Message-ID: <87siagh4kh.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-XM-AID: U2FsdGVkX1/PvDG6ctr3mKu+0JqMfBbKjwyTh/WQvkM= X-SA-Exim-Connect-IP: 67.3.205.90 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Andy Lutomirski X-Spam-Relay-Country: X-Spam-Timing: total 4158 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 4.3 (0.1%), b_tie_ro: 3.1 (0.1%), parse: 3.9 (0.1%), extract_message_metadata: 19 (0.5%), get_uri_detail_list: 5 (0.1%), tests_pri_-1000: 8 (0.2%), tests_pri_-950: 1.08 (0.0%), tests_pri_-900: 0.88 (0.0%), tests_pri_-400: 45 (1.1%), check_bayes: 43 (1.0%), b_tokenize: 15 (0.4%), b_tok_get_all: 14 (0.3%), b_comp_prob: 6 (0.1%), b_tok_touch_all: 5 (0.1%), b_finish: 1.02 (0.0%), tests_pri_0: 509 (12.2%), tests_pri_500: 3558 (85.6%), poll_dns_idle: 3550 (85.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] devpts: Add ptmx_uid and ptmx_gid options X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Andy Lutomirski writes: > On Thu, May 28, 2015 at 10:01 AM, Alexander Larsson wrote: >> On Thu, 2015-05-28 at 11:44 -0500, Eric W. Biederman wrote: >>> Andy Lutomirski writes: >>> >>> > On Thu, Apr 2, 2015 at 11:27 AM, Eric W. Biederman >>> > wrote: >>> > > Andy Lutomirski writes: >>> > > >>> > > > On Thu, Apr 2, 2015 at 7:29 AM, Alexander Larsson < >>> > > > alexl@redhat.com> wrote: >>> > > > > On Thu, 2015-04-02 at 07:06 -0700, Andy Lutomirski wrote: >>> > > > > > On Thu, Apr 2, 2015 at 3:12 AM, James Bottomley >>> > > > > > wrote: >>> > > > > > > On Tue, 2015-03-31 at 16:17 +0200, Alexander Larsson >>> > > > > > > wrote: >>> > > > > > > > On tis, 2015-03-31 at 17:08 +0300, James Bottomley >>> > > > > > > > wrote: >>> > > > > > > > > On Tue, 2015-03-31 at 06:59 -0700, Andy Lutomirski >>> > > > > > > > > wrote: >>> > > > > > > > > > >>> > > > > > > > > > I don't think that this is correct. That user can >>> > > > > > > > > > already create a >>> > > > > > > > > > nested userns and map themselves as 0 inside it. >>> > > > > > > > > > Then they can mount >>> > > > > > > > > > devpts. >>> > > > > > > > > >>> > > > > > > > > I don't mind if they create a container and control >>> > > > > > > > > the isolated ttys in >>> > > > > > > > > that sub container in the VPS; that's fine. I do >>> > > > > > > > > mind if they get >>> > > > > > > > > access to the ttys in the VPS. >>> > > > > > > > > >>> > > > > > > > > If you can convince me (and the rest of Linux) that >>> > > > > > > > > the tty subsystem >>> > > > > > > > > should be mountable by an unprivileged user >>> > > > > > > > > generally, then what you >>> > > > > > > > > propose is OK. >>> > > > > > > > >>> > > > > > > > That is controlled by the general rights to mount >>> > > > > > > > stuff. I.e. unless you >>> > > > > > > > have CAP_SYS_ADMIN in the VPS container you will not be >>> > > > > > > > able to mount >>> > > > > > > > devpts there. You can only do it in a subcontainer >>> > > > > > > > where you got >>> > > > > > > > permissions to mount via using user namespaces. >>> > > > > > > >>> > > > > > > OK let me try again. Fine, if you want to speak >>> > > > > > > capabilities, you've >>> > > > > > > given a non-root user an unexpected capability (the >>> > > > > > > capability of >>> > > > > > > creating a ptmx device). But you haven't used a >>> > > > > > > capability separation >>> > > > > > > to do this, you've just hard coded it via a mount >>> > > > > > > parameter mechanism. >>> > > > > > > >>> > > > > > > If you want to do this thing, do it properly, so it's >>> > > > > > > acceptable to the >>> > > > > > > whole of Linux, not a special corner case for one >>> > > > > > > particular type of >>> > > > > > > container. >>> > > > > > > >>> > > > > > > Security breaches are created when people code in >>> > > > > > > special, little used, >>> > > > > > > corner cases because they don't get as thoroughly tested >>> > > > > > > and inspected >>> > > > > > > as generally applicable mechanisms. >>> > > > > > > >>> > > > > > > What you want is to be able to use the tty subsystem as a >>> > > > > > > non root user: >>> > > > > > > fine, but set that up globally, don't hide it in >>> > > > > > > containers so a lot >>> > > > > > > fewer people care. >>> > > > > > >>> > > > > > I tend to agree, and not just for the tty subsystem. This >>> > > > > > is an >>> > > > > > attack surface issue. With unprivileged user namespaces, >>> > > > > > unprivileged >>> > > > > > users can create mount namespaces (probably a good thing >>> > > > > > for bind >>> > > > > > mounts, etc), network namespaces (reasonably safe by >>> > > > > > themselves), >>> > > > > > network interfaces and iptables rules (scary), fresh >>> > > > > > instances/superblocks of some filesystems (scariness >>> > > > > > depends on the fs >>> > > > > > -- tmpfs is probably fine), and more. >>> > > > > > >>> > > > > > I think we should have real controls for this, and this is >>> > > > > > mostly >>> > > > > > Eric's domain. Eric? A silly issue that sometimes >>> > > > > > prevents devpts >>> > > > > > from being mountable isn't a real control, though. >>> > > >>> > > I thought the controls for limiting how much of the userspace API >>> > > an application could use were called seccomp and seccomp2. >>> > > >>> > > Do we need something like a PAM module so that we can set up >>> > > these >>> > > controls during login? >>> > > >>> > > > > I'm honestly surprised that non-root is allowed to mount >>> > > > > things in >>> > > > > general with user namespaces. This was long disabled use for >>> > > > > non-root in >>> > > > > Fedora, but it is now enabled. >>> > > > > >>> > > > > For instance, using loopback mounted files you could probably >>> > > > > attack >>> > > > > some of the less well tested filesystem implementations by >>> > > > > feeding them >>> > > > > fuzzed data. >>> > > > > >>> > > > >>> > > > You actually can't do that right now. Filesystems have to opt >>> > > > in to >>> > > > being mounted in unprivileged user namespaces, and no >>> > > > filesystems with >>> > > > backing stores have opted in. devpts has, but it's buggy >>> > > > without this >>> > > > patch IMO. >>> > > >>> > > Arguably you should use two user namespaces. The first to do >>> > > what you >>> > > want to as root the second to run as the uid you want to run as. >>> > > >>> > > > > Anyway, I don't see how this affects devpts though. If you're >>> > > > > running in >>> > > > > a container (or uncontained), as a regular users with no >>> > > > > mount >>> > > > > capabilities you can already mount a devpts filesystem if you >>> > > > > create a >>> > > > > subbcontainer with user namespaces and map your uid to 0 in >>> > > > > the >>> > > > > subcontainer. Then you get a new ptmx device that you can do >>> > > > > whatever >>> > > > > you want with. The mount option would let you do the same, >>> > > > > except be >>> > > > > your regular uid in the subcontainer. >>> > > > > >>> > > > > The only difference outside of the subcontainer is that if >>> > > > > the outer >>> > > > > container has no uid 0 mapped, yet the user has CAP_SYSADMIN >>> > > > > rights in >>> > > > > that container. Then he can mount devpts in the outer >>> > > > > container where he >>> > > > > before could only mount it in an inner container. >>> > > > > >>> > > > >>> > > > Agreed. Also, devpts doesn't seem scary at all to me from a >>> > > > userns >>> > > > perspective. Regular users on normal systems can already use >>> > > > ptmx, >>> > > > and AFAICS basically all of the attack surface is already >>> > > > available >>> > > > through the normal /dev/ptmx node. >>> > > >>> > > My only real take is that there are a lot more places that you >>> > > need to >>> > > tweak beyond devpts. So this patch seemed lacking and boring. >>> > > >>> > > Beyond that until I get the mount namespace sorted out things are >>> > > pretty >>> > > much in a feature freeze because I can't multitask well enough to >>> > > do >>> > > complicated patches and take feature patches. >>> > > >>> > >>> > Eric, do you think you have time now to take a look at this patch? >>> >>> I am much closer. Escaping bind mounts is still not yet fixed but I >>> have code that almost works. >>> >>> My gut feel still says that two user namespaces one where your 0 is >>> mapped to your uid and a second where your uid is identity mapped is >>> the >>> preferrable configuration, and makes this patch unnecessary. >> >> I don't really understand this. My usecase is that I want a desktop app >> sandbox, it should run as the actual user that is running the graphical >> session mapped to its real uid. In this namespace i want a /dev/pts so >> that i can e.g. shell out to ssh and feed it a password on the tty >> prompt or similar. And i don't want to bind-mount in the host /dev/pts, >> because then the sandbox can read from the ttys of other apps. >> >> Where does the second namespace enter into this? >> > > I think Eric is suggesting making a user namespace that maps your uid > as 0, then making a mount namespace and mounting devpts, then making > *another* user namespace that maps your uid (seen as 0) back to > whatever nonzero number you want. > > That would probably work, but I think it's really ugly. I just looked and the number of places where we actually care if uid 0 is mapped is very small. Mostly just the places that have to deal with setuid applications. So I think the maintenance burden is much smaller that I would have expected. That said if we update /dev/pts to handle being mounted by a non-root user I expect what we actually want is to use the fsuid and fsgid of the caller of mount. That is less code and it does the right thing without effort, and it makes sense even outside of a user namespace context. Something like: Eric --- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index add566303c68..8fdaa6740f23 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -245,13 +245,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(); mutex_lock(&d_inode(root)->i_mutex); @@ -282,8 +277,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);