namei: trim the arguments of get_link()
same story as the previous commit Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
b9ff44293c
commit
3b2e7f7539
45
fs/namei.c
45
fs/namei.c
@ -843,27 +843,33 @@ static int may_linkat(struct path *link)
|
|||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __always_inline const char *
|
static __always_inline
|
||||||
get_link(struct path *link, struct nameidata *nd, void **p)
|
const char *get_link(struct nameidata *nd)
|
||||||
{
|
{
|
||||||
struct dentry *dentry = link->dentry;
|
struct saved *last = nd->stack + nd->depth;
|
||||||
|
struct dentry *dentry = nd->link.dentry;
|
||||||
struct inode *inode = dentry->d_inode;
|
struct inode *inode = dentry->d_inode;
|
||||||
int error;
|
int error;
|
||||||
const char *res;
|
const char *res;
|
||||||
|
|
||||||
BUG_ON(nd->flags & LOOKUP_RCU);
|
BUG_ON(nd->flags & LOOKUP_RCU);
|
||||||
|
|
||||||
if (link->mnt == nd->path.mnt)
|
if (nd->link.mnt == nd->path.mnt)
|
||||||
mntget(link->mnt);
|
mntget(nd->link.mnt);
|
||||||
|
|
||||||
res = ERR_PTR(-ELOOP);
|
if (unlikely(current->total_link_count >= 40)) {
|
||||||
if (unlikely(current->total_link_count >= 40))
|
path_put(&nd->path);
|
||||||
goto out;
|
path_put(&nd->link);
|
||||||
|
return ERR_PTR(-ELOOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
last->link = nd->link;
|
||||||
|
last->cookie = NULL;
|
||||||
|
|
||||||
cond_resched();
|
cond_resched();
|
||||||
current->total_link_count++;
|
current->total_link_count++;
|
||||||
|
|
||||||
touch_atime(link);
|
touch_atime(&last->link);
|
||||||
|
|
||||||
error = security_inode_follow_link(dentry);
|
error = security_inode_follow_link(dentry);
|
||||||
res = ERR_PTR(error);
|
res = ERR_PTR(error);
|
||||||
@ -871,14 +877,13 @@ get_link(struct path *link, struct nameidata *nd, void **p)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
nd->last_type = LAST_BIND;
|
nd->last_type = LAST_BIND;
|
||||||
*p = NULL;
|
|
||||||
res = inode->i_link;
|
res = inode->i_link;
|
||||||
if (!res) {
|
if (!res) {
|
||||||
res = inode->i_op->follow_link(dentry, p, nd);
|
res = inode->i_op->follow_link(dentry, &last->cookie, nd);
|
||||||
if (IS_ERR(res)) {
|
if (IS_ERR(res)) {
|
||||||
out:
|
out:
|
||||||
path_put(&nd->path);
|
path_put(&nd->path);
|
||||||
path_put(link);
|
path_put(&last->link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -1717,7 +1722,6 @@ static inline u64 hash_name(const char *name)
|
|||||||
*/
|
*/
|
||||||
static int link_path_walk(const char *name, struct nameidata *nd)
|
static int link_path_walk(const char *name, struct nameidata *nd)
|
||||||
{
|
{
|
||||||
struct saved *last = nd->stack;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
while (*name=='/')
|
while (*name=='/')
|
||||||
@ -1795,16 +1799,13 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
|||||||
|
|
||||||
nd->depth++;
|
nd->depth++;
|
||||||
current->link_count++;
|
current->link_count++;
|
||||||
last++;
|
|
||||||
|
|
||||||
last->link = nd->link;
|
s = get_link(nd);
|
||||||
s = get_link(&last->link, nd, &last->cookie);
|
|
||||||
|
|
||||||
if (unlikely(IS_ERR(s))) {
|
if (unlikely(IS_ERR(s))) {
|
||||||
err = PTR_ERR(s);
|
err = PTR_ERR(s);
|
||||||
current->link_count--;
|
current->link_count--;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
last--;
|
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
err = 0;
|
err = 0;
|
||||||
@ -1813,7 +1814,6 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
|||||||
put_link(nd);
|
put_link(nd);
|
||||||
current->link_count--;
|
current->link_count--;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
last--;
|
|
||||||
} else {
|
} else {
|
||||||
if (*s == '/') {
|
if (*s == '/') {
|
||||||
if (!nd->root.mnt)
|
if (!nd->root.mnt)
|
||||||
@ -1826,7 +1826,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
nd->inode = nd->path.dentry->d_inode;
|
nd->inode = nd->path.dentry->d_inode;
|
||||||
last->name = name;
|
nd->stack[nd->depth].name = name;
|
||||||
if (!*s)
|
if (!*s)
|
||||||
goto OK;
|
goto OK;
|
||||||
name = s;
|
name = s;
|
||||||
@ -1844,17 +1844,15 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
|||||||
put_link(nd);
|
put_link(nd);
|
||||||
current->link_count--;
|
current->link_count--;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
last--;
|
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
OK:
|
OK:
|
||||||
if (unlikely(nd->depth)) {
|
if (unlikely(nd->depth)) {
|
||||||
name = last->name;
|
name = nd->stack[nd->depth].name;
|
||||||
err = walk_component(nd, LOOKUP_FOLLOW);
|
err = walk_component(nd, LOOKUP_FOLLOW);
|
||||||
put_link(nd);
|
put_link(nd);
|
||||||
current->link_count--;
|
current->link_count--;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
last--;
|
|
||||||
goto Walked;
|
goto Walked;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -1979,8 +1977,7 @@ static int trailing_symlink(struct nameidata *nd)
|
|||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
return error;
|
return error;
|
||||||
nd->flags |= LOOKUP_PARENT;
|
nd->flags |= LOOKUP_PARENT;
|
||||||
nd->stack[0].link = nd->link;
|
s = get_link(nd);
|
||||||
s = get_link(&nd->stack[0].link, nd, &nd->stack[0].cookie);
|
|
||||||
if (unlikely(IS_ERR(s)))
|
if (unlikely(IS_ERR(s)))
|
||||||
return PTR_ERR(s);
|
return PTR_ERR(s);
|
||||||
if (unlikely(!s))
|
if (unlikely(!s))
|
||||||
|
Loading…
Reference in New Issue
Block a user