Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2493227ybh; Mon, 9 Mar 2020 07:02:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtbgzxxEPRvsDSIMy06np/38TG+w3ZpeM2eX1nwZjQ216LNaSiFkr08LzcQwrxUYPYhDeCD X-Received: by 2002:a05:6830:1504:: with SMTP id k4mr13746984otp.244.1583762533266; Mon, 09 Mar 2020 07:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583762533; cv=none; d=google.com; s=arc-20160816; b=fpQm6J7jvkYJbVaEKjeNCsrNUTM8GJiREsOEem1bagDT4TXs4dnniXa5h1vNcaxptz tzlYJ6rysZcFcqohUSh0n1l7Ja1xoJtp8+P1YvZttSHvG5Mz9lFl1iqHC5GoKTpA3nWV LWPaqXHHgy2AWURSWzbCi5vpgFJedFroOo914fHVA8MXHfIK6VqOXv6qMvNJ2+4yhVbr mUDwYinGypwtL/MNf5s9T62y/M79KIaIAea8XCwGuSX0edsqH50bzbVfnnlra1JhxM3l aH4FIZTaD/vfZujPaQiGQD6S8pdBuUvNX+we30vDHlRFpdhg9/c6M9qxqhJEfx0MUvb+ RWyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=qNKh0fdBMDq9px7If3jTtquCU4PmuL5OeIUw4lVkYl4=; b=0wwRFP1Dz/VnWTRNO+QZOaYzuawaB8TXncL7FxtoczOo+UZZ7VeowcNUl8QPTB4kHN JxPbi+Nj3hvVzbCe1Ami2L9PEkGVNYjRVD1Lmf2y+T3Qf9E1OIGyZwwETQPgoipKu3NW ONwrfzIPwMOMcdKRzxdH1588PGLStCOgjOhtgIfACyV28tbOwO1okj/Bwr/P6rP0MuSn 20lUDTjsJmPKHpEhsz5wu8rV8utQjFjlkIqd2zpG4E01rE2JocLNCSJytiCyuYtGHGRn eHzfq78e07wWQjC8qgLE4FlDLNqFUgptq3wENMMXZzIHOLUPBUAD5qhaI/TyDCZXYPrv /28A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UbaCId7H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si2333422otc.161.2020.03.09.07.01.46; Mon, 09 Mar 2020 07:02:13 -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=@redhat.com header.s=mimecast20190719 header.b=UbaCId7H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726859AbgCIOBF (ORCPT + 99 others); Mon, 9 Mar 2020 10:01:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:35304 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726759AbgCIOBF (ORCPT ); Mon, 9 Mar 2020 10:01:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583762464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qNKh0fdBMDq9px7If3jTtquCU4PmuL5OeIUw4lVkYl4=; b=UbaCId7Ht+GeTMfxHJCXU3QjxGgHYN49nk9qJwMkenh98ChwyJ82cfWvPx2W1dbbpieB2B JPts9pBmvz1rCzR5KiML8eIW+0b+RtzlAY2mavY+6WGF1HryaH8+bnW6ahcQY4JB8lCsYW T3pzcRaThzTEqGlhgLynmOqVnDrCLYE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-487-ql6zw2YSMKWuXue31dqvEw-1; Mon, 09 Mar 2020 10:01:02 -0400 X-MC-Unique: ql6zw2YSMKWuXue31dqvEw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C977CDB61; Mon, 9 Mar 2020 14:01:00 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-182.rdu2.redhat.com [10.10.120.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF79F60C05; Mon, 9 Mar 2020 14:00:57 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 01/14] VFS: Add additional RESOLVE_* flags [ver #18] From: David Howells To: torvalds@linux-foundation.org, viro@zeniv.linux.org.uk Cc: Stefan Metzmacher , Aleksa Sarai , dhowells@redhat.com, raven@themaw.net, mszeredi@redhat.com, christian@brauner.io, jannh@google.com, darrick.wong@oracle.com, kzak@redhat.com, jlayton@redhat.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 09 Mar 2020 14:00:57 +0000 Message-ID: <158376245699.344135.7522994074747336376.stgit@warthog.procyon.org.uk> In-Reply-To: <158376244589.344135.12925590041630631412.stgit@warthog.procyon.org.uk> References: <158376244589.344135.12925590041630631412.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.21 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add additional RESOLVE_* flags to correspond to AT_* flags that aren't currently implemented: RESOLVE_NO_TRAILING_SYMLINKS for AT_SYMLINK_NOFOLLOW RESOLVE_NO_TRAILING_AUTOMOUNTS for AT_NO_AUTOMOUNT RESOLVE_EMPTY_PATH for AT_EMPTY_PATH This is necessary for fsinfo() to use RESOLVE_* flags instead of AT_* flags if the latter are to be considered deprecated for new system calls. Also make openat2() handle RESOLVE_NO_TRAILING_SYMLINKS. Automounting is currently forced by doing an open(), so adding support to openat2() for RESOLVE_NO_TRAILING_AUTOMOUNTS is not trivial. Reported-by: Stefan Metzmacher Signed-off-by: David Howells cc: Aleksa Sarai --- fs/open.c | 8 +++++--- include/linux/fcntl.h | 3 ++- include/uapi/linux/openat2.h | 8 +++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/fs/open.c b/fs/open.c index 0788b3715731..7c38a7605c21 100644 --- a/fs/open.c +++ b/fs/open.c @@ -977,7 +977,7 @@ inline struct open_how build_open_how(int flags, umode_t mode) inline int build_open_flags(const struct open_how *how, struct open_flags *op) { int flags = how->flags; - int lookup_flags = 0; + int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; int acc_mode = ACC_MODE(flags); /* Must never be set by userspace */ @@ -1055,8 +1055,8 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) if (flags & O_DIRECTORY) lookup_flags |= LOOKUP_DIRECTORY; - if (!(flags & O_NOFOLLOW)) - lookup_flags |= LOOKUP_FOLLOW; + if (flags & O_NOFOLLOW) + lookup_flags &= ~LOOKUP_FOLLOW; if (how->resolve & RESOLVE_NO_XDEV) lookup_flags |= LOOKUP_NO_XDEV; @@ -1068,6 +1068,8 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) lookup_flags |= LOOKUP_BENEATH; if (how->resolve & RESOLVE_IN_ROOT) lookup_flags |= LOOKUP_IN_ROOT; + if (how->resolve & RESOLVE_NO_TRAILING_SYMLINKS) + lookup_flags &= ~LOOKUP_FOLLOW; op->lookup_flags = lookup_flags; return 0; diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h index 7bcdcf4f6ab2..eacf17a8ca34 100644 --- a/include/linux/fcntl.h +++ b/include/linux/fcntl.h @@ -19,7 +19,8 @@ /* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ (RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \ - RESOLVE_BENEATH | RESOLVE_IN_ROOT) + RESOLVE_BENEATH | RESOLVE_IN_ROOT | RESOLVE_NO_TRAILING_SYMLINKS | \ + RESOLVE_NO_TRAILING_AUTOMOUNTS | RESOLVE_EMPTY_PATH) /* List of all open_how "versions". */ #define OPEN_HOW_SIZE_VER0 24 /* sizeof first published struct */ diff --git a/include/uapi/linux/openat2.h b/include/uapi/linux/openat2.h index 58b1eb711360..2647a108f116 100644 --- a/include/uapi/linux/openat2.h +++ b/include/uapi/linux/openat2.h @@ -22,7 +22,10 @@ struct open_how { __u64 resolve; }; -/* how->resolve flags for openat2(2). */ +/* + * Path resolution paths to replace AT_* paths in all new syscalls that would + * use them. + */ #define RESOLVE_NO_XDEV 0x01 /* Block mount-point crossings (includes bind-mounts). */ #define RESOLVE_NO_MAGICLINKS 0x02 /* Block traversal through procfs-style @@ -35,5 +38,8 @@ struct open_how { #define RESOLVE_IN_ROOT 0x10 /* Make all jumps to "/" and ".." be scoped inside the dirfd (similar to chroot(2)). */ +#define RESOLVE_NO_TRAILING_SYMLINKS 0x20 /* Don't follow trailing symlinks in the path */ +#define RESOLVE_NO_TRAILING_AUTOMOUNTS 0x40 /* Don't follow trailing automounts in the path */ +#define RESOLVE_EMPTY_PATH 0x80 /* Permit a path of "" to indicate the dfd exactly */ #endif /* _UAPI_LINUX_OPENAT2_H */