1 // SPDX-License-Identifier: GPL-2.0 << 2 /* 1 /* 3 * security/tomoyo/realpath.c 2 * security/tomoyo/realpath.c 4 * 3 * 5 * Copyright (C) 2005-2011 NTT DATA CORPORATI !! 4 * Get the canonicalized absolute pathnames. The basis for TOMOYO. >> 5 * >> 6 * Copyright (C) 2005-2009 NTT DATA CORPORATION >> 7 * >> 8 * Version: 2.2.0 2009/04/01 >> 9 * 6 */ 10 */ 7 11 >> 12 #include <linux/types.h> >> 13 #include <linux/mount.h> >> 14 #include <linux/mnt_namespace.h> >> 15 #include <linux/fs_struct.h> 8 #include "common.h" 16 #include "common.h" 9 #include <linux/magic.h> !! 17 #include "realpath.h" 10 #include <linux/proc_fs.h> << 11 18 12 /** 19 /** 13 * tomoyo_encode2 - Encode binary string to as !! 20 * tomoyo_encode: Convert binary string to ascii string. 14 * 21 * 15 * @str: String in binary format. !! 22 * @buffer: Buffer for ASCII string. 16 * @str_len: Size of @str in byte. !! 23 * @buflen: Size of @buffer. >> 24 * @str: Binary string. 17 * 25 * 18 * Returns pointer to @str in ascii format on !! 26 * Returns 0 on success, -ENOMEM otherwise. 19 * << 20 * This function uses kzalloc(), so caller mus << 21 * didn't return NULL. << 22 */ 27 */ 23 char *tomoyo_encode2(const char *str, int str_ !! 28 int tomoyo_encode(char *buffer, int buflen, const char *str) 24 { 29 { 25 int i; !! 30 while (1) { 26 int len = 0; !! 31 const unsigned char c = *(unsigned char *) str++; 27 const char *p = str; << 28 char *cp; << 29 char *cp0; << 30 32 31 if (!p) !! 33 if (tomoyo_is_valid(c)) { 32 return NULL; !! 34 if (--buflen <= 0) 33 for (i = 0; i < str_len; i++) { !! 35 break; 34 const unsigned char c = p[i]; !! 36 *buffer++ = (char) c; >> 37 if (c != '\\') >> 38 continue; >> 39 if (--buflen <= 0) >> 40 break; >> 41 *buffer++ = (char) c; >> 42 continue; >> 43 } >> 44 if (!c) { >> 45 if (--buflen <= 0) >> 46 break; >> 47 *buffer = '\0'; >> 48 return 0; >> 49 } >> 50 buflen -= 4; >> 51 if (buflen <= 0) >> 52 break; >> 53 *buffer++ = '\\'; >> 54 *buffer++ = (c >> 6) + ''; >> 55 *buffer++ = ((c >> 3) & 7) + ''; >> 56 *buffer++ = (c & 7) + ''; >> 57 } >> 58 return -ENOMEM; >> 59 } 35 60 36 if (c == '\\') !! 61 /** 37 len += 2; !! 62 * tomoyo_realpath_from_path2 - Returns realpath(3) of the given dentry but ignores chroot'ed root. 38 else if (c > ' ' && c < 127) !! 63 * 39 len++; !! 64 * @path: Pointer to "struct path". 40 else !! 65 * @newname: Pointer to buffer to return value in. 41 len += 4; !! 66 * @newname_len: Size of @newname. >> 67 * >> 68 * Returns 0 on success, negative value otherwise. >> 69 * >> 70 * If dentry is a directory, trailing '/' is appended. >> 71 * Characters out of 0x20 < c < 0x7F range are converted to >> 72 * \ooo style octal string. >> 73 * Character \ is converted to \\ string. >> 74 */ >> 75 int tomoyo_realpath_from_path2(struct path *path, char *newname, >> 76 int newname_len) >> 77 { >> 78 int error = -ENOMEM; >> 79 struct dentry *dentry = path->dentry; >> 80 char *sp; >> 81 >> 82 if (!dentry || !path->mnt || !newname || newname_len <= 2048) >> 83 return -EINVAL; >> 84 if (dentry->d_op && dentry->d_op->d_dname) { >> 85 /* For "socket:[\$]" and "pipe:[\$]". */ >> 86 static const int offset = 1536; >> 87 sp = dentry->d_op->d_dname(dentry, newname + offset, >> 88 newname_len - offset); >> 89 } else { >> 90 /* Taken from d_namespace_path(). */ >> 91 struct path root; >> 92 struct path ns_root = { }; >> 93 struct path tmp; >> 94 >> 95 read_lock(¤t->fs->lock); >> 96 root = current->fs->root; >> 97 path_get(&root); >> 98 read_unlock(¤t->fs->lock); >> 99 spin_lock(&vfsmount_lock); >> 100 if (root.mnt && root.mnt->mnt_ns) >> 101 ns_root.mnt = mntget(root.mnt->mnt_ns->root); >> 102 if (ns_root.mnt) >> 103 ns_root.dentry = dget(ns_root.mnt->mnt_root); >> 104 spin_unlock(&vfsmount_lock); >> 105 spin_lock(&dcache_lock); >> 106 tmp = ns_root; >> 107 sp = __d_path(path, &tmp, newname, newname_len); >> 108 spin_unlock(&dcache_lock); >> 109 path_put(&root); >> 110 path_put(&ns_root); 42 } 111 } 43 len++; !! 112 if (IS_ERR(sp)) 44 /* Reserve space for appending "/". */ !! 113 error = PTR_ERR(sp); 45 cp = kzalloc(len + 10, GFP_NOFS); !! 114 else 46 if (!cp) !! 115 error = tomoyo_encode(newname, sp - newname, sp); 47 return NULL; !! 116 /* Append trailing '/' if dentry is a directory. */ 48 cp0 = cp; !! 117 if (!error && dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode) 49 p = str; !! 118 && *newname) { 50 for (i = 0; i < str_len; i++) { !! 119 sp = newname + strlen(newname); 51 const unsigned char c = p[i]; !! 120 if (*(sp - 1) != '/') { 52 !! 121 if (sp < newname + newname_len - 4) { 53 if (c == '\\') { !! 122 *sp++ = '/'; 54 *cp++ = '\\'; !! 123 *sp = '\0'; 55 *cp++ = '\\'; !! 124 } else { 56 } else if (c > ' ' && c < 127) !! 125 error = -ENOMEM; 57 *cp++ = c; !! 126 } 58 } else { << 59 *cp++ = '\\'; << 60 *cp++ = (c >> 6) + ''; << 61 *cp++ = ((c >> 3) & 7) << 62 *cp++ = (c & 7) + ''; << 63 } 127 } 64 } 128 } 65 return cp0; !! 129 if (error) >> 130 printk(KERN_WARNING "tomoyo_realpath: Pathname too long.\n"); >> 131 return error; 66 } 132 } 67 133 68 /** 134 /** 69 * tomoyo_encode - Encode binary string to asc !! 135 * tomoyo_realpath_from_path - Returns realpath(3) of the given pathname but ignores chroot'ed root. 70 * 136 * 71 * @str: String in binary format. !! 137 * @path: Pointer to "struct path". 72 * 138 * 73 * Returns pointer to @str in ascii format on !! 139 * Returns the realpath of the given @path on success, NULL otherwise. 74 * 140 * 75 * This function uses kzalloc(), so caller mus !! 141 * These functions use tomoyo_alloc(), so the caller must call tomoyo_free() 76 * didn't return NULL. !! 142 * if these functions didn't return NULL. 77 */ 143 */ 78 char *tomoyo_encode(const char *str) !! 144 char *tomoyo_realpath_from_path(struct path *path) 79 { 145 { 80 return str ? tomoyo_encode2(str, strle !! 146 char *buf = tomoyo_alloc(sizeof(struct tomoyo_page_buffer)); >> 147 >> 148 BUILD_BUG_ON(sizeof(struct tomoyo_page_buffer) >> 149 <= TOMOYO_MAX_PATHNAME_LEN - 1); >> 150 if (!buf) >> 151 return NULL; >> 152 if (tomoyo_realpath_from_path2(path, buf, >> 153 TOMOYO_MAX_PATHNAME_LEN - 1) == 0) >> 154 return buf; >> 155 tomoyo_free(buf); >> 156 return NULL; 81 } 157 } 82 158 83 /** 159 /** 84 * tomoyo_get_absolute_path - Get the path of !! 160 * tomoyo_realpath - Get realpath of a pathname. 85 * 161 * 86 * @path: Pointer to "struct path". !! 162 * @pathname: The pathname to solve. 87 * @buffer: Pointer to buffer to return value << 88 * @buflen: Sizeof @buffer. << 89 * 163 * 90 * Returns the buffer on success, an error cod !! 164 * Returns the realpath of @pathname on success, NULL otherwise. >> 165 */ >> 166 char *tomoyo_realpath(const char *pathname) >> 167 { >> 168 struct path path; >> 169 >> 170 if (pathname && kern_path(pathname, LOOKUP_FOLLOW, &path) == 0) { >> 171 char *buf = tomoyo_realpath_from_path(&path); >> 172 path_put(&path); >> 173 return buf; >> 174 } >> 175 return NULL; >> 176 } >> 177 >> 178 /** >> 179 * tomoyo_realpath_nofollow - Get realpath of a pathname. 91 * 180 * 92 * If dentry is a directory, trailing '/' is a !! 181 * @pathname: The pathname to solve. >> 182 * >> 183 * Returns the realpath of @pathname on success, NULL otherwise. 93 */ 184 */ 94 static char *tomoyo_get_absolute_path(const st !! 185 char *tomoyo_realpath_nofollow(const char *pathname) 95 const in << 96 { 186 { 97 char *pos = ERR_PTR(-ENOMEM); !! 187 struct path path; 98 188 99 if (buflen >= 256) { !! 189 if (pathname && kern_path(pathname, 0, &path) == 0) { 100 /* go to whatever namespace ro !! 190 char *buf = tomoyo_realpath_from_path(&path); 101 pos = d_absolute_path(path, bu !! 191 path_put(&path); 102 if (!IS_ERR(pos) && *pos == '/ !! 192 return buf; 103 struct inode *inode = << 104 << 105 if (inode && S_ISDIR(i << 106 buffer[buflen << 107 buffer[buflen << 108 } << 109 } << 110 } 193 } 111 return pos; !! 194 return NULL; 112 } 195 } 113 196 >> 197 /* Memory allocated for non-string data. */ >> 198 static unsigned int tomoyo_allocated_memory_for_elements; >> 199 /* Quota for holding non-string data. */ >> 200 static unsigned int tomoyo_quota_for_elements; >> 201 114 /** 202 /** 115 * tomoyo_get_dentry_path - Get the path of a !! 203 * tomoyo_alloc_element - Allocate permanent memory for structures. 116 * 204 * 117 * @dentry: Pointer to "struct dentry". !! 205 * @size: Size in bytes. 118 * @buffer: Pointer to buffer to return value << 119 * @buflen: Sizeof @buffer. << 120 * 206 * 121 * Returns the buffer on success, an error cod !! 207 * Returns pointer to allocated memory on success, NULL otherwise. 122 * 208 * 123 * If dentry is a directory, trailing '/' is a !! 209 * Memory has to be zeroed. >> 210 * The RAM is chunked, so NEVER try to kfree() the returned pointer. 124 */ 211 */ 125 static char *tomoyo_get_dentry_path(struct den !! 212 void *tomoyo_alloc_element(const unsigned int size) 126 const int << 127 { 213 { 128 char *pos = ERR_PTR(-ENOMEM); !! 214 static char *buf; 129 !! 215 static DEFINE_MUTEX(lock); 130 if (buflen >= 256) { !! 216 static unsigned int buf_used_len = PATH_MAX; 131 pos = dentry_path_raw(dentry, !! 217 char *ptr = NULL; 132 if (!IS_ERR(pos) && *pos == '/ !! 218 /*Assumes sizeof(void *) >= sizeof(long) is true. */ 133 struct inode *inode = !! 219 const unsigned int word_aligned_size 134 !! 220 = roundup(size, max(sizeof(void *), sizeof(long))); 135 if (inode && S_ISDIR(i !! 221 if (word_aligned_size > PATH_MAX) 136 buffer[buflen !! 222 return NULL; 137 buffer[buflen !! 223 mutex_lock(&lock); 138 } !! 224 if (buf_used_len + word_aligned_size > PATH_MAX) { >> 225 if (!tomoyo_quota_for_elements || >> 226 tomoyo_allocated_memory_for_elements >> 227 + PATH_MAX <= tomoyo_quota_for_elements) >> 228 ptr = kzalloc(PATH_MAX, GFP_KERNEL); >> 229 if (!ptr) { >> 230 printk(KERN_WARNING "ERROR: Out of memory " >> 231 "for tomoyo_alloc_element().\n"); >> 232 if (!tomoyo_policy_loaded) >> 233 panic("MAC Initialization failed.\n"); >> 234 } else { >> 235 buf = ptr; >> 236 tomoyo_allocated_memory_for_elements += PATH_MAX; >> 237 buf_used_len = word_aligned_size; >> 238 ptr = buf; >> 239 } >> 240 } else if (word_aligned_size) { >> 241 int i; >> 242 ptr = buf + buf_used_len; >> 243 buf_used_len += word_aligned_size; >> 244 for (i = 0; i < word_aligned_size; i++) { >> 245 if (!ptr[i]) >> 246 continue; >> 247 printk(KERN_ERR "WARNING: Reserved memory was tainted! " >> 248 "The system might go wrong.\n"); >> 249 ptr[i] = '\0'; 139 } 250 } 140 } 251 } 141 return pos; !! 252 mutex_unlock(&lock); >> 253 return ptr; 142 } 254 } 143 255 >> 256 /* Memory allocated for string data in bytes. */ >> 257 static unsigned int tomoyo_allocated_memory_for_savename; >> 258 /* Quota for holding string data in bytes. */ >> 259 static unsigned int tomoyo_quota_for_savename; >> 260 >> 261 /* >> 262 * TOMOYO uses this hash only when appending a string into the string >> 263 * table. Frequency of appending strings is very low. So we don't need >> 264 * large (e.g. 64k) hash size. 256 will be sufficient. >> 265 */ >> 266 #define TOMOYO_MAX_HASH 256 >> 267 >> 268 /* >> 269 * tomoyo_name_entry is a structure which is used for linking >> 270 * "struct tomoyo_path_info" into tomoyo_name_list . >> 271 * >> 272 * Since tomoyo_name_list manages a list of strings which are shared by >> 273 * multiple processes (whereas "struct tomoyo_path_info" inside >> 274 * "struct tomoyo_path_info_with_data" is not shared), a reference counter will >> 275 * be added to "struct tomoyo_name_entry" rather than "struct tomoyo_path_info" >> 276 * when TOMOYO starts supporting garbage collector. >> 277 */ >> 278 struct tomoyo_name_entry { >> 279 struct list_head list; >> 280 struct tomoyo_path_info entry; >> 281 }; >> 282 >> 283 /* Structure for available memory region. */ >> 284 struct tomoyo_free_memory_block_list { >> 285 struct list_head list; >> 286 char *ptr; /* Pointer to a free area. */ >> 287 int len; /* Length of the area. */ >> 288 }; >> 289 >> 290 /* >> 291 * tomoyo_name_list is used for holding string data used by TOMOYO. >> 292 * Since same string data is likely used for multiple times (e.g. >> 293 * "/lib/libc-2.5.so"), TOMOYO shares string data in the form of >> 294 * "const struct tomoyo_path_info *". >> 295 */ >> 296 static struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; >> 297 144 /** 298 /** 145 * tomoyo_get_local_path - Get the path of a d !! 299 * tomoyo_save_name - Allocate permanent memory for string data. >> 300 * >> 301 * @name: The string to store into the permernent memory. 146 * 302 * 147 * @dentry: Pointer to "struct dentry". !! 303 * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise. 148 * @buffer: Pointer to buffer to return value << 149 * @buflen: Sizeof @buffer. << 150 * 304 * 151 * Returns the buffer on success, an error cod !! 305 * The RAM is shared, so NEVER try to modify or kfree() the returned name. 152 */ 306 */ 153 static char *tomoyo_get_local_path(struct dent !! 307 const struct tomoyo_path_info *tomoyo_save_name(const char *name) 154 const int b << 155 { 308 { 156 struct super_block *sb = dentry->d_sb; !! 309 static LIST_HEAD(fmb_list); 157 char *pos = tomoyo_get_dentry_path(den !! 310 static DEFINE_MUTEX(lock); 158 !! 311 struct tomoyo_name_entry *ptr; 159 if (IS_ERR(pos)) !! 312 unsigned int hash; 160 return pos; !! 313 /* fmb contains available size in bytes. 161 /* Convert from $PID to self if $PID i !! 314 fmb is removed from the fmb_list when fmb->len becomes 0. */ 162 if (sb->s_magic == PROC_SUPER_MAGIC && !! 315 struct tomoyo_free_memory_block_list *fmb; 163 char *ep; !! 316 int len; 164 const pid_t pid = (pid_t) simp !! 317 char *cp; 165 struct pid_namespace *proc_pid << 166 318 167 if (*ep == '/' && pid && pid = !! 319 if (!name) 168 task_tgid_nr_ns(current, p !! 320 return NULL; 169 pos = ep - 5; !! 321 len = strlen(name) + 1; 170 if (pos < buffer) !! 322 if (len > TOMOYO_MAX_PATHNAME_LEN) { 171 goto out; !! 323 printk(KERN_WARNING "ERROR: Name too long " 172 memmove(pos, "/self", !! 324 "for tomoyo_save_name().\n"); 173 } !! 325 return NULL; 174 goto prepend_filesystem_name; << 175 } 326 } 176 /* Use filesystem name for unnamed dev !! 327 hash = full_name_hash((const unsigned char *) name, len - 1); 177 if (!MAJOR(sb->s_dev)) !! 328 mutex_lock(&lock); 178 goto prepend_filesystem_name; !! 329 list_for_each_entry(ptr, &tomoyo_name_list[hash % TOMOYO_MAX_HASH], 179 { !! 330 list) { 180 struct inode *inode = d_backin !! 331 if (hash == ptr->entry.hash && !strcmp(name, ptr->entry.name)) 181 << 182 /* << 183 * Use filesystem name if file << 184 * operation. << 185 */ << 186 if (!inode->i_op->rename) << 187 goto prepend_filesyste << 188 } << 189 /* Prepend device name. */ << 190 { << 191 char name[64]; << 192 int name_len; << 193 const dev_t dev = sb->s_dev; << 194 << 195 name[sizeof(name) - 1] = '\0'; << 196 snprintf(name, sizeof(name) - << 197 MINOR(dev)); << 198 name_len = strlen(name); << 199 pos -= name_len; << 200 if (pos < buffer) << 201 goto out; 332 goto out; 202 memmove(pos, name, name_len); << 203 return pos; << 204 } 333 } 205 /* Prepend filesystem name. */ !! 334 list_for_each_entry(fmb, &fmb_list, list) { 206 prepend_filesystem_name: !! 335 if (len <= fmb->len) 207 { !! 336 goto ready; 208 const char *name = sb->s_type- !! 337 } 209 const int name_len = strlen(na !! 338 if (!tomoyo_quota_for_savename || 210 !! 339 tomoyo_allocated_memory_for_savename + PATH_MAX 211 pos -= name_len + 1; !! 340 <= tomoyo_quota_for_savename) 212 if (pos < buffer) !! 341 cp = kzalloc(PATH_MAX, GFP_KERNEL); 213 goto out; !! 342 else 214 memmove(pos, name, name_len); !! 343 cp = NULL; 215 pos[name_len] = ':'; !! 344 fmb = kzalloc(sizeof(*fmb), GFP_KERNEL); >> 345 if (!cp || !fmb) { >> 346 kfree(cp); >> 347 kfree(fmb); >> 348 printk(KERN_WARNING "ERROR: Out of memory " >> 349 "for tomoyo_save_name().\n"); >> 350 if (!tomoyo_policy_loaded) >> 351 panic("MAC Initialization failed.\n"); >> 352 ptr = NULL; >> 353 goto out; 216 } 354 } 217 return pos; !! 355 tomoyo_allocated_memory_for_savename += PATH_MAX; 218 out: !! 356 list_add(&fmb->list, &fmb_list); 219 return ERR_PTR(-ENOMEM); !! 357 fmb->ptr = cp; >> 358 fmb->len = PATH_MAX; >> 359 ready: >> 360 ptr = tomoyo_alloc_element(sizeof(*ptr)); >> 361 if (!ptr) >> 362 goto out; >> 363 ptr->entry.name = fmb->ptr; >> 364 memmove(fmb->ptr, name, len); >> 365 tomoyo_fill_path_info(&ptr->entry); >> 366 fmb->ptr += len; >> 367 fmb->len -= len; >> 368 list_add_tail(&ptr->list, &tomoyo_name_list[hash % TOMOYO_MAX_HASH]); >> 369 if (fmb->len == 0) { >> 370 list_del(&fmb->list); >> 371 kfree(fmb); >> 372 } >> 373 out: >> 374 mutex_unlock(&lock); >> 375 return ptr ? &ptr->entry : NULL; 220 } 376 } 221 377 222 /** 378 /** 223 * tomoyo_realpath_from_path - Returns realpat !! 379 * tomoyo_realpath_init - Initialize realpath related code. >> 380 */ >> 381 void __init tomoyo_realpath_init(void) >> 382 { >> 383 int i; >> 384 >> 385 BUILD_BUG_ON(TOMOYO_MAX_PATHNAME_LEN > PATH_MAX); >> 386 for (i = 0; i < TOMOYO_MAX_HASH; i++) >> 387 INIT_LIST_HEAD(&tomoyo_name_list[i]); >> 388 INIT_LIST_HEAD(&tomoyo_kernel_domain.acl_info_list); >> 389 tomoyo_kernel_domain.domainname = tomoyo_save_name(TOMOYO_ROOT_NAME); >> 390 list_add_tail(&tomoyo_kernel_domain.list, &tomoyo_domain_list); >> 391 down_read(&tomoyo_domain_list_lock); >> 392 if (tomoyo_find_domain(TOMOYO_ROOT_NAME) != &tomoyo_kernel_domain) >> 393 panic("Can't register tomoyo_kernel_domain"); >> 394 up_read(&tomoyo_domain_list_lock); >> 395 } >> 396 >> 397 /* Memory allocated for temporary purpose. */ >> 398 static atomic_t tomoyo_dynamic_memory_size; >> 399 >> 400 /** >> 401 * tomoyo_alloc - Allocate memory for temporary purpose. 224 * 402 * 225 * @path: Pointer to "struct path". !! 403 * @size: Size in bytes. 226 * 404 * 227 * Returns the realpath of the given @path on !! 405 * Returns pointer to allocated memory on success, NULL otherwise. >> 406 */ >> 407 void *tomoyo_alloc(const size_t size) >> 408 { >> 409 void *p = kzalloc(size, GFP_KERNEL); >> 410 if (p) >> 411 atomic_add(ksize(p), &tomoyo_dynamic_memory_size); >> 412 return p; >> 413 } >> 414 >> 415 /** >> 416 * tomoyo_free - Release memory allocated by tomoyo_alloc(). 228 * 417 * 229 * If dentry is a directory, trailing '/' is a !! 418 * @p: Pointer returned by tomoyo_alloc(). May be NULL. 230 * Characters out of 0x20 < c < 0x7F range are << 231 * \ooo style octal string. << 232 * Character \ is converted to \\ string. << 233 * 419 * 234 * These functions use kzalloc(), so the calle !! 420 * Returns nothing. 235 * if these functions didn't return NULL. << 236 */ 421 */ 237 char *tomoyo_realpath_from_path(const struct p !! 422 void tomoyo_free(const void *p) 238 { 423 { 239 char *buf = NULL; !! 424 if (p) { 240 char *name = NULL; !! 425 atomic_sub(ksize(p), &tomoyo_dynamic_memory_size); 241 unsigned int buf_len = PAGE_SIZE / 2; !! 426 kfree(p); 242 struct dentry *dentry = path->dentry; << 243 struct super_block *sb = dentry->d_sb; << 244 << 245 while (1) { << 246 char *pos; << 247 struct inode *inode; << 248 << 249 buf_len <<= 1; << 250 kfree(buf); << 251 buf = kmalloc(buf_len, GFP_NOF << 252 if (!buf) << 253 break; << 254 /* To make sure that pos is '\ << 255 buf[buf_len - 1] = '\0'; << 256 /* For "pipe:[\$]" and "socket << 257 if (dentry->d_op && dentry->d_ << 258 pos = dentry->d_op->d_ << 259 goto encode; << 260 } << 261 inode = d_backing_inode(sb->s_ << 262 /* << 263 * Get local name for filesyst << 264 */ << 265 if ((!inode->i_op->rename && << 266 !(sb->s_type->fs_flags & << 267 pos = tomoyo_get_local << 268 << 269 /* Get absolute name for the r << 270 else { << 271 pos = tomoyo_get_absol << 272 /* << 273 * Fall back to local << 274 * available. << 275 */ << 276 if (pos == ERR_PTR(-EI << 277 pos = tomoyo_g << 278 << 279 } << 280 encode: << 281 if (IS_ERR(pos)) << 282 continue; << 283 name = tomoyo_encode(pos); << 284 break; << 285 } 427 } 286 kfree(buf); << 287 if (!name) << 288 tomoyo_warn_oom(__func__); << 289 return name; << 290 } 428 } 291 429 292 /** 430 /** 293 * tomoyo_realpath_nofollow - Get realpath of !! 431 * tomoyo_read_memory_counter - Check for memory usage in bytes. 294 * 432 * 295 * @pathname: The pathname to solve. !! 433 * @head: Pointer to "struct tomoyo_io_buffer". 296 * 434 * 297 * Returns the realpath of @pathname on succes !! 435 * Returns memory usage. 298 */ 436 */ 299 char *tomoyo_realpath_nofollow(const char *pat !! 437 int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head) 300 { 438 { 301 struct path path; !! 439 if (!head->read_eof) { >> 440 const unsigned int shared >> 441 = tomoyo_allocated_memory_for_savename; >> 442 const unsigned int private >> 443 = tomoyo_allocated_memory_for_elements; >> 444 const unsigned int dynamic >> 445 = atomic_read(&tomoyo_dynamic_memory_size); >> 446 char buffer[64]; >> 447 >> 448 memset(buffer, 0, sizeof(buffer)); >> 449 if (tomoyo_quota_for_savename) >> 450 snprintf(buffer, sizeof(buffer) - 1, >> 451 " (Quota: %10u)", >> 452 tomoyo_quota_for_savename); >> 453 else >> 454 buffer[0] = '\0'; >> 455 tomoyo_io_printf(head, "Shared: %10u%s\n", shared, buffer); >> 456 if (tomoyo_quota_for_elements) >> 457 snprintf(buffer, sizeof(buffer) - 1, >> 458 " (Quota: %10u)", >> 459 tomoyo_quota_for_elements); >> 460 else >> 461 buffer[0] = '\0'; >> 462 tomoyo_io_printf(head, "Private: %10u%s\n", private, buffer); >> 463 tomoyo_io_printf(head, "Dynamic: %10u\n", dynamic); >> 464 tomoyo_io_printf(head, "Total: %10u\n", >> 465 shared + private + dynamic); >> 466 head->read_eof = true; >> 467 } >> 468 return 0; >> 469 } 302 470 303 if (pathname && kern_path(pathname, 0, !! 471 /** 304 char *buf = tomoyo_realpath_fr !! 472 * tomoyo_write_memory_quota - Set memory quota. >> 473 * >> 474 * @head: Pointer to "struct tomoyo_io_buffer". >> 475 * >> 476 * Returns 0. >> 477 */ >> 478 int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head) >> 479 { >> 480 char *data = head->write_buf; >> 481 unsigned int size; 305 482 306 path_put(&path); !! 483 if (sscanf(data, "Shared: %u", &size) == 1) 307 return buf; !! 484 tomoyo_quota_for_savename = size; 308 } !! 485 else if (sscanf(data, "Private: %u", &size) == 1) 309 return NULL; !! 486 tomoyo_quota_for_elements = size; >> 487 return 0; 310 } 488 } 311 489
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.