[PATCH 07/17] vfs: add is_following_link() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux