Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp307700ybi; Thu, 13 Jun 2019 16:38:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4hVkfoDcRrhy2OHogZEyY8JAQ7cGovnsUuwxGhXwGmdMW+A9MCEYBTSOPfrhMihjslcOx X-Received: by 2002:a65:60d9:: with SMTP id r25mr32798803pgv.228.1560469111550; Thu, 13 Jun 2019 16:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560469111; cv=none; d=google.com; s=arc-20160816; b=WYBy76dGZZLQ4pkBbnHDfnaUlboDMLGSoIlK2Qza0Gf2qCCMQEMlbx76iA5Tj7j5zI Pk7yc1OjHVKzS7xJsgQtzrgrOfqFWjdxJieYW6UVwr0ZVR7uyuMzkqVW6G48Dt+Jw/ID 7HlirkwOO9hUcNu3qgShDktTQPKAhrwrtp6krNjEIGkoVqe6ChYuYtZh5lijtsUrcASm pQCWwNJVkdPAETfRgOFZJKe6E5rKqqhMbxemrCtGpAL/9X2CTDFQkx9j9c5UWqRXGHHh 2JXweIgJ4PV2tPDmzwXcl+pGnapW4f6r59iNqbOoSBarlWDNTOJF5NPZ4rAPhXif//to cxCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=oodRWfym8vGhEJNTwBcKhJMKuWNGLtph+QGLWfAyKO0=; b=ZDY+VuqM5W+0kLe/UxGkZINtMyI3XiPqhqy06XCfraEQmhYkK/cWp4cyAjQjL3wO2G Ayrt++Nehn8w2xVgSiFCU2Df0Fg/UnQRZBw6TjYdkPFXVQqm9XR347Ho6oq6+48rFzVr dNs42HHLVgybIR1r73EC1CASw5oHn8ska+WYz6E+ATMN02J5MPT2v7+qGwtrQ7OIZU6Z PvMpBdRHHCEKPZDTO19xDj4f4R723RSN718wHBA5RFvMri2ujam96yhaXPCVuRBZdnOm oW4ZnYw3O/tRDI84Rv89pHd5rGoWbncWqo+alTrUkXISaEP3S8J0969R2lKyVVhjnYUn vGEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=BvbGJfCr; 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 j9si883008pgh.385.2019.06.13.16.38.15; Thu, 13 Jun 2019 16:38:31 -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=@brauner.io header.s=google header.b=BvbGJfCr; 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 S1727204AbfFMXhN (ORCPT + 99 others); Thu, 13 Jun 2019 19:37:13 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51441 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbfFMXhM (ORCPT ); Thu, 13 Jun 2019 19:37:12 -0400 Received: by mail-wm1-f68.google.com with SMTP id 207so465801wma.1 for ; Thu, 13 Jun 2019 16:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=oodRWfym8vGhEJNTwBcKhJMKuWNGLtph+QGLWfAyKO0=; b=BvbGJfCrFemSkbH88wzZyyFSZzIZCF3X5vaX3OL9UB8Lz6ZMFUlq6T7RtZ5xwzVe2m HGeBjbnEatgk9gSuh2WSiV+1vzf4BLyKfU6qbBz/4JMx/GGodTcx4WLzM+cUKFDgk7ut 8X7p3+SL7XYNw8+ei+6PhnS02p01XJ+5Xzs1Fn/fGsDgjjxrjpq6INY/46Ooh+ZdhAGK Z+wGDUrYd+UR1Q8ZFuUHNrQwf4ValMHY33hco3gNPx00Auyxm4rAcRlWv9qKAvua0nBx yvAtdRmzcUviT0Kw+M6SucHg8julb2219C8fnqqt8ccGYQs4MvzsDL0f34FkR2JospN9 pp4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=oodRWfym8vGhEJNTwBcKhJMKuWNGLtph+QGLWfAyKO0=; b=O6FtXcM1siUfEY+HbKgLqQcEPpI1V2XxktsKs3gGhgrBp/11VRM6Qfz1FBQQpXoti7 QAquwrFPQnASuLJhtsWmQle7+HWFnrSEWd1AUcp1QvBQsaZrS4ekiYZcb6D81RR50ApR 4o407aI5aCehsG0z1K3mUbTAw3JqdXdvlyZ37AvLnC0EeIR2l5Lf1lGjTYTscEJjq49U ei6fseRz92rIblDeAZdmeciGC7j+fz9iG7sSZqmJpjqj6nVUGUx52z26A+XmBKVlcyEi du4IOHKKQ8nWp3HL7OXBB91RaUy8VIaiv2YlI225RwWqgFjhQHt4Vl9ZwHUWMl2l/2QC Qf+Q== X-Gm-Message-State: APjAAAWCwtxuSupmQ7kWYZscLaOpiJWRwnV6iwonjrrQkN8qeuPRAWNS 4ly+kkHAkd7ii3F+cFhCnFvlxg== X-Received: by 2002:a7b:cd84:: with SMTP id y4mr5640506wmj.41.1560469029595; Thu, 13 Jun 2019 16:37:09 -0700 (PDT) Received: from brauner.io ([212.91.227.56]) by smtp.gmail.com with ESMTPSA id f13sm2169960wrt.27.2019.06.13.16.37.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 13 Jun 2019 16:37:09 -0700 (PDT) Date: Fri, 14 Jun 2019 01:37:07 +0200 From: Christian Brauner To: "Eric W. Biederman" Cc: Miklos Szeredi , Linus Torvalds , Al Viro , Linux List Kernel Mailing , linux-fsdevel , Linux API , David Howells Subject: Re: Regression for MS_MOVE on kernel v5.1 Message-ID: <20190613233706.6k6struu7valxaxy@brauner.io> References: <20190612225431.p753mzqynxpsazb7@brauner.io> <20190613132250.u65yawzvf4voifea@brauner.io> <871rzxwcz7.fsf@xmission.com> <878su5tadf.fsf@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <878su5tadf.fsf@xmission.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 13, 2019 at 04:59:24PM -0500, Eric W. Biederman wrote: > Miklos Szeredi writes: > > > On Thu, Jun 13, 2019 at 8:35 PM Eric W. Biederman wrote: > >> > >> Christian Brauner writes: > >> > >> > On Wed, Jun 12, 2019 at 06:00:39PM -1000, Linus Torvalds wrote: > >> >> On Wed, Jun 12, 2019 at 12:54 PM Christian Brauner wrote: > >> >> > > >> >> > The commit changes the internal logic to lock mounts when propagating > >> >> > mounts (user+)mount namespaces and - I believe - causes do_mount_move() > >> >> > to fail at: > >> >> > >> >> You mean 'do_move_mount()'. > >> >> > >> >> > if (old->mnt.mnt_flags & MNT_LOCKED) > >> >> > goto out; > >> >> > > >> >> > If that's indeed the case we should either revert this commit (reverts > >> >> > cleanly, just tested it) or find a fix. > >> >> > >> >> Hmm.. I'm not entirely sure of the logic here, and just looking at > >> >> that commit 3bd045cc9c4b ("separate copying and locking mount tree on > >> >> cross-userns copies") doesn't make me go "Ahh" either. > >> >> > >> >> Al? My gut feel is that we need to just revert, since this was in 5.1 > >> >> and it's getting reasonably late in 5.2 too. But maybe you go "guys, > >> >> don't be silly, this is easily fixed with this one-liner". > >> > > >> > David and I have been staring at that code today for a while together. > >> > I think I made some sense of it. > >> > One thing we weren't absolutely sure is if the old MS_MOVE behavior was > >> > intentional or a bug. If it is a bug we have a problem since we quite > >> > heavily rely on this... > >> > >> It was intentional. > >> > >> The only mounts that are locked in propagation are the mounts that > >> propagate together. If you see the mounts come in as individuals you > >> can always see/manipulate/work with the underlying mount. > >> > >> I can think of only a few ways for MNT_LOCKED to become set: > >> a) unshare(CLONE_NEWNS) > >> b) mount --rclone /path/to/mnt/tree /path/to/propagation/point > >> c) mount --move /path/to/mnt/tree /path/to/propgation/point > >> > >> Nothing in the target namespace should be locked on the propgation point > >> but all of the new mounts that came across as a unit should be locked > >> together. > > > > Locked together means the root of the new mount tree doesn't have > > MNT_LOCKED set, but all mounts below do have MNT_LOCKED, right? > > > > Isn't the bug here that the root mount gets MNT_LOCKED as well? Yes, we suspected this as well. We just couldn't pinpoint where the surgery would need to start. > > Yes, and the code to remove MNT_LOCKED is still sitting there in > propogate_one right after it calls copy_tree. It should be a trivial > matter of moving that change to after the lock_mnt_tree call. > > Now that I have been elightened about anonymous mount namespaces > I am suspecting that we want to take the user_namespace of the anonymous > namespace into account when deciding to lock the mounts. > > >> Then it breaking is definitely a regression that needs to be fixed. > >> > >> I believe the problematic change as made because the new mount > >> api allows attaching floating mounts. Or that was the plan last I > >> looked. Those floating mounts don't have a mnt_ns so will result > >> in a NULL pointer dereference when they are attached. > > > > Well, it's called anonymous namespace. So there *is* an mnt_ns, and > > its lifetime is bound to the file returned by fsmount(). > > Interesting. That has changed since I last saw the patches. > > Below is what will probably be a straight forward fix for the regression. Tested the patch just now applied on top of v5.1. It fixes the regression. Can you please send a proper patch, Eric? Tested-by: Christian Brauner Acked-by: Christian Brauner > > Eric > > diff --git a/fs/namespace.c b/fs/namespace.c > index ffb13f0562b0..a39edeecbc46 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -2105,6 +2105,7 @@ static int attach_recursive_mnt(struct mount *source_mnt, > /* Notice when we are propagating across user namespaces */ > if (child->mnt_parent->mnt_ns->user_ns != user_ns) > lock_mnt_tree(child); > + child->mnt.mnt_flags &= ~MNT_LOCKED; > commit_tree(child); > } > put_mountpoint(smp); > diff --git a/fs/pnode.c b/fs/pnode.c > index 7ea6cfb65077..012be405fec0 100644 > --- a/fs/pnode.c > +++ b/fs/pnode.c > @@ -262,7 +262,6 @@ static int propagate_one(struct mount *m) > child = copy_tree(last_source, last_source->mnt.mnt_root, type); > if (IS_ERR(child)) > return PTR_ERR(child); > - child->mnt.mnt_flags &= ~MNT_LOCKED; > mnt_set_mountpoint(m, mp, child); > last_dest = m; > last_source = child; > >