@@ -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);
@@ -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)
{
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(+)