Skip to content

Commit 1020966

Browse files
Ma Wupenggregkh
Ma Wupeng
authored andcommitted
ipc: fix memleak if msg_init_ns failed in create_ipc_ns
commit bc8f592 upstream. Percpu memory allocation may failed during create_ipc_ns however this fail is not handled properly since ipc sysctls and mq sysctls is not released properly. Fix this by release these two resource when failure. Here is the kmemleak stack when percpu failed: unreferenced object 0xffff88819de2a600 (size 512): comm "shmem_2nstest", pid 120711, jiffies 4300542254 hex dump (first 32 bytes): 60 aa 9d 84 ff ff ff ff fc 18 48 b2 84 88 ff ff `.........H..... 04 00 00 00 a4 01 00 00 20 e4 56 81 ff ff ff ff ........ .V..... backtrace (crc be7cba35): [<ffffffff81b43f83>] __kmalloc_node_track_caller_noprof+0x333/0x420 [<ffffffff81a52e56>] kmemdup_noprof+0x26/0x50 [<ffffffff821b2f37>] setup_mq_sysctls+0x57/0x1d0 [<ffffffff821b29cc>] copy_ipcs+0x29c/0x3b0 [<ffffffff815d6a10>] create_new_namespaces+0x1d0/0x920 [<ffffffff815d7449>] copy_namespaces+0x2e9/0x3e0 [<ffffffff815458f3>] copy_process+0x29f3/0x7ff0 [<ffffffff8154b080>] kernel_clone+0xc0/0x650 [<ffffffff8154b6b1>] __do_sys_clone+0xa1/0xe0 [<ffffffff843df8ff>] do_syscall_64+0xbf/0x1c0 [<ffffffff846000b0>] entry_SYSCALL_64_after_hwframe+0x4b/0x53 Link: https://lkml.kernel.org/r/[email protected] Fixes: 72d1e61 ("ipc/msg: mitigate the lock contention with percpu counter") Signed-off-by: Ma Wupeng <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 27d6e7e commit 1020966

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ipc/namespace.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
8383

8484
err = msg_init_ns(ns);
8585
if (err)
86-
goto fail_put;
86+
goto fail_ipc;
8787

8888
sem_init_ns(ns);
8989
shm_init_ns(ns);
9090

9191
return ns;
9292

93+
fail_ipc:
94+
retire_ipc_sysctls(ns);
9395
fail_mq:
9496
retire_mq_sysctls(ns);
9597

0 commit comments

Comments
 (0)