From: demiobenour@gmail.com
To: Alexander Viro <viro@zeniv.linux.org.uk>,
David Howells <dhowells@redhat.com>,
"Demi M. Obenour" <demiobenour@gmail.com>,
linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and
infrastructure)), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 1/4] Add path resolution flag LOOKUP_NEVER_FOLLOW
Date: Tue, 12 Feb 2019 09:54:44 -0500 [thread overview]
Message-ID: <20190212145450.2200-1-demiobenour@gmail.com> (raw)
From: "Demi M. Obenour" <demiobenour@gmail.com>
This adds the flag LOOKUP_NEVER_FOLLOW to path resolution, which tells
the code in fs/namei.c to never follow symlinks. This flag overrides
LOOKUP_FOLLOW, since this makes internal APIs simpler: code can set the
flag without needing to also clear LOOKUP_FOLLOW, which is often set by
default.
This is a prerequisite to adding O_PATHSTATIC, but is also useful for
kernel-internal use.
---
fs/namei.c | 4 +++-
include/linux/namei.h | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/namei.c b/fs/namei.c
index 914178cdbe94..54fbd2c7ba82 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1720,7 +1720,9 @@ static int pick_link(struct nameidata *nd, struct path *link,
{
int error;
struct saved *last;
- if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) {
+ const int max_symlinks = (nd->flags & LOOKUP_NEVER_FOLLOW) ?
+ 0 : MAXSYMLINKS;
+ if (unlikely(nd->total_link_count++ >= max_symlinks)) {
path_to_nameidata(link, nd);
return -ELOOP;
}
diff --git a/include/linux/namei.h b/include/linux/namei.h
index a78606e8e3df..f065502a653d 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -24,10 +24,12 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
* - internal "there are more path components" flag
* - dentry cache is untrusted; force a real lookup
* - suppress terminal automount
+ * - never follow symbolic links, even internally
*/
#define LOOKUP_FOLLOW 0x0001
#define LOOKUP_DIRECTORY 0x0002
#define LOOKUP_AUTOMOUNT 0x0004
+#define LOOKUP_NEVER_FOLLOW 0x0008
#define LOOKUP_PARENT 0x0010
#define LOOKUP_REVAL 0x0020
--
2.20.1
next reply other threads:[~2019-02-12 14:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-12 14:54 demiobenour [this message]
2019-02-12 14:54 ` [PATCH 2/4] Expose O_PATHSTATIC to userspace demiobenour
2019-02-12 20:18 ` Andreas Dilger
2019-02-12 22:41 ` Demi M. Obenour
2019-02-12 14:54 ` [PATCH 3/4] Add AT_PATHSTATIC to linkat() demiobenour
2019-02-12 14:54 ` [PATCH 4/4] Return -EINVAL if userspace passes bogus flags to open() demiobenour
2019-02-12 20:38 ` Al Viro
2019-02-12 23:00 ` Demi M. Obenour
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190212145450.2200-1-demiobenour@gmail.com \
--to=demiobenour@gmail.com \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).