Skip to content

Commit 665dc1e

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 bba68ec commit 665dc1e

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
@@ -3176,11 +3176,10 @@ int ksys_unshare(unsigned long unshare_flags)
31763176
new_cred, new_fs);
31773177
if (err)
31783178
goto bad_unshare_cleanup_cred;
3179-
31803179
if (new_cred) {
31813180
err = set_cred_ucounts(new_cred);
31823181
if (err)
3183-
goto bad_unshare_cleanup_cred;
3182+
goto bad_unshare_cleanup_nsproxy;
31843183
}
31853184

31863185
if (new_fs || new_fd || do_sysvsem || new_cred || new_nsproxy) {
@@ -3196,8 +3195,10 @@ int ksys_unshare(unsigned long unshare_flags)
31963195
shm_init_task(current);
31973196
}
31983197

3199-
if (new_nsproxy)
3198+
if (new_nsproxy) {
32003199
switch_task_namespaces(current, new_nsproxy);
3200+
new_nsproxy = NULL;
3201+
}
32013202

32023203
task_lock(current);
32033204

@@ -3226,13 +3227,15 @@ int ksys_unshare(unsigned long unshare_flags)
32263227

32273228
perf_event_namespaces(current);
32283229

3230+
bad_unshare_cleanup_nsproxy:
3231+
if (new_nsproxy)
3232+
put_nsproxy(new_nsproxy);
32293233
bad_unshare_cleanup_cred:
32303234
if (new_cred)
32313235
put_cred(new_cred);
32323236
bad_unshare_cleanup_fd:
32333237
if (new_fd)
32343238
put_files_struct(new_fd);
3235-
32363239
bad_unshare_cleanup_fs:
32373240
if (new_fs)
32383241
free_fs_struct(new_fs);

0 commit comments

Comments
 (0)