From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27BC425F792; Tue, 11 Mar 2025 15:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741706480; cv=none; b=aqxXqj1SNervsUGhD36tZHTye/ucNd5zpa50g1TH+k/qfukPKCXuBBe6YEfxUMVZQVirNao4oonFRY+EbBl1wl+HftsBeRI26RFwGvDaBFi+ZH8hwXvZmK8nG9+xvwMSchJiLBqQGgMZkacY2WY5YXsVO5VfzMLNkT7glpwVqGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741706480; c=relaxed/simple; bh=j9rWExjzmlr9qZQgycjMemj5JkemTOEZMjixnR/M6Fc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HLDlNNQmzFuzbdTxG1babzAwpVxgOSRdQsNRX+kaAT1J1kpZO53SV2N3i41cie+rmTFmkuhsVkhLhjETodiJ75JtjogXymISIBpWSgCvh62+1/2GFsX49LW2qVOPnImqZWYOfPDdhojy23Wn84OJOfFOMeoFDBhlNcyyaKBawfA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xQGSiPiF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xQGSiPiF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48877C4CEE9; Tue, 11 Mar 2025 15:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741706479; bh=j9rWExjzmlr9qZQgycjMemj5JkemTOEZMjixnR/M6Fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xQGSiPiFjVotKNhIP2iN8qJ6ilyZp+CntDn5c9u1Z5SMsdmjknNLvTphY8PHaf61l 5orVM8po48BbiFEW/py/Qcu8ysdStPtbL0Vko8/89hTiUNJIgaLJy1dBNHVeTyp9z1 8i89CANvT1L+atfRJ90nxsbGcriywoMjBSTS0k5A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chen Ridong , Daniel Jordan , Herbert Xu , Sasha Levin Subject: [PATCH 5.10 062/462] padata: avoid UAF for reorder_work Date: Tue, 11 Mar 2025 15:55:28 +0100 Message-ID: <20250311145800.800616122@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145758.343076290@linuxfoundation.org> References: <20250311145758.343076290@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chen Ridong [ Upstream commit dd7d37ccf6b11f3d95e797ebe4e9e886d0332600 ] Although the previous patch can avoid ps and ps UAF for _do_serial, it can not avoid potential UAF issue for reorder_work. This issue can happen just as below: crypto_request crypto_request crypto_del_alg padata_do_serial ... padata_reorder // processes all remaining // requests then breaks while (1) { if (!padata) break; ... } padata_do_serial // new request added list_add // sees the new request queue_work(reorder_work) padata_reorder queue_work_on(squeue->work) ... padata_serial_worker // completes new request, // no more outstanding // requests crypto_del_alg // free pd invoke_padata_reorder // UAF of pd To avoid UAF for 'reorder_work', get 'pd' ref before put 'reorder_work' into the 'serial_wq' and put 'pd' ref until the 'serial_wq' finish. Fixes: bbefa1dd6a6d ("crypto: pcrypt - Avoid deadlock by using per-instance padata queues") Signed-off-by: Chen Ridong Acked-by: Daniel Jordan Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- kernel/padata.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/padata.c b/kernel/padata.c index 02bb06a2c797d..c7aa60907fdf8 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -357,8 +357,14 @@ static void padata_reorder(struct parallel_data *pd) smp_mb(); reorder = per_cpu_ptr(pd->reorder_list, pd->cpu); - if (!list_empty(&reorder->list) && padata_find_next(pd, false)) + if (!list_empty(&reorder->list) && padata_find_next(pd, false)) { + /* + * Other context(eg. the padata_serial_worker) can finish the request. + * To avoid UAF issue, add pd ref here, and put pd ref after reorder_work finish. + */ + padata_get_pd(pd); queue_work(pinst->serial_wq, &pd->reorder_work); + } } static void invoke_padata_reorder(struct work_struct *work) @@ -369,6 +375,8 @@ static void invoke_padata_reorder(struct work_struct *work) pd = container_of(work, struct parallel_data, reorder_work); padata_reorder(pd); local_bh_enable(); + /* Pairs with putting the reorder_work in the serial_wq */ + padata_put_pd(pd); } static void padata_serial_worker(struct work_struct *serial_work) -- 2.39.5