linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 07/17] vfs: add is_following_link() helper
Date: Mon, 12 Sep 2016 21:29:09 +0200	[thread overview]
Message-ID: <1473708559-12714-8-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1473708559-12714-1-git-send-email-mszeredi@redhat.com>

The remainging instances of ->readlink that don't use generic_readlink are
/proc/$$/fd/N, /proc/$$/map_files/A and /proc/$$/ns/X.  The reason is that
these have special get_link() implementations is that they "jump" to
locations not indicated by the symlink contents.

Since there are so few of these (the fd and map_files ones are essentially
the same), it doesn't make sense to create a separate i_op method for them.
This patch adds a helper: is_following_link() by which the two different
modes of operation can be differentiated by the special get_link()
implementations.

Also add a WARN_ON_ONCE() in generic_readlink() to prevent misuse.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 fs/namei.c            | 9 +++++++++
 include/linux/namei.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/fs/namei.c b/fs/namei.c
index c06a68b82088..f72c405d1a27 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -880,6 +880,11 @@ void nd_jump_link(struct path *path)
 	nd->flags |= LOOKUP_JUMPED;
 }
 
+bool is_following_link(void)
+{
+	return current->nameidata;
+}
+
 static inline void put_link(struct nameidata *nd)
 {
 	struct saved *last = nd->stack + --nd->depth;
@@ -4670,6 +4675,10 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
 		link = inode->i_op->get_link(dentry, inode, &done);
 		if (IS_ERR(link))
 			return PTR_ERR(link);
+
+		/* "jumping" is unacceptable, warn and return error */
+		if (WARN_ON_ONCE(!link))
+			return -EIO;
 	}
 	res = readlink_copy(buffer, buflen, link);
 	do_delayed_call(&done);
diff --git a/include/linux/namei.h b/include/linux/namei.h
index f29abda31e6d..ec7b8ccfe064 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -90,6 +90,7 @@ extern struct dentry *lock_rename(struct dentry *, struct dentry *);
 extern void unlock_rename(struct dentry *, struct dentry *);
 
 extern void nd_jump_link(struct path *path);
+extern bool is_following_link(void);
 
 static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
 {
-- 
2.5.5

  parent reply	other threads:[~2016-09-12 19:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 19:29 [PATCH 00/17] clean up readlinks Miklos Szeredi
2016-09-12 19:29 ` [PATCH 01/17] bad_inode: add missing i_op initializers Miklos Szeredi
2016-09-12 19:29 ` [PATCH 02/17] ovl: use generic_readlink Miklos Szeredi
2016-09-12 19:29 ` [PATCH 03/17] proc/self: " Miklos Szeredi
2016-09-12 19:29 ` [PATCH 04/17] afs: " Miklos Szeredi
2016-09-12 19:29 ` [PATCH 05/17] bad_inode: " Miklos Szeredi
2016-09-12 19:29 ` [PATCH 06/17] vfs: remove page_readlink() Miklos Szeredi
2016-09-12 19:29 ` Miklos Szeredi [this message]
2016-09-12 19:29 ` [PATCH 08/17] proc: merge proc_pid_readlink() into proc_pid_get_link() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 09/17] proc: merge proc_ns_readlink() into proc_ns_get_link() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 10/17] nsfs: clean up ns_get_name() interface Miklos Szeredi
2016-09-12 19:29 ` [PATCH 11/17] vfs: replace calling i_op->readlink with vfs_readlink() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 12/17] vfs: remove ".readlink = generic_readlink" assignments Miklos Szeredi
2016-09-12 19:29 ` [PATCH 13/17] vfs: remove unused i_op->readlink Miklos Szeredi
2016-09-12 19:29 ` [PATCH 14/17] vfs: remove unused generic_readlink() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 15/17] vfs: add vfs_get_link() helper Miklos Szeredi
2016-09-12 19:29 ` [PATCH 16/17] ovl: use vfs_get_link() Miklos Szeredi
2016-09-12 19:29 ` [PATCH 17/17] ecryptfs: " Miklos Szeredi
2016-09-27  3:10 ` [PATCH 00/17] clean up readlinks Al Viro
2016-09-27  9:38   ` Miklos Szeredi
2016-09-28  2:17     ` Al Viro
2016-09-28 14:47       ` Miklos Szeredi

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=1473708559-12714-8-git-send-email-mszeredi@redhat.com \
    --to=mszeredi@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).