Skip to contentSkip to conversation

inotify: add error handling for kmem_cache_create

PATCH In review Zhouyang Jia 3 participants 3 messages Jun 12, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inotify: add error handling for kmem_cache_create

When kmem_cache_create fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling kmem_cache_create.

---
 fs/notify/inotify/inotify_user.c | 2 ++
 1 file changed, 2 insertions(+)
fs/notify/inotify/inotify_user.c +2 -0
index ef32f36..0704bab 100644
@@ -805,6 +805,8 @@ static int __init inotify_user_setup(void)
 	BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
 
 	inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
+	if (!inotify_inode_mark_cachep)
+		return -ENOMEM;
 
 	inotify_max_queued_events = 16384;
 	init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines

锟斤拷 2018锟斤拷6锟斤拷12锟秸o拷锟斤拷锟斤拷12:22锟斤拷Zhouyang Jia <[email protected]> 写锟斤拷锟斤拷

When kmem_cache_create fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling kmem_cache_create.

I think SLAB_PANIC can handle this case.

Thanks,
Chengguang.

Quoted 22 lines

---
fs/notify/inotify/inotify_user.c | 2 ++

1 file changed, 2 insertions(+)
fs/notify/inotify/inotify_user.c +2 -0
index ef32f36..0704bab 100644
@@ -805,6 +805,8 @@ static int __init inotify_user_setup(void)
 	BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
 
 	inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
+	if (!inotify_inode_mark_cachep)
+		return -ENOMEM;
 
 	inotify_max_queued_events = 16384;
 	init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;
Signature · 1 line
2.7.4
#2 lore raw

in __kmem_cache_create->kmem_cache_open

with SLAB_PANIC, kernel will panic if it fail

Quoted 36 lines · On Tue, Jun 12, 2018 at 3:41 PM, [email protected] <[email protected]> wrote:
Quoted 7 lines · 在 2018年6月12日,下午12:22,Zhouyang Jia <[email protected]> 写道:

When kmem_cache_create fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling kmem_cache_create.

I think SLAB_PANIC can handle this case.

Thanks,
Chengguang.

Quoted 22 lines

---
fs/notify/inotify/inotify_user.c | 2 ++

1 file changed, 2 insertions(+)
fs/notify/inotify/inotify_user.c +2 -1
index ef32f36..0704bab 100644
@@ -805,6 +805,8 @@ static int __init inotify_user_setup(void)
      BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
 
      inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
+     if (!inotify_inode_mark_cachep)
+             return -ENOMEM;
 
      inotify_max_queued_events = 16384;
      init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;
--

2.7.4

Signature · 2 lines
Best regards
Kassey