Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4797397ybl; Mon, 13 Jan 2020 21:14:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwiw6LolQkoVT5juUuEpr3g/2NV3gc/og6W2d8zvrw/gyv2ahuD2s8+oWahhPzPX5mJmz/V X-Received: by 2002:a9d:7852:: with SMTP id c18mr15033919otm.247.1578978855947; Mon, 13 Jan 2020 21:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578978855; cv=none; d=google.com; s=arc-20160816; b=aHiGD4rNQRGIS5LhVgRI3hm/2WLKUbSDeGk/JsgKhswuVyt+dyFOd6xT8Q1Is8kCA9 vT/3jFLigqdGOCA1lrd9TNI838aEaAucb+hbkvjgd+qsWrhg4skPxw9qpxqt4e2FCzph 4qEfvhQpiRESG1BEp3SKeKbJbahaIiitBg0CkOdt28RLH1RzNweXkQM2CDOhMg3pGklF JqfPjCjS/fL2X3qL46IK/7E28pcNlCuEFq7jcnXzXsO18rfL+Hr7I209pKuVoRUzMFA1 hGgnC0uXN8xcB47sDIv5PqdQ4o6IB6TchLIwNWX+svza4drdj/km6yQ2o9VWqCGWdM2K DOUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Z5n9uAZV/1D2N0mzHb+DHI6y9RIul5PFyLvHnnvHZ74=; b=CInKSAUN3sv5htY8QjrnWyTOKREGhWf5vXuK6NUVjKMeRyykySA+vZMiSrlanUy3py /hzkyns5nXwUJGLxJHnBIrHm+Y3FvrbEEsOYxV/PwbAedwv6nD1KzTjJrZ4m390g8+8P OTpFkSc1ZQ1DBi8o2jcI+i66bdl5FWz8pZtmJuKhg1qU2oRmIT2zmFKWzdfKSKSwXYOx Hc0AnoATGk9xTvkGsF5CK1Ny54AqLcIr+/xzLwScXdl5WdIp9YBejjhI2NaYuv86qHzo eJn22cMrUVa0G/3t0HfM5p1xoK/t0oU+DB8DQr/MgivoIiPN/TG8fxuc07tYTvw4ZciM 9ueQ== 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 12si6706157oiz.131.2020.01.13.21.14.02; Mon, 13 Jan 2020 21:14:15 -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 S1726156AbgANFM6 (ORCPT + 99 others); Tue, 14 Jan 2020 00:12:58 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:33610 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgANFM6 (ORCPT ); Tue, 14 Jan 2020 00:12:58 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1irEVU-007mgT-4P; Tue, 14 Jan 2020 05:12:48 +0000 Date: Tue, 14 Jan 2020 05:12:48 +0000 From: Al Viro To: Aleksa Sarai Cc: Linus Torvalds , David Howells , Eric Biederman , stable , Christian Brauner , Serge Hallyn , dev@opencontainers.org, Linux Containers , Linux API , linux-fsdevel , Linux Kernel Mailing List , Ian Kent Subject: Re: [PATCH RFC 0/1] mount: universally disallow mounting over symlinks Message-ID: <20200114051248.GX8904@ZenIV.linux.org.uk> References: <20200101005446.GH4203@ZenIV.linux.org.uk> <20200101030815.GA17593@ZenIV.linux.org.uk> <20200101144407.ugjwzk7zxrucaa6a@yavin.dot.cyphar.com> <20200101234009.GB8904@ZenIV.linux.org.uk> <20200102035920.dsycgxnb6ba2jhz2@yavin.dot.cyphar.com> <20200103014901.GC8904@ZenIV.linux.org.uk> <20200108031314.GE8904@ZenIV.linux.org.uk> <20200110210719.ktg3l2kwjrdutlh6@yavin> <20200114045733.GW8904@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200114045733.GW8904@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 14, 2020 at 04:57:33AM +0000, Al Viro wrote: > On Sat, Jan 11, 2020 at 08:07:19AM +1100, Aleksa Sarai wrote: > > > If I'm understanding this proposal correctly, this would be a problem > > for the libpathrs use-case -- if this is done then there's no way to > > avoid a TOCTOU with someone mounting and the userspace program checking > > whether something is a mountpoint (unless you have Linux >5.6 and > > RESOLVE_NO_XDEV). Today, you can (in theory) do it with MNT_EXPIRE: > > > > 1. Open the candidate directory. > > 2. umount2(MNT_EXPIRE) the fd. > > * -EINVAL means it wasn't a mountpoint when we got the fd, and the > > fd is a stable handle to the underlying directory. > > * -EAGAIN or -EBUSY means that it was a mountpoint or became a > > mountpoint after the fd was opened (we don't care about that, but > > fail-safe is better here). > > 3. Use the fd from (1) for all operations. > > ... except that foo/../bar *WILL* cross into the covering mount, on any > kernel that supports ...at(2) at all, so I would be very cautious about > any kind "hardening" claims in that case. > > I'm not sure about Linus' proposal - it looks rather convoluted and we > get a hard to describe twist of semantics in an area (procfs symlinks > vs. mount traversal) on top of everything else in there... PS: one thing that might be interesting is exposing LOOKUP_DOWN via AT_... flag - it would allow to request mount traversals at the starting point explicitly. Pretty much all code needed for that is already there; all it would take is checking the flag in path_openat() and path_parentat() and having handle_lookup_down() called there, same as in path_lookupat(). A tricky question is whether such flag should affect absolute symlinks - i.e. chdir /foo ln -s /bar barf overmount / do lookup with that flag for /bar/splat do lookup with that flag for barf/splat Do we want the same results in both calls? The first one would traverse mounts on / and walk into /bar/splat in overmounting; the second - see no mounts whatsoever on current directory (/foo in old root), see the symlink to "/bar", jump to process' root and proceed from there, first for "bar", then "splat" in it...