Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2771404ybc; Wed, 13 Nov 2019 21:46:03 -0800 (PST) X-Google-Smtp-Source: APXvYqywMa1jVcBFchnBwsLfOSnHgbK1UOOFzbN4jGW4hqoAiJSqy2GZywNkltnbIyCE6Re9mkeq X-Received: by 2002:a50:898a:: with SMTP id g10mr7960496edg.191.1573710362952; Wed, 13 Nov 2019 21:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573710362; cv=none; d=google.com; s=arc-20160816; b=DQjD0AhFojrmy/ZqCm0qwFuWa+drEe32o3aR+J4cYb3mfbbvCN6BuyTY+nW8bkPCh/ iPH5OVi11ID+CwDdeG/luAHr9GiJVO+uCHuX2lX4/D9a8YoRqZfT5+e/1s4R6ONA8DUG zwvrW7JHKstFb4jRy3bqQ0TE6kbGRRGNz606h7plBiDbP/0Qcx7jj03FeZOQLoc1jn/n YgGjaNoTC2lgNTvbeELRiXH1ugRg/0OCNuuFjwVeA8LwnyMSrqAiTElxHO0kMjJmdYEH 5Tl4IE1K61FYHlUQyw2ntfijkiow6ig/kmj2vlGLCkRRGhQBgvL6/VfU4noKLXIwzfM6 T6pQ== 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; bh=0KqYnjv9QfFis8o2QEKo0g2pawSH9hw5IIlbCdytdpQ=; b=k9HVpF+ejidK0ZE9qtBL3LkhRlhOnpphVGQHxOLrpxwZZ0KiJZ78SoQbJcUVcRHvb2 yttIphH0MU/7nPv0CsgunGs2f/LmDdQRbwNS0L4zflxLx03m+HJYGvbrTPMcniKLdiME +hTPPokc96pWzR9H1Ob7NRuPkOskwYEoTdnvU4rflBbD7n60oLiTJ4GBvN3CRAjMSUbw Cp0JG8CX3evoAxyH1AAMA+23VfaGXvK/YO6FhCtDcUJimuhlX12KHxRLzYvILbLOi+RQ cba0LNFmb55stK3XuQyg8E9Mcj2nmn0hs824wnsdiFPz0EBJaD9/Sg3TBY0aEJLJhyw2 26yQ== ARC-Authentication-Results: i=1; mx.google.com; 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 h15si2803267ejt.387.2019.11.13.21.45.36; Wed, 13 Nov 2019 21:46:02 -0800 (PST) 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; 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 S1726202AbfKNFoy (ORCPT + 99 others); Thu, 14 Nov 2019 00:44:54 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:33296 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725601AbfKNFox (ORCPT ); Thu, 14 Nov 2019 00:44:53 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1iV7v2-0000Ln-Fm; Thu, 14 Nov 2019 05:43:48 +0000 Date: Thu, 14 Nov 2019 05:43:48 +0000 From: Al Viro To: Aleksa Sarai Cc: Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Christian Brauner , David Drysdale , Andy Lutomirski , Linus Torvalds , Eric Biederman , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Tycho Andersen , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Aleksa Sarai , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, libc-alpha@sourceware.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: Re: [PATCH v15 3/9] namei: LOOKUP_NO_XDEV: block mountpoint crossing Message-ID: <20191114054348.GH26530@ZenIV.linux.org.uk> References: <20191105090553.6350-1-cyphar@cyphar.com> <20191105090553.6350-4-cyphar@cyphar.com> <20191113013630.GZ26530@ZenIV.linux.org.uk> <20191114044945.ldedzjrb4s7i7irr@yavin.dot.cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191114044945.ldedzjrb4s7i7irr@yavin.dot.cyphar.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 14, 2019 at 03:49:45PM +1100, Aleksa Sarai wrote: > On 2019-11-13, Al Viro wrote: > > On Tue, Nov 05, 2019 at 08:05:47PM +1100, Aleksa Sarai wrote: > > > > > @@ -862,6 +870,8 @@ static int nd_jump_root(struct nameidata *nd) > > > void nd_jump_link(struct path *path) > > > { > > > struct nameidata *nd = current->nameidata; > > > + > > > + nd->last_magiclink.same_mnt = (nd->path.mnt == path->mnt); > > > path_put(&nd->path); > > > > > > nd->path = *path; > > > @@ -1082,6 +1092,10 @@ const char *get_link(struct nameidata *nd) > > > if (nd->flags & LOOKUP_MAGICLINK_JUMPED) { > > > if (unlikely(nd->flags & LOOKUP_NO_MAGICLINKS)) > > > return ERR_PTR(-ELOOP); > > > + if (unlikely(nd->flags & LOOKUP_NO_XDEV)) { > > > + if (!nd->last_magiclink.same_mnt) > > > + return ERR_PTR(-EXDEV); > > > + } > > > } > > > > Ugh... Wouldn't it be better to take that logics (some equivalent thereof) > > into nd_jump_link()? Or just have nd_jump_link() return an error... > > This could be done, but the reason for stashing it away in > last_magiclink is because of the future magic-link re-opening patches > which can't be implemented like that without putting the open_flags > inside nameidata (which was decided to be too ugly a while ago). > > My point being that I could implement it this way for this series, but > I'd have to implement something like last_magiclink when I end up > re-posting the magic-link stuff in a few weeks. > > Looking at all the nd_jump_link() users, the other option is to just > disallow magic-link crossings entirely for LOOKUP_NO_XDEV. The only > thing allowing them permits is to resolve file descriptors that are > pointing to the same procfs mount -- and it's unclear to me how useful > that really is (apparmorfs and nsfs will always give -EXDEV because > aafs_mnt and nsfs_mnt are internal kernel vfsmounts). I would rather keep the entire if (nd->flags & LOOKUP_MAGICLINK_JUMPED) out of the get_link(). If you want to generate some error if nd_jump_link() has been called, just do it right there. The fewer pieces of state need to be carried around, the better... And as for opening them... Why would you need full open_flags in there? Details, please...