Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp15871805ybl; Tue, 31 Dec 2019 16:59:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwU4NB8zqZOTk7A5W4BMRd3sT+JBYZHVjtwLbCFgG7SIcZ8ZyEN423aS3jaM/UkaHLTcNwn X-Received: by 2002:a05:6402:c82:: with SMTP id cm2mr78540265edb.19.1577840373161; Tue, 31 Dec 2019 16:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577840373; cv=none; d=google.com; s=arc-20160816; b=C3rnEZ9oA4jn8ZrX02cmHhf4BGLTarb1VTzWS/eiTEOa7qv4FAU8KvdzHQzKokGRxq 4SOTkatVkniNC45SG7/rT6SSqXY1FyRvCaiQtX9plpPGd1T2H74CHsjeDwy8v3yISBT+ CcdTBPWV4qABH5Q7EkSJujoZ9OJhr0MJKUJslgA2uIg4sE6oRGQdjlZMR7C2IJXZ93l7 oIknf/e2DPBlAEITUm/LE5RzLwwG0kNoFFSV2STRZ0GaMhcRn4EuscFMUtI6SvI/dUo3 q3QRoc1K451JjoSZqkDXcVy6iOkyzOkbOsvKPRQPecvjbNHZUvxLMMu2rNIfFk/ErECw fWcQ== 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=50LZ6c04bKefdehPYORJlFWjS0n7SHWZ6fqx/9+2KX4=; b=zFkQvdiFk7XB99oVHbaekQgnj7YvSbSYqTBcAiSbjwJT/EDRncw1b1HU3qz8brcahK 7LpIC+UG5LjDfTTasnZLXBoLEFK3s69yvyCTrFY1wTY7VpDT3trkn2wdFEBFEAtACZWb BmTRY/NPO51VkhWl05IFKEX2IFZOsS7xP900RoQUdCzxKYC5olbabIKofK4juuU/uowo Cu2nCVT2FO9eNKm27hYXS+ISCn+C4OBN1OhWVpOU4tEtetMYLY9gfl8y9iX+iQxY3JRH /BLRqA06MFf0SxZG1Osaoa5+iJsnZx5T2RECQ1wnbjgDrOmIaQgyMn0/7Jyi22Qiw5sp tBSw== 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 w26si33748751edl.301.2019.12.31.16.58.55; Tue, 31 Dec 2019 16:59:33 -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 S1727142AbgAAAy6 (ORCPT + 99 others); Tue, 31 Dec 2019 19:54:58 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:40944 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgAAAy6 (ORCPT ); Tue, 31 Dec 2019 19:54:58 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1imSHe-0004Zd-1d; Wed, 01 Jan 2020 00:54:46 +0000 Date: Wed, 1 Jan 2020 00:54:46 +0000 From: Al Viro To: Aleksa Sarai Cc: David Howells , Eric Biederman , Linus Torvalds , stable@vger.kernel.org, Christian Brauner , Serge Hallyn , dev@opencontainers.org, containers@lists.linux-foundation.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC 0/1] mount: universally disallow mounting over symlinks Message-ID: <20200101005446.GH4203@ZenIV.linux.org.uk> References: <20191230052036.8765-1-cyphar@cyphar.com> <20191230054413.GX4203@ZenIV.linux.org.uk> <20191230054913.c5avdjqbygtur2l7@yavin.dot.cyphar.com> <20191230072959.62kcojxpthhdwmfa@yavin.dot.cyphar.com> <20200101004324.GA11269@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200101004324.GA11269@ZenIV.linux.org.uk> 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 Wed, Jan 01, 2020 at 12:43:24AM +0000, Al Viro wrote: > I'm not sure if you have caught anything else, but we really, really should *NOT* > consider the LAST_BIND as "maybe we should follow the result" material. So > at least the following is needed; could you check if anything else remains > with that applied? > > diff --git a/fs/namei.c b/fs/namei.c > index d6c91d1e88cb..d4fbbda8a7ff 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2656,10 +2656,7 @@ mountpoint_last(struct nameidata *nd) > nd->flags &= ~LOOKUP_PARENT; > > if (unlikely(nd->last_type != LAST_NORM)) { > - error = handle_dots(nd, nd->last_type); > - if (error) > - return error; > - path.dentry = dget(nd->path.dentry); > + return handle_dots(nd, nd->last_type); > } else { > path.dentry = d_lookup(dir, &nd->last); > if (!path.dentry) { Note, BTW, that lookup_last() (aka walk_component()) does just that - we only hit step_into() on LAST_NORM. The same goes for do_last(). mountpoint_last() not doing the same is _not_ intentional - it's definitely a bug. Consider your testcase; link points to . here. So the only thing you could expect from trying to follow it would be the directory 'link' lives in. And you don't have it when you reach the fscker via /proc/self/fd/3; what happens instead is nd->path set to ./link (by nd_jump_link()) *AND* step_into() called, pushing the same ./link onto stack. It violates all kinds of assumptions made by fs/namei.c - when pushing a symlink onto stack nd->path is expected to contain the base directory for resolving it. I'm fairly sure that this is the cause of at least some of the insanity you've caught; there always could be something else, of course, but this hole needs to be closed in any case.