Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7023810ybi; Thu, 13 Jun 2019 08:18:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqydWLeiVwJVSZEu+1kK9VHHkVK1e8ibClMrhPHPKcqQlAOhLSLb74Eg0lnCZYUKtOE31QnY X-Received: by 2002:a17:90a:258b:: with SMTP id k11mr5917395pje.110.1560439118257; Thu, 13 Jun 2019 08:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560439118; cv=none; d=google.com; s=arc-20160816; b=edny9sC1n5Iep/8aSOfJpfKiXzwT8mTqAARc+qXnQ+puxLXXS8Qr7plFNQqLkoOcg4 9jhpPM88AFpbynlwA/TYCPJgr0g9EPHWyj/CNpxORCBUlIcBCOHwj/VM9DmrlMbKchUh 8wGlq9z2nidEt6A3duj4PjC5JY2Wa97i10MNuADVa/Nj0xAtGqtZH1bGeG1jvv/HpO4Z zBZA1KgZwjdw4U8uOqHA0g50jjrV05Cu18NidqyO+WQPeKW+nX6C/iINpP5OubzWq/JX /1N+TF9W7XvE0iFoDAdprOsUPoBP4hc+hheXD0WDQxYm5ZtNqrorNWawW2kK/T7m32Gu snVg== 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=wuAK6EQ80PyDNnpIyEX4qP2XC/coEnhgovta7yfYWxY=; b=yWKkwmH1AG5HqnFhQLeNCAAbk5l0LFv04YeOe7bdK2efbkXyBTlTalZTH2n+gsCQ6z 200ZP1nKGhO8brOlEEhBwLfZfvzBG4E9E8hPUUWckY91ffXY9SN0GZw7BxD4uNtTMr36 m4ImDws23QKGKCV+D+2/c4Secuz46SfwxwkRxTpegiwSgpa0qFWKMr/LeRoKn0f53AOT A76wp5h+U1nJrLeny+8M3M1hX8nOH0RB5VCgE3RXcwvoUU5Y90pIV8Wf2J54RhUElKiX ZqD6ixmGgbSs/1D8Eub2r59bxsoeHbXwHH11GGhCqYP3eCtScUqdrWiG9ZO8BvtPh9Tt MZaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=JMQ0l3Nr; 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 c2si3156477pls.346.2019.06.13.08.18.23; Thu, 13 Jun 2019 08:18:38 -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=JMQ0l3Nr; 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 S1732191AbfFMPRU (ORCPT + 99 others); Thu, 13 Jun 2019 11:17:20 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35752 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732194AbfFMNWz (ORCPT ); Thu, 13 Jun 2019 09:22:55 -0400 Received: by mail-wm1-f68.google.com with SMTP id c6so10145312wml.0 for ; Thu, 13 Jun 2019 06:22:54 -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=wuAK6EQ80PyDNnpIyEX4qP2XC/coEnhgovta7yfYWxY=; b=JMQ0l3NrX2S5rxk2gqdSAV86GVbkXTUcGPYAfocG6ziyl8sqM3X+SMNxQgaJ7/z2U5 HJ4eyfVwdzmcB0Zb1Y1LC+S5FHiMrDv9M1bCkfwvadnhM5bHTiVz3TpWvQc0LwHv14Bg EaXkN7lOTGprcoVn6/xbN8yMBrS2n60nsukmJN/V6yw78xXOI/PjvhfZRKH6E0vgUR91 feM1JDdZdSetkpv4okXsDVJL2RxQkpL5Frr7VMsmNVAfI3iJCf5GlflsDSQv+1i5VPXO 4SvN2fm0I6lD8JtK5KrWSuUpCZ4R1A0ZwKaMBsKzvg9ZqXYmaPdBL3YqRQwlfvRmO3Sa Q9fQ== 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=wuAK6EQ80PyDNnpIyEX4qP2XC/coEnhgovta7yfYWxY=; b=pvD3715tJiqrmDbp835cFKPS3pn6NGDgNoDUD66Z1RXGX/XuSPVYM2aieB/8bgDIWQ Bh/bxls8GahL3tgVb61G6t+E6W6pCVgdiNwIbGdbY5+VOAboNooGfxZowI68wYpDiq85 uVQ6WoTjpZPqg8SmP8WQ1urFpQMLobh+dImi0BOxzJjSwAPn7bPqca2u11vJGE7B+4sw KYOhNSoOmC68yq1ZOBCcJU5M6GsxSRAlctbN4FEabABd/JpV9CEtasxL9feQ2EsDt/K/ Uez6bo8z8BLb7XILKS7fOteuz0+xKeuzddfyxUAtjhcR62MK9PDAlJg4vqESrU3rx4D7 qWWw== X-Gm-Message-State: APjAAAXGCFSX2IKLWV5f2CHv3z3njNNDjukkyioLM9gM4xbhEerHyZy4 GPlhd7wPba07gtbAeokffGiQ6w== X-Received: by 2002:a1c:f519:: with SMTP id t25mr3944137wmh.58.1560432173272; Thu, 13 Jun 2019 06:22:53 -0700 (PDT) Received: from brauner.io ([212.91.227.56]) by smtp.gmail.com with ESMTPSA id f3sm2842924wre.93.2019.06.13.06.22.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 13 Jun 2019 06:22:52 -0700 (PDT) Date: Thu, 13 Jun 2019 15:22:51 +0200 From: Christian Brauner To: Linus Torvalds Cc: Al Viro , Linux List Kernel Mailing , linux-fsdevel , Linux API , David Howells , "Eric W. Biederman" Subject: Re: Regression for MS_MOVE on kernel v5.1 Message-ID: <20190613132250.u65yawzvf4voifea@brauner.io> References: <20190612225431.p753mzqynxpsazb7@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... So this whole cross-user+mnt namespace propagation mechanism comes with a big hammer that Eric indeed did introduce a while back which is MNT_LOCKED (cf. [1] for the relevant commit). Afaict, MNT_LOCKED is (among other cases) supposed to prevent a user+mnt namespace pair to get access to a mount that is hidden underneath an additional mount. Consider the following scenario: sudo mount -t tmpfs tmpfs /mnt sudo mount --make-rshared /mnt sudo mount -t tmpfs tmpfs /mnt sudo mount --make-rshared /mnt unshare -U -m --map-root --propagation=unchanged umount /mnt # or mount --move -mnt /opt The last umount/MS_MOVE is supposed to fail since the mount is locked with MNT_LOCKED since umounting or MS_MOVing the mount would reveal the underlying mount which I didn't have access to prior to the creation of my user+mnt namespace pair. (Whether or not this is a reasonable security mechanism is a separate discussion.) But now consider the case where from the ancestor user+mnt namespace pair I do: # propagate the mount to the user+mount namespace pair sudo mount -t tmpfs tmpfs /mnt # switch to the child user+mnt namespace pair umount /mnt # or mount --move /mnt /opt That umount/MS_MOVE should work since that mount was propagated to the unprivileged task after the user+mnt namespace pair was created. Also, because I already had access to the underlying mount in the first place and second because this is literally the only way - we know of - to inject a mount cross mount namespaces and this is a must have feature that quite a lot of users rely on. Christian [1]: git show 5ff9d8a65ce80efb509ce4e8051394e9ed2cd942