Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tomoyo: Fix null pointer check

Since tomoyo_memory_ok() will check for null pointer returned by
kzalloc() in tomoyo_assign_profile(), tomoyo_assign_namespace(),
tomoyo_get_name() and tomoyo_commit_ok(), then emit OOM warnings
if needed. And this is the expected behavior as informed by
Tetsuo Handa.

Let's add __GFP_NOWARN to kzalloc() in those related functions.
Besides, to achieve this goal, remove the null check for entry
right after kzalloc() in tomoyo_assign_namespace().

Reported-by: Hulk Robot <hulkci@huawei.com>
Suggested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Zheng Zengkai <zhengzengkai@huawei.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>

authored by

Zheng Zengkai and committed by
Tetsuo Handa
1b6b924e e991a40b

+4 -6
+1 -1
security/tomoyo/common.c
··· 498 498 ptr = ns->profile_ptr[profile]; 499 499 if (ptr) 500 500 return ptr; 501 - entry = kzalloc(sizeof(*entry), GFP_NOFS); 501 + entry = kzalloc(sizeof(*entry), GFP_NOFS | __GFP_NOWARN); 502 502 if (mutex_lock_interruptible(&tomoyo_policy_lock)) 503 503 goto out; 504 504 ptr = ns->profile_ptr[profile];
+1 -3
security/tomoyo/domain.c
··· 473 473 return ptr; 474 474 if (len >= TOMOYO_EXEC_TMPSIZE - 10 || !tomoyo_domain_def(domainname)) 475 475 return NULL; 476 - entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS); 477 - if (!entry) 478 - return NULL; 476 + entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS | __GFP_NOWARN); 479 477 if (mutex_lock_interruptible(&tomoyo_policy_lock)) 480 478 goto out; 481 479 ptr = tomoyo_find_namespace(domainname, len);
+2 -2
security/tomoyo/memory.c
··· 73 73 */ 74 74 void *tomoyo_commit_ok(void *data, const unsigned int size) 75 75 { 76 - void *ptr = kzalloc(size, GFP_NOFS); 76 + void *ptr = kzalloc(size, GFP_NOFS | __GFP_NOWARN); 77 77 78 78 if (tomoyo_memory_ok(ptr)) { 79 79 memmove(ptr, data, size); ··· 170 170 atomic_inc(&ptr->head.users); 171 171 goto out; 172 172 } 173 - ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS); 173 + ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS | __GFP_NOWARN); 174 174 if (tomoyo_memory_ok(ptr)) { 175 175 ptr->entry.name = ((char *) ptr) + sizeof(*ptr); 176 176 memmove((char *) ptr->entry.name, name, len);