diff options
Diffstat (limited to 'security/tomoyo/realpath.c')
-rw-r--r-- | security/tomoyo/realpath.c | 45 |
1 files changed, 4 insertions, 41 deletions
diff --git a/security/tomoyo/realpath.c b/security/tomoyo/realpath.c index 54226d5be493..92460c7ded67 100644 --- a/security/tomoyo/realpath.c +++ b/security/tomoyo/realpath.c | |||
@@ -150,12 +150,12 @@ int tomoyo_realpath_from_path2(struct path *path, char *newname, | |||
150 | * | 150 | * |
151 | * Returns the realpath of the given @path on success, NULL otherwise. | 151 | * Returns the realpath of the given @path on success, NULL otherwise. |
152 | * | 152 | * |
153 | * These functions use tomoyo_alloc(), so the caller must call tomoyo_free() | 153 | * These functions use kzalloc(), so the caller must call kfree() |
154 | * if these functions didn't return NULL. | 154 | * if these functions didn't return NULL. |
155 | */ | 155 | */ |
156 | char *tomoyo_realpath_from_path(struct path *path) | 156 | char *tomoyo_realpath_from_path(struct path *path) |
157 | { | 157 | { |
158 | char *buf = tomoyo_alloc(sizeof(struct tomoyo_page_buffer)); | 158 | char *buf = kzalloc(sizeof(struct tomoyo_page_buffer), GFP_KERNEL); |
159 | 159 | ||
160 | BUILD_BUG_ON(sizeof(struct tomoyo_page_buffer) | 160 | BUILD_BUG_ON(sizeof(struct tomoyo_page_buffer) |
161 | <= TOMOYO_MAX_PATHNAME_LEN - 1); | 161 | <= TOMOYO_MAX_PATHNAME_LEN - 1); |
@@ -164,7 +164,7 @@ char *tomoyo_realpath_from_path(struct path *path) | |||
164 | if (tomoyo_realpath_from_path2(path, buf, | 164 | if (tomoyo_realpath_from_path2(path, buf, |
165 | TOMOYO_MAX_PATHNAME_LEN - 1) == 0) | 165 | TOMOYO_MAX_PATHNAME_LEN - 1) == 0) |
166 | return buf; | 166 | return buf; |
167 | tomoyo_free(buf); | 167 | kfree(buf); |
168 | return NULL; | 168 | return NULL; |
169 | } | 169 | } |
170 | 170 | ||
@@ -346,39 +346,6 @@ void __init tomoyo_realpath_init(void) | |||
346 | panic("Can't register tomoyo_kernel_domain"); | 346 | panic("Can't register tomoyo_kernel_domain"); |
347 | } | 347 | } |
348 | 348 | ||
349 | /* Memory allocated for temporary purpose. */ | ||
350 | static atomic_t tomoyo_dynamic_memory_size; | ||
351 | |||
352 | /** | ||
353 | * tomoyo_alloc - Allocate memory for temporary purpose. | ||
354 | * | ||
355 | * @size: Size in bytes. | ||
356 | * | ||
357 | * Returns pointer to allocated memory on success, NULL otherwise. | ||
358 | */ | ||
359 | void *tomoyo_alloc(const size_t size) | ||
360 | { | ||
361 | void *p = kzalloc(size, GFP_KERNEL); | ||
362 | if (p) | ||
363 | atomic_add(ksize(p), &tomoyo_dynamic_memory_size); | ||
364 | return p; | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * tomoyo_free - Release memory allocated by tomoyo_alloc(). | ||
369 | * | ||
370 | * @p: Pointer returned by tomoyo_alloc(). May be NULL. | ||
371 | * | ||
372 | * Returns nothing. | ||
373 | */ | ||
374 | void tomoyo_free(const void *p) | ||
375 | { | ||
376 | if (p) { | ||
377 | atomic_sub(ksize(p), &tomoyo_dynamic_memory_size); | ||
378 | kfree(p); | ||
379 | } | ||
380 | } | ||
381 | |||
382 | /** | 349 | /** |
383 | * tomoyo_read_memory_counter - Check for memory usage in bytes. | 350 | * tomoyo_read_memory_counter - Check for memory usage in bytes. |
384 | * | 351 | * |
@@ -393,8 +360,6 @@ int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head) | |||
393 | = tomoyo_allocated_memory_for_savename; | 360 | = tomoyo_allocated_memory_for_savename; |
394 | const unsigned int private | 361 | const unsigned int private |
395 | = tomoyo_allocated_memory_for_elements; | 362 | = tomoyo_allocated_memory_for_elements; |
396 | const unsigned int dynamic | ||
397 | = atomic_read(&tomoyo_dynamic_memory_size); | ||
398 | char buffer[64]; | 363 | char buffer[64]; |
399 | 364 | ||
400 | memset(buffer, 0, sizeof(buffer)); | 365 | memset(buffer, 0, sizeof(buffer)); |
@@ -412,9 +377,7 @@ int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head) | |||
412 | else | 377 | else |
413 | buffer[0] = '\0'; | 378 | buffer[0] = '\0'; |
414 | tomoyo_io_printf(head, "Private: %10u%s\n", private, buffer); | 379 | tomoyo_io_printf(head, "Private: %10u%s\n", private, buffer); |
415 | tomoyo_io_printf(head, "Dynamic: %10u\n", dynamic); | 380 | tomoyo_io_printf(head, "Total: %10u\n", shared + private); |
416 | tomoyo_io_printf(head, "Total: %10u\n", | ||
417 | shared + private + dynamic); | ||
418 | head->read_eof = true; | 381 | head->read_eof = true; |
419 | } | 382 | } |
420 | return 0; | 383 | return 0; |