Skip to content

Commit a261fcc

Browse files
Michal Grzedzickigregkh
authored andcommitted
unshare: fix nsproxy leak in ksys_unshare() on set_cred_ucounts() failure
[ Upstream commit a98621a ] 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: 905ae01 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c892d0d commit a261fcc

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

kernel/fork.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,11 +3132,10 @@ int ksys_unshare(unsigned long unshare_flags)
31323132
new_cred, new_fs);
31333133
if (err)
31343134
goto bad_unshare_cleanup_cred;
3135-
31363135
if (new_cred) {
31373136
err = set_cred_ucounts(new_cred);
31383137
if (err)
3139-
goto bad_unshare_cleanup_cred;
3138+
goto bad_unshare_cleanup_nsproxy;
31403139
}
31413140

31423141
if (new_fs || new_fd || do_sysvsem || new_cred || new_nsproxy) {
@@ -3152,8 +3151,10 @@ int ksys_unshare(unsigned long unshare_flags)
31523151
shm_init_task(current);
31533152
}
31543153

3155-
if (new_nsproxy)
3154+
if (new_nsproxy) {
31563155
switch_task_namespaces(current, new_nsproxy);
3156+
new_nsproxy = NULL;
3157+
}
31573158

31583159
task_lock(current);
31593160

@@ -3182,13 +3183,15 @@ int ksys_unshare(unsigned long unshare_flags)
31823183

31833184
perf_event_namespaces(current);
31843185

3186+
bad_unshare_cleanup_nsproxy:
3187+
if (new_nsproxy)
3188+
put_nsproxy(new_nsproxy);
31853189
bad_unshare_cleanup_cred:
31863190
if (new_cred)
31873191
put_cred(new_cred);
31883192
bad_unshare_cleanup_fd:
31893193
if (new_fd)
31903194
put_files_struct(new_fd);
3191-
31923195
bad_unshare_cleanup_fs:
31933196
if (new_fs)
31943197
free_fs_struct(new_fs);

0 commit comments

Comments
 (0)