diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/dcache.c | 54 | ||||
-rw-r--r-- | fs/proc/base.c | 2 |
2 files changed, 51 insertions, 5 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index 7fccb00f498d..166d35d56868 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -2019,6 +2019,11 @@ static int path_with_deleted(const struct path *path, struct path *root, | |||
2019 | return prepend_path(path, root, buf, buflen); | 2019 | return prepend_path(path, root, buf, buflen); |
2020 | } | 2020 | } |
2021 | 2021 | ||
2022 | static int prepend_unreachable(char **buffer, int *buflen) | ||
2023 | { | ||
2024 | return prepend(buffer, buflen, "(unreachable)", 13); | ||
2025 | } | ||
2026 | |||
2022 | /** | 2027 | /** |
2023 | * d_path - return the path of a dentry | 2028 | * d_path - return the path of a dentry |
2024 | * @path: path to report | 2029 | * @path: path to report |
@@ -2064,6 +2069,39 @@ char *d_path(const struct path *path, char *buf, int buflen) | |||
2064 | } | 2069 | } |
2065 | EXPORT_SYMBOL(d_path); | 2070 | EXPORT_SYMBOL(d_path); |
2066 | 2071 | ||
2072 | /** | ||
2073 | * d_path_with_unreachable - return the path of a dentry | ||
2074 | * @path: path to report | ||
2075 | * @buf: buffer to return value in | ||
2076 | * @buflen: buffer length | ||
2077 | * | ||
2078 | * The difference from d_path() is that this prepends "(unreachable)" | ||
2079 | * to paths which are unreachable from the current process' root. | ||
2080 | */ | ||
2081 | char *d_path_with_unreachable(const struct path *path, char *buf, int buflen) | ||
2082 | { | ||
2083 | char *res = buf + buflen; | ||
2084 | struct path root; | ||
2085 | struct path tmp; | ||
2086 | int error; | ||
2087 | |||
2088 | if (path->dentry->d_op && path->dentry->d_op->d_dname) | ||
2089 | return path->dentry->d_op->d_dname(path->dentry, buf, buflen); | ||
2090 | |||
2091 | get_fs_root(current->fs, &root); | ||
2092 | spin_lock(&dcache_lock); | ||
2093 | tmp = root; | ||
2094 | error = path_with_deleted(path, &tmp, &res, &buflen); | ||
2095 | if (!error && !path_equal(&tmp, &root)) | ||
2096 | error = prepend_unreachable(&res, &buflen); | ||
2097 | spin_unlock(&dcache_lock); | ||
2098 | path_put(&root); | ||
2099 | if (error) | ||
2100 | res = ERR_PTR(error); | ||
2101 | |||
2102 | return res; | ||
2103 | } | ||
2104 | |||
2067 | /* | 2105 | /* |
2068 | * Helper function for dentry_operations.d_dname() members | 2106 | * Helper function for dentry_operations.d_dname() members |
2069 | */ | 2107 | */ |
@@ -2173,15 +2211,23 @@ SYSCALL_DEFINE2(getcwd, char __user *, buf, unsigned long, size) | |||
2173 | if (!d_unlinked(pwd.dentry)) { | 2211 | if (!d_unlinked(pwd.dentry)) { |
2174 | unsigned long len; | 2212 | unsigned long len; |
2175 | struct path tmp = root; | 2213 | struct path tmp = root; |
2176 | char * cwd; | 2214 | char *cwd = page + PAGE_SIZE; |
2215 | int buflen = PAGE_SIZE; | ||
2177 | 2216 | ||
2178 | cwd = __d_path(&pwd, &tmp, page, PAGE_SIZE); | 2217 | prepend(&cwd, &buflen, "\0", 1); |
2218 | error = prepend_path(&pwd, &tmp, &cwd, &buflen); | ||
2179 | spin_unlock(&dcache_lock); | 2219 | spin_unlock(&dcache_lock); |
2180 | 2220 | ||
2181 | error = PTR_ERR(cwd); | 2221 | if (error) |
2182 | if (IS_ERR(cwd)) | ||
2183 | goto out; | 2222 | goto out; |
2184 | 2223 | ||
2224 | /* Unreachable from current root */ | ||
2225 | if (!path_equal(&tmp, &root)) { | ||
2226 | error = prepend_unreachable(&cwd, &buflen); | ||
2227 | if (error) | ||
2228 | goto out; | ||
2229 | } | ||
2230 | |||
2185 | error = -ERANGE; | 2231 | error = -ERANGE; |
2186 | len = PAGE_SIZE + page - cwd; | 2232 | len = PAGE_SIZE + page - cwd; |
2187 | if (len <= size) { | 2233 | if (len <= size) { |
diff --git a/fs/proc/base.c b/fs/proc/base.c index 4cf5abf77ddf..a1c43e7c8a7b 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -1526,7 +1526,7 @@ static int do_proc_readlink(struct path *path, char __user *buffer, int buflen) | |||
1526 | if (!tmp) | 1526 | if (!tmp) |
1527 | return -ENOMEM; | 1527 | return -ENOMEM; |
1528 | 1528 | ||
1529 | pathname = d_path(path, tmp, PAGE_SIZE); | 1529 | pathname = d_path_with_unreachable(path, tmp, PAGE_SIZE); |
1530 | len = PTR_ERR(pathname); | 1530 | len = PTR_ERR(pathname); |
1531 | if (IS_ERR(pathname)) | 1531 | if (IS_ERR(pathname)) |
1532 | goto out; | 1532 | goto out; |