diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2010-08-10 05:41:41 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-08-11 00:29:47 -0400 |
commit | 8df9d1a4142311c084ffeeacb67cd34d190eff74 (patch) | |
tree | 512e018114ea506659fac73d838bfca0fb97a5a4 | |
parent | ffd1f4ed5bddccf2277e3d8525bcedf1983319f8 (diff) |
vfs: show unreachable paths in getcwd and proc
Prepend "(unreachable)" to path strings if the path is not reachable
from the current root.
Two places updated are
- the return string from getcwd()
- and symlinks under /proc/$PID.
Other uses of d_path() are left unchanged (we know that some old
software crashes if /proc/mounts is changed).
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/dcache.c | 54 | ||||
-rw-r--r-- | fs/proc/base.c | 2 | ||||
-rw-r--r-- | include/linux/dcache.h | 1 | ||||
-rw-r--r-- | include/linux/path.h | 5 |
4 files changed, 57 insertions, 5 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index 7fccb00f498..166d35d5686 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 4cf5abf77dd..a1c43e7c8a7 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; |
diff --git a/include/linux/dcache.h b/include/linux/dcache.h index d23be0386e2..6a4aea30aa0 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h | |||
@@ -315,6 +315,7 @@ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...); | |||
315 | 315 | ||
316 | extern char *__d_path(const struct path *path, struct path *root, char *, int); | 316 | extern char *__d_path(const struct path *path, struct path *root, char *, int); |
317 | extern char *d_path(const struct path *, char *, int); | 317 | extern char *d_path(const struct path *, char *, int); |
318 | extern char *d_path_with_unreachable(const struct path *, char *, int); | ||
318 | extern char *__dentry_path(struct dentry *, char *, int); | 319 | extern char *__dentry_path(struct dentry *, char *, int); |
319 | extern char *dentry_path(struct dentry *, char *, int); | 320 | extern char *dentry_path(struct dentry *, char *, int); |
320 | 321 | ||
diff --git a/include/linux/path.h b/include/linux/path.h index 915e0c382a5..edc98dec626 100644 --- a/include/linux/path.h +++ b/include/linux/path.h | |||
@@ -12,4 +12,9 @@ struct path { | |||
12 | extern void path_get(struct path *); | 12 | extern void path_get(struct path *); |
13 | extern void path_put(struct path *); | 13 | extern void path_put(struct path *); |
14 | 14 | ||
15 | static inline int path_equal(const struct path *path1, const struct path *path2) | ||
16 | { | ||
17 | return path1->mnt == path2->mnt && path1->dentry == path2->dentry; | ||
18 | } | ||
19 | |||
15 | #endif /* _LINUX_PATH_H */ | 20 | #endif /* _LINUX_PATH_H */ |