Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 2 | /* |
| 3 | * security/tomoyo/realpath.c |
| 4 | * |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 5 | * Copyright (C) 2005-2011 NTT DATA CORPORATION |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 8 | #include "common.h" |
Al Viro | d10577a | 2011-12-07 13:06:11 -0500 | [diff] [blame] | 9 | #include <linux/magic.h> |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 10 | |
| 11 | /** |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 12 | * tomoyo_encode2 - Encode binary string to ascii string. |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 13 | * |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 14 | * @str: String in binary format. |
| 15 | * @str_len: Size of @str in byte. |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 16 | * |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 17 | * Returns pointer to @str in ascii format on success, NULL otherwise. |
| 18 | * |
| 19 | * This function uses kzalloc(), so caller must kfree() if this function |
| 20 | * didn't return NULL. |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 21 | */ |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 22 | char *tomoyo_encode2(const char *str, int str_len) |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 23 | { |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 24 | int i; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 25 | int len = 0; |
| 26 | const char *p = str; |
| 27 | char *cp; |
| 28 | char *cp0; |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 29 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 30 | if (!p) |
| 31 | return NULL; |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 32 | for (i = 0; i < str_len; i++) { |
| 33 | const unsigned char c = p[i]; |
| 34 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 35 | if (c == '\\') |
| 36 | len += 2; |
| 37 | else if (c > ' ' && c < 127) |
| 38 | len++; |
| 39 | else |
| 40 | len += 4; |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 41 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 42 | len++; |
| 43 | /* Reserve space for appending "/". */ |
| 44 | cp = kzalloc(len + 10, GFP_NOFS); |
| 45 | if (!cp) |
| 46 | return NULL; |
| 47 | cp0 = cp; |
| 48 | p = str; |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 49 | for (i = 0; i < str_len; i++) { |
| 50 | const unsigned char c = p[i]; |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 51 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 52 | if (c == '\\') { |
| 53 | *cp++ = '\\'; |
| 54 | *cp++ = '\\'; |
| 55 | } else if (c > ' ' && c < 127) { |
| 56 | *cp++ = c; |
| 57 | } else { |
| 58 | *cp++ = '\\'; |
| 59 | *cp++ = (c >> 6) + '0'; |
| 60 | *cp++ = ((c >> 3) & 7) + '0'; |
| 61 | *cp++ = (c & 7) + '0'; |
Eric W. Biederman | a4054b6 | 2009-11-20 09:12:22 -0800 | [diff] [blame] | 62 | } |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 63 | } |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 64 | return cp0; |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 68 | * tomoyo_encode - Encode binary string to ascii string. |
| 69 | * |
| 70 | * @str: String in binary format. |
| 71 | * |
| 72 | * Returns pointer to @str in ascii format on success, NULL otherwise. |
| 73 | * |
| 74 | * This function uses kzalloc(), so caller must kfree() if this function |
| 75 | * didn't return NULL. |
| 76 | */ |
| 77 | char *tomoyo_encode(const char *str) |
| 78 | { |
| 79 | return str ? tomoyo_encode2(str, strlen(str)) : NULL; |
| 80 | } |
| 81 | |
| 82 | /** |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 83 | * tomoyo_get_absolute_path - Get the path of a dentry but ignores chroot'ed root. |
| 84 | * |
| 85 | * @path: Pointer to "struct path". |
| 86 | * @buffer: Pointer to buffer to return value in. |
| 87 | * @buflen: Sizeof @buffer. |
| 88 | * |
| 89 | * Returns the buffer on success, an error code otherwise. |
| 90 | * |
| 91 | * If dentry is a directory, trailing '/' is appended. |
| 92 | */ |
Al Viro | 2247386 | 2015-03-08 19:24:30 -0400 | [diff] [blame] | 93 | static char *tomoyo_get_absolute_path(const struct path *path, char * const buffer, |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 94 | const int buflen) |
| 95 | { |
| 96 | char *pos = ERR_PTR(-ENOMEM); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 97 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 98 | if (buflen >= 256) { |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 99 | /* go to whatever namespace root we are under */ |
Al Viro | 02125a8 | 2011-12-05 08:43:34 -0500 | [diff] [blame] | 100 | pos = d_absolute_path(path, buffer, buflen - 1); |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 101 | if (!IS_ERR(pos) && *pos == '/' && pos[1]) { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 102 | struct inode *inode = d_backing_inode(path->dentry); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 103 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 104 | if (inode && S_ISDIR(inode->i_mode)) { |
| 105 | buffer[buflen - 2] = '/'; |
| 106 | buffer[buflen - 1] = '\0'; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | return pos; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * tomoyo_get_dentry_path - Get the path of a dentry. |
| 115 | * |
| 116 | * @dentry: Pointer to "struct dentry". |
| 117 | * @buffer: Pointer to buffer to return value in. |
| 118 | * @buflen: Sizeof @buffer. |
| 119 | * |
| 120 | * Returns the buffer on success, an error code otherwise. |
| 121 | * |
| 122 | * If dentry is a directory, trailing '/' is appended. |
| 123 | */ |
| 124 | static char *tomoyo_get_dentry_path(struct dentry *dentry, char * const buffer, |
| 125 | const int buflen) |
| 126 | { |
| 127 | char *pos = ERR_PTR(-ENOMEM); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 128 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 129 | if (buflen >= 256) { |
| 130 | pos = dentry_path_raw(dentry, buffer, buflen - 1); |
| 131 | if (!IS_ERR(pos) && *pos == '/' && pos[1]) { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 132 | struct inode *inode = d_backing_inode(dentry); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 133 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 134 | if (inode && S_ISDIR(inode->i_mode)) { |
| 135 | buffer[buflen - 2] = '/'; |
| 136 | buffer[buflen - 1] = '\0'; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | return pos; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * tomoyo_get_local_path - Get the path of a dentry. |
| 145 | * |
| 146 | * @dentry: Pointer to "struct dentry". |
| 147 | * @buffer: Pointer to buffer to return value in. |
| 148 | * @buflen: Sizeof @buffer. |
| 149 | * |
| 150 | * Returns the buffer on success, an error code otherwise. |
| 151 | */ |
| 152 | static char *tomoyo_get_local_path(struct dentry *dentry, char * const buffer, |
| 153 | const int buflen) |
| 154 | { |
| 155 | struct super_block *sb = dentry->d_sb; |
| 156 | char *pos = tomoyo_get_dentry_path(dentry, buffer, buflen); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 157 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 158 | if (IS_ERR(pos)) |
| 159 | return pos; |
| 160 | /* Convert from $PID to self if $PID is current thread. */ |
| 161 | if (sb->s_magic == PROC_SUPER_MAGIC && *pos == '/') { |
| 162 | char *ep; |
| 163 | const pid_t pid = (pid_t) simple_strtoul(pos + 1, &ep, 10); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 164 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 165 | if (*ep == '/' && pid && pid == |
| 166 | task_tgid_nr_ns(current, sb->s_fs_info)) { |
| 167 | pos = ep - 5; |
| 168 | if (pos < buffer) |
| 169 | goto out; |
| 170 | memmove(pos, "/self", 5); |
| 171 | } |
| 172 | goto prepend_filesystem_name; |
| 173 | } |
| 174 | /* Use filesystem name for unnamed devices. */ |
| 175 | if (!MAJOR(sb->s_dev)) |
| 176 | goto prepend_filesystem_name; |
| 177 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 178 | struct inode *inode = d_backing_inode(sb->s_root); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 179 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 180 | /* |
| 181 | * Use filesystem name if filesystem does not support rename() |
| 182 | * operation. |
| 183 | */ |
Miklos Szeredi | 2773bf0 | 2016-09-27 11:03:58 +0200 | [diff] [blame] | 184 | if (!inode->i_op->rename) |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 185 | goto prepend_filesystem_name; |
| 186 | } |
| 187 | /* Prepend device name. */ |
| 188 | { |
| 189 | char name[64]; |
| 190 | int name_len; |
| 191 | const dev_t dev = sb->s_dev; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 192 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 193 | name[sizeof(name) - 1] = '\0'; |
| 194 | snprintf(name, sizeof(name) - 1, "dev(%u,%u):", MAJOR(dev), |
| 195 | MINOR(dev)); |
| 196 | name_len = strlen(name); |
| 197 | pos -= name_len; |
| 198 | if (pos < buffer) |
| 199 | goto out; |
| 200 | memmove(pos, name, name_len); |
| 201 | return pos; |
| 202 | } |
| 203 | /* Prepend filesystem name. */ |
| 204 | prepend_filesystem_name: |
| 205 | { |
| 206 | const char *name = sb->s_type->name; |
| 207 | const int name_len = strlen(name); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 208 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 209 | pos -= name_len + 1; |
| 210 | if (pos < buffer) |
| 211 | goto out; |
| 212 | memmove(pos, name, name_len); |
| 213 | pos[name_len] = ':'; |
| 214 | } |
| 215 | return pos; |
| 216 | out: |
| 217 | return ERR_PTR(-ENOMEM); |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * tomoyo_get_socket_name - Get the name of a socket. |
| 222 | * |
| 223 | * @path: Pointer to "struct path". |
| 224 | * @buffer: Pointer to buffer to return value in. |
| 225 | * @buflen: Sizeof @buffer. |
| 226 | * |
| 227 | * Returns the buffer. |
| 228 | */ |
Al Viro | 2247386 | 2015-03-08 19:24:30 -0400 | [diff] [blame] | 229 | static char *tomoyo_get_socket_name(const struct path *path, char * const buffer, |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 230 | const int buflen) |
| 231 | { |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 232 | struct inode *inode = d_backing_inode(path->dentry); |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 233 | struct socket *sock = inode ? SOCKET_I(inode) : NULL; |
| 234 | struct sock *sk = sock ? sock->sk : NULL; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 235 | |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 236 | if (sk) { |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 237 | snprintf(buffer, buflen, "socket:[family=%u:type=%u:protocol=%u]", |
| 238 | sk->sk_family, sk->sk_type, sk->sk_protocol); |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 239 | } else { |
| 240 | snprintf(buffer, buflen, "socket:[unknown]"); |
| 241 | } |
| 242 | return buffer; |
| 243 | } |
| 244 | |
| 245 | /** |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 246 | * tomoyo_realpath_from_path - Returns realpath(3) of the given pathname but ignores chroot'ed root. |
| 247 | * |
| 248 | * @path: Pointer to "struct path". |
| 249 | * |
| 250 | * Returns the realpath of the given @path on success, NULL otherwise. |
| 251 | * |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 252 | * If dentry is a directory, trailing '/' is appended. |
| 253 | * Characters out of 0x20 < c < 0x7F range are converted to |
| 254 | * \ooo style octal string. |
| 255 | * Character \ is converted to \\ string. |
| 256 | * |
Tetsuo Handa | 8e2d39a | 2010-01-26 20:45:27 +0900 | [diff] [blame] | 257 | * These functions use kzalloc(), so the caller must call kfree() |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 258 | * if these functions didn't return NULL. |
| 259 | */ |
Al Viro | 2247386 | 2015-03-08 19:24:30 -0400 | [diff] [blame] | 260 | char *tomoyo_realpath_from_path(const struct path *path) |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 261 | { |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 262 | char *buf = NULL; |
| 263 | char *name = NULL; |
| 264 | unsigned int buf_len = PAGE_SIZE / 2; |
| 265 | struct dentry *dentry = path->dentry; |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 266 | struct super_block *sb; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 267 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 268 | if (!dentry) |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 269 | return NULL; |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 270 | sb = dentry->d_sb; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 271 | while (1) { |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 272 | char *pos; |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 273 | struct inode *inode; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 274 | |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 275 | buf_len <<= 1; |
| 276 | kfree(buf); |
| 277 | buf = kmalloc(buf_len, GFP_NOFS); |
| 278 | if (!buf) |
| 279 | break; |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 280 | /* To make sure that pos is '\0' terminated. */ |
| 281 | buf[buf_len - 1] = '\0'; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 282 | /* Get better name for socket. */ |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 283 | if (sb->s_magic == SOCKFS_MAGIC) { |
| 284 | pos = tomoyo_get_socket_name(path, buf, buf_len - 1); |
| 285 | goto encode; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 286 | } |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 287 | /* For "pipe:[\$]". */ |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 288 | if (dentry->d_op && dentry->d_op->d_dname) { |
| 289 | pos = dentry->d_op->d_dname(dentry, buf, buf_len - 1); |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 290 | goto encode; |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 291 | } |
David Howells | c6f493d | 2015-03-17 22:26:22 +0000 | [diff] [blame] | 292 | inode = d_backing_inode(sb->s_root); |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 293 | /* |
| 294 | * Get local name for filesystems without rename() operation |
| 295 | * or dentry without vfsmount. |
| 296 | */ |
Tetsuo Handa | 8fe7a26 | 2014-08-20 14:14:04 +0900 | [diff] [blame] | 297 | if (!path->mnt || |
Miklos Szeredi | 2773bf0 | 2016-09-27 11:03:58 +0200 | [diff] [blame] | 298 | (!inode->i_op->rename)) |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 299 | pos = tomoyo_get_local_path(path->dentry, buf, |
| 300 | buf_len - 1); |
| 301 | /* Get absolute name for the rest. */ |
Tetsuo Handa | 1418a3e | 2011-12-08 21:24:06 +0900 | [diff] [blame] | 302 | else { |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 303 | pos = tomoyo_get_absolute_path(path, buf, buf_len - 1); |
Tetsuo Handa | 1418a3e | 2011-12-08 21:24:06 +0900 | [diff] [blame] | 304 | /* |
| 305 | * Fall back to local name if absolute name is not |
| 306 | * available. |
| 307 | */ |
| 308 | if (pos == ERR_PTR(-EINVAL)) |
| 309 | pos = tomoyo_get_local_path(path->dentry, buf, |
| 310 | buf_len - 1); |
| 311 | } |
Tetsuo Handa | 5625f2e | 2011-06-26 23:20:23 +0900 | [diff] [blame] | 312 | encode: |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 313 | if (IS_ERR(pos)) |
| 314 | continue; |
| 315 | name = tomoyo_encode(pos); |
| 316 | break; |
| 317 | } |
Tetsuo Handa | 8e2d39a | 2010-01-26 20:45:27 +0900 | [diff] [blame] | 318 | kfree(buf); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 319 | if (!name) |
| 320 | tomoyo_warn_oom(__func__); |
Tetsuo Handa | c8c57e8 | 2010-06-03 20:36:43 +0900 | [diff] [blame] | 321 | return name; |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 325 | * tomoyo_realpath_nofollow - Get realpath of a pathname. |
| 326 | * |
| 327 | * @pathname: The pathname to solve. |
| 328 | * |
| 329 | * Returns the realpath of @pathname on success, NULL otherwise. |
| 330 | */ |
| 331 | char *tomoyo_realpath_nofollow(const char *pathname) |
| 332 | { |
Al Viro | e24977d | 2009-04-02 21:17:03 -0400 | [diff] [blame] | 333 | struct path path; |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 334 | |
Al Viro | e24977d | 2009-04-02 21:17:03 -0400 | [diff] [blame] | 335 | if (pathname && kern_path(pathname, 0, &path) == 0) { |
| 336 | char *buf = tomoyo_realpath_from_path(&path); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 337 | |
Al Viro | e24977d | 2009-04-02 21:17:03 -0400 | [diff] [blame] | 338 | path_put(&path); |
Kentaro Takeda | c73bd6d | 2009-02-05 17:18:12 +0900 | [diff] [blame] | 339 | return buf; |
| 340 | } |
| 341 | return NULL; |
| 342 | } |