summaryrefslogtreecommitdiffstats
path: root/fs/d_path.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2021-05-16 20:24:00 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2021-05-18 20:15:58 -0400
commite4b275531887fef7f7d8a7284bfc32f0fbbd4208 (patch)
treeffa3d81f820e1f226c0738db7ecfafc7563aad52 /fs/d_path.c
parentcf4febc1adc8e5cd11ca3386e1e3ea356e0792f0 (diff)
downloadlinux-stable-e4b275531887fef7f7d8a7284bfc32f0fbbd4208.tar.gz
linux-stable-e4b275531887fef7f7d8a7284bfc32f0fbbd4208.tar.bz2
linux-stable-e4b275531887fef7f7d8a7284bfc32f0fbbd4208.zip
getcwd(2): clean up error handling
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/d_path.c')
-rw-r--r--fs/d_path.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/fs/d_path.c b/fs/d_path.c
index 8a9cd44f6689..23a53f7b5c71 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -390,9 +390,11 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
rcu_read_lock();
get_fs_root_and_pwd_rcu(current->fs, &root, &pwd);
- error = -ENOENT;
- if (!d_unlinked(pwd.dentry)) {
- unsigned long len;
+ if (unlikely(d_unlinked(pwd.dentry))) {
+ rcu_read_unlock();
+ error = -ENOENT;
+ } else {
+ unsigned len;
DECLARE_BUFFER(b, page, PATH_MAX);
prepend(&b, "", 1);
@@ -400,23 +402,16 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size)
prepend(&b, "(unreachable)", 13);
rcu_read_unlock();
- if (b.len < 0) {
- error = -ENAMETOOLONG;
- goto out;
- }
-
- error = -ERANGE;
len = PATH_MAX - b.len;
- if (len <= size) {
+ if (unlikely(len > PATH_MAX))
+ error = -ENAMETOOLONG;
+ else if (unlikely(len > size))
+ error = -ERANGE;
+ else if (copy_to_user(buf, b.buf, len))
+ error = -EFAULT;
+ else
error = len;
- if (copy_to_user(buf, b.buf, len))
- error = -EFAULT;
- }
- } else {
- rcu_read_unlock();
}
-
-out:
__putname(page);
return error;
}