Skip to content

Commit 1bc8207

Browse files
cypharAl Viro
authored andcommitted
namei: allow nd_jump_link() to produce errors
In preparation for LOOKUP_NO_MAGICLINKS, it's necessary to add the ability for nd_jump_link() to return an error which the corresponding get_link() caller must propogate back up to the VFS. Suggested-by: Al Viro <[email protected]> Signed-off-by: Aleksa Sarai <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent ce623f8 commit 1bc8207

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

fs/namei.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,15 @@ static int nd_jump_root(struct nameidata *nd)
859859
* Helper to directly jump to a known parsed path from ->get_link,
860860
* caller must have taken a reference to path beforehand.
861861
*/
862-
void nd_jump_link(struct path *path)
862+
int nd_jump_link(struct path *path)
863863
{
864864
struct nameidata *nd = current->nameidata;
865865
path_put(&nd->path);
866866

867867
nd->path = *path;
868868
nd->inode = nd->path.dentry->d_inode;
869869
nd->flags |= LOOKUP_JUMPED;
870+
return 0;
870871
}
871872

872873
static inline void put_link(struct nameidata *nd)

fs/proc/base.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,7 @@ static const char *proc_pid_get_link(struct dentry *dentry,
16261626
if (error)
16271627
goto out;
16281628

1629-
nd_jump_link(&path);
1630-
return NULL;
1629+
error = nd_jump_link(&path);
16311630
out:
16321631
return ERR_PTR(error);
16331632
}

fs/proc/namespaces.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ static const char *proc_ns_get_link(struct dentry *dentry,
5151
if (!task)
5252
return ERR_PTR(-EACCES);
5353

54-
if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) {
55-
error = ns_get_path(&ns_path, task, ns_ops);
56-
if (!error)
57-
nd_jump_link(&ns_path);
58-
}
54+
if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS))
55+
goto out;
56+
57+
error = ns_get_path(&ns_path, task, ns_ops);
58+
if (error)
59+
goto out;
60+
61+
error = nd_jump_link(&ns_path);
62+
out:
5963
put_task_struct(task);
6064
return ERR_PTR(error);
6165
}

include/linux/namei.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extern int follow_up(struct path *);
6969
extern struct dentry *lock_rename(struct dentry *, struct dentry *);
7070
extern void unlock_rename(struct dentry *, struct dentry *);
7171

72-
extern void nd_jump_link(struct path *path);
72+
extern int __must_check nd_jump_link(struct path *path);
7373

7474
static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
7575
{

security/apparmor/apparmorfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,16 +2573,18 @@ static const char *policy_get_link(struct dentry *dentry,
25732573
{
25742574
struct aa_ns *ns;
25752575
struct path path;
2576+
int error;
25762577

25772578
if (!dentry)
25782579
return ERR_PTR(-ECHILD);
2580+
25792581
ns = aa_get_current_ns();
25802582
path.mnt = mntget(aafs_mnt);
25812583
path.dentry = dget(ns_dir(ns));
2582-
nd_jump_link(&path);
2584+
error = nd_jump_link(&path);
25832585
aa_put_ns(ns);
25842586

2585-
return NULL;
2587+
return ERR_PTR(error);
25862588
}
25872589

25882590
static int policy_readlink(struct dentry *dentry, char __user *buffer,

0 commit comments

Comments
 (0)