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

powerpc/powernv/vas: Release reference to tgid during window close

The kernel handles the NX fault by updating CSB or sending
signal to process. In multithread applications, children can
open VAS windows and can exit without closing them. But the
parent can continue to send NX requests with these windows. To
prevent pid reuse, reference will be taken on pid and tgid
when the window is opened and release them during window close.

The current code is not releasing the tgid reference which can
cause pid leak and this patch fixes the issue.

Fixes: db1c08a740635 ("powerpc/vas: Take reference to PID and mm for user space windows")
Cc: stable@vger.kernel.org # 5.8+
Reported-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Haren Myneni <haren@linux.ibm.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/6020fc4d444864fe20f7dcdc5edfe53e67480a1c.camel@linux.ibm.com

authored by

Haren Myneni and committed by
Michael Ellerman
91cdbb95 3c536423

+5 -4
+5 -4
arch/powerpc/platforms/powernv/vas-window.c
··· 1093 1093 /* 1094 1094 * Process closes window during exit. In the case of 1095 1095 * multithread application, the child thread can open 1096 - * window and can exit without closing it. Expects parent 1097 - * thread to use and close the window. So do not need 1098 - * to take pid reference for parent thread. 1096 + * window and can exit without closing it. so takes tgid 1097 + * reference until window closed to make sure tgid is not 1098 + * reused. 1099 1099 */ 1100 1100 txwin->tgid = find_get_pid(task_tgid_vnr(current)); 1101 1101 /* ··· 1339 1339 /* if send window, drop reference to matching receive window */ 1340 1340 if (window->tx_win) { 1341 1341 if (window->user_win) { 1342 - /* Drop references to pid and mm */ 1342 + /* Drop references to pid. tgid and mm */ 1343 1343 put_pid(window->pid); 1344 + put_pid(window->tgid); 1344 1345 if (window->mm) { 1345 1346 mm_context_remove_vas_window(window->mm); 1346 1347 mmdrop(window->mm);