From: ebiederm@xmission.com (Eric W. Biederman) Subject: Re: [PATCH] umount: Do not allow unmounting rootfs. Date: Tue, 07 Oct 2014 16:35:10 -0700 Message-ID: <878ukrmp1t.fsf@x220.int.ebiederm.org> References: <1412683212-28077-1-git-send-email-avagin@openvz.org> <20141007132431.GF7996@ZenIV.linux.org.uk> <20141007134011.GA569@paralelels.com> <87vbnv3cl1.fsf_-_@x220.int.ebiederm.org> <20141007195307.GA23694@paralelels.com> <87iojvvbqe.fsf@x220.int.ebiederm.org> <20141007215959.GA4622@paralelels.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Al Viro , Andrey Vagin , , , Serge Hallyn To: Andrew Vagin Return-path: In-Reply-To: <20141007215959.GA4622@paralelels.com> (Andrew Vagin's message of "Wed, 8 Oct 2014 02:00:00 +0400") Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Andrew Vagin writes: > On Tue, Oct 07, 2014 at 01:58:01PM -0700, Eric W. Biederman wrote: >> Andrew Vagin writes: >> >> > On Tue, Oct 07, 2014 at 12:27:06PM -0700, Eric W. Biederman wrote: >> >> >> >> Which in practice is totally uninteresting. Only the global root user can >> >> do it, and it is just a stupid thing to do. >> >> >> >> However that is no excuse to allow a silly way to oops the kernel. >> >> >> >> We can avoid this silly problem by setting MNT_LOCKED on the rootfs >> >> mount point and thus avoid needing any special cases in the unmount >> >> code. >> > >> > I had this idea too, but it doesn't work. >> > >> > MNT_LOCKED isn't inherited, if the privileged user creates a new mount >> > namespace. >> > >> > So "unshame -m ./nsenter" reproduces the same BUG. >> >> Which broken tree do you have where MNT_LOCKED is not inherited? > > It is Linus' tree with your patch. > > I commented out one line and the BUG isn't triggered any more. Ok. That is very very weird. It works for me and not for you. Doh! I ran your test program first on the primary mount namespace and didn't have /proc mounted when I tried to run your test program later. Thanks for the hint about copy_tree that does seem to be where the logic goes haywire. In copy_mnt_ns we want an exact copy not a partial copy. The good news is that this bug could only affect rootfs, so it is not a security hole with respect to mount namespaces, created with user namespace permissions. mount --rbind and mount propogation should not be locked to their parent mounts so we do need to clear MNT_LOCKED in a few places. A patch that fixes copy_tree carefully in a moment. Eric