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

Configure Feed

Select the types of activity you want to include in your feed.

unshare: fix nsproxy leak in ksys_unshare() on set_cred_ucounts() failure

When set_cred_ucounts() fails in ksys_unshare() new_nsproxy is leaked.

Let's call put_nsproxy() if that happens.

Link: https://lkml.kernel.org/r/20260213193959.2556730-1-mge@meta.com
Fixes: 905ae01c4ae2 ("Add a reference to ucounts for each cred")
Signed-off-by: Michal Grzedzicki <mge@meta.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexey Gladkov (Intel) <legion@kernel.org>
Cc: Ben Segall <bsegall@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Michal Grzedzicki and committed by
Andrew Morton
a98621a0 c970a863

+7 -4
+7 -4
kernel/fork.c
··· 3174 3174 new_cred, new_fs); 3175 3175 if (err) 3176 3176 goto bad_unshare_cleanup_cred; 3177 - 3178 3177 if (new_cred) { 3179 3178 err = set_cred_ucounts(new_cred); 3180 3179 if (err) 3181 - goto bad_unshare_cleanup_cred; 3180 + goto bad_unshare_cleanup_nsproxy; 3182 3181 } 3183 3182 3184 3183 if (new_fs || new_fd || do_sysvsem || new_cred || new_nsproxy) { ··· 3193 3194 shm_init_task(current); 3194 3195 } 3195 3196 3196 - if (new_nsproxy) 3197 + if (new_nsproxy) { 3197 3198 switch_task_namespaces(current, new_nsproxy); 3199 + new_nsproxy = NULL; 3200 + } 3198 3201 3199 3202 task_lock(current); 3200 3203 ··· 3225 3224 3226 3225 perf_event_namespaces(current); 3227 3226 3227 + bad_unshare_cleanup_nsproxy: 3228 + if (new_nsproxy) 3229 + put_nsproxy(new_nsproxy); 3228 3230 bad_unshare_cleanup_cred: 3229 3231 if (new_cred) 3230 3232 put_cred(new_cred); 3231 3233 bad_unshare_cleanup_fd: 3232 3234 if (new_fd) 3233 3235 put_files_struct(new_fd); 3234 - 3235 3236 bad_unshare_cleanup_fs: 3236 3237 if (new_fs) 3237 3238 free_fs_struct(new_fs);