Commit f8fc1343 authored by Chen Ridong's avatar Chen Ridong Committed by Zicheng Qu
Browse files

padata: avoid UAF for reorder_work

stable inclusion
from stable-v6.6.76
commit 6f45ef616775b0ce7889b0f6077fc8d681ab30bc
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBPBDP
CVE: CVE-2025-21726

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=6f45ef616775b0ce7889b0f6077fc8d681ab30bc



--------------------------------

[ 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)
...

				<kworker context>
				padata_serial_worker
				// completes new request,
				// no more outstanding
				// requests

							crypto_del_alg
							  // free pd

<kworker context>
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: bbefa1dd ("crypto: pcrypt - Avoid deadlock by using per-instance padata queues")
Signed-off-by: default avatarChen Ridong <chenridong@huawei.com>
Acked-by: default avatarDaniel Jordan <daniel.m.jordan@oracle.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZicheng Qu <quzicheng@huawei.com>
parent 50e56e12
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -357,9 +357,15 @@ 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)