Message ID | 20221019083708.27138-3-nstange@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp201439wrs; Wed, 19 Oct 2022 01:38:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4s0molZA4G0uT5d/wGO7knm3JWBzHCzomFoJaoqwR8sBLo+1KU9owpqNdin8NstpBM+ubj X-Received: by 2002:a05:6a00:1406:b0:565:dc13:bb36 with SMTP id l6-20020a056a00140600b00565dc13bb36mr7620476pfu.46.1666168681717; Wed, 19 Oct 2022 01:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168681; cv=none; d=google.com; s=arc-20160816; b=c8k8QLEcUdcFS+bsKiSsa0OZOVpsmkYmSo7MgoNd9G1WPfGv0sxFtD3AzYEnk3XOCA pE4QrOD3fRWGt1m/iGt5AFpDFJkQKGlPwdDpmVukrgAucCmeuWVZGib5NjZlZ+ljkNiK b3hN6mXfeyX+VWokVhLgRmr0LJJznjvQyVBPNmqELpfCXwvSzWtm++Q7B26SbPpO9et4 1n3MNeUXpUdtuaq+emJCkIo+nhIm+XV1T3u4gYY5NPT4TZ9SRxq5agY06mTMxsmkDjOs K6012yHdfQ/3RAR+uyFIuYpE4LdbLBG7DzXVm02npmaFdl5aeZKgOSEdZGDJSyv1ZwyI FVcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=D7VyTjcX7VW48TVL80NmZysRhyGrdRwOMNYwKQUMavo=; b=NwC3dvgPIkT/s5WR/l+RDGhiv5pWKbSZs038K16hTT3VIH3MfWd7Sv6P9O86alfNtI spYGtIENMV6ObdK31xtSI2icQSyuWQtnxkXRATGrgIzSX5kEwC7kC46RcPkzSWB3AQW+ J6uin3rRW56as1aRHk9LltNEQXU4Nbw/l9GY+oLBiureshpW8k50orD3DkapWPsQ8jOD CUYKGndPA6oNfxMRml32cHURrtIGiqGNWozoZCJxd61mN13D0GLDWqFZeit7TR7H9PKW Gr6JtRDgQyg3ym3aoQndHHZ3HWSLSsZC6cs0KuLDEcHVYwNGMBtv4wtg9AD/o2PQvuaW 5nBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=edqx8wbz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=dZPyjF1y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a170902b28900b001712e1efa9asi16676618plr.542.2022.10.19.01.37.49; Wed, 19 Oct 2022 01:38:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=edqx8wbz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=dZPyjF1y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbiJSIhd (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 04:37:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiJSIh0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 04:37:26 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A5274F677; Wed, 19 Oct 2022 01:37:24 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 131EF339ED; Wed, 19 Oct 2022 08:37:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666168642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D7VyTjcX7VW48TVL80NmZysRhyGrdRwOMNYwKQUMavo=; b=edqx8wbz4Mm+r4zK7xBid02cl0Hen8mMeleU9d9POi505+eX92W7XmE4mbJgKSjnux9OrX HR0EtpTnR6+nINT+Qn75I5xYJIG1kMX2dUK4ki6v3695x5G2bDM9W8FeHutx/GCeg7enWV HDBk4lpFsOm0lqEFWM8mD4qWqD+NibI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666168642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D7VyTjcX7VW48TVL80NmZysRhyGrdRwOMNYwKQUMavo=; b=dZPyjF1y8YbtDITpU29vZ91BAv8tTFw6T4i8RK/1levpSBAkUq5I+PahlYVT0y72721d2d GSIjW/09iXZBXYAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0354F13345; Wed, 19 Oct 2022 08:37:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RHk4AEK3T2NLZQAAMHmgww (envelope-from <nstange@suse.de>); Wed, 19 Oct 2022 08:37:22 +0000 From: Nicolai Stange <nstange@suse.de> To: Steffen Klassert <steffen.klassert@secunet.com>, Daniel Jordan <daniel.m.jordan@oracle.com> Cc: Herbert Xu <herbert@gondor.apana.org.au>, Martin Doucha <mdoucha@suse.cz>, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange <nstange@suse.de> Subject: [PATCH 2/5] padata: make padata_free_shell() to respect pd's ->refcnt Date: Wed, 19 Oct 2022 10:37:05 +0200 Message-Id: <20221019083708.27138-3-nstange@suse.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221019083708.27138-1-nstange@suse.de> References: <20221019083708.27138-1-nstange@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104491761071688?= X-GMAIL-MSGID: =?utf-8?q?1747104491761071688?= |
Series |
padata: fix liftime issues after ->serial() has completed
|
|
Commit Message
Nicolai Stange
Oct. 19, 2022, 8:37 a.m. UTC
On a PREEMPT kernel, the following has been observed while running
pcrypt_aead01 from LTP:
[ ] general protection fault: 0000 [#1] PREEMPT_RT SMP PTI
<...>
[ ] Workqueue: pdecrypt_parallel padata_parallel_worker
[ ] RIP: 0010:padata_reorder+0x19/0x120
<...>
[ ] Call Trace:
[ ] padata_parallel_worker+0xa3/0xf0
[ ] process_one_work+0x1db/0x4a0
[ ] worker_thread+0x2d/0x3c0
[ ] ? process_one_work+0x4a0/0x4a0
[ ] kthread+0x159/0x180
[ ] ? kthread_park+0xb0/0xb0
[ ] ret_from_fork+0x35/0x40
The pcrypt_aead01 testcase basically runs a NEWALG/DELALG sequence for some
fixed pcrypt instance in a loop, back to back.
The problem is that once the last ->serial() in padata_serial_worker() is
getting invoked, the pcrypt requests from the selftests would signal
completion, and pcrypt_aead01 can move on and subsequently issue a DELALG.
Upon pcrypt instance deregistration, the associated padata_shell would get
destroyed, which in turn would unconditionally free the associated
parallel_data instance.
If padata_serial_worker() now resumes operation after e.g. having
previously been preempted upon the return from the last of those ->serial()
callbacks, its subsequent accesses to pd for managing the ->refcnt will
all be UAFs. In particular, if the memory backing pd has meanwhile been
reused for some new parallel_data allocation, e.g in the course of
processing another subsequent NEWALG request, the padata_serial_worker()
might find the initial ->refcnt of one and free pd from under that NEWALG
or the associated selftests respectively, leading to "secondary" UAFs such
as in the Oops above.
Note that as it currently stands, a padata_shell owns a reference on its
associated parallel_data already. So fix the UAF in padata_serial_worker()
by making padata_free_shell() to not unconditionally free the shell's
associated parallel_data, but to properly drop that reference via
padata_put_pd() instead.
Fixes: 07928d9bfc81 ("padata: Remove broken queue flushing")
Signed-off-by: Nicolai Stange <nstange@suse.de>
---
kernel/padata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Wed, Oct 19, 2022 at 10:37:05AM +0200, Nicolai Stange wrote: > On a PREEMPT kernel, the following has been observed while running > pcrypt_aead01 from LTP: > > [ ] general protection fault: 0000 [#1] PREEMPT_RT SMP PTI > <...> > [ ] Workqueue: pdecrypt_parallel padata_parallel_worker > [ ] RIP: 0010:padata_reorder+0x19/0x120 > <...> > [ ] Call Trace: > [ ] padata_parallel_worker+0xa3/0xf0 > [ ] process_one_work+0x1db/0x4a0 > [ ] worker_thread+0x2d/0x3c0 > [ ] ? process_one_work+0x4a0/0x4a0 > [ ] kthread+0x159/0x180 > [ ] ? kthread_park+0xb0/0xb0 > [ ] ret_from_fork+0x35/0x40 > > The pcrypt_aead01 testcase basically runs a NEWALG/DELALG sequence for some > fixed pcrypt instance in a loop, back to back. > > The problem is that once the last ->serial() in padata_serial_worker() is > getting invoked, the pcrypt requests from the selftests would signal > completion, and pcrypt_aead01 can move on and subsequently issue a DELALG. > Upon pcrypt instance deregistration, the associated padata_shell would get > destroyed, which in turn would unconditionally free the associated > parallel_data instance. > > If padata_serial_worker() now resumes operation after e.g. having > previously been preempted upon the return from the last of those ->serial() > callbacks, its subsequent accesses to pd for managing the ->refcnt will > all be UAFs. In particular, if the memory backing pd has meanwhile been > reused for some new parallel_data allocation, e.g in the course of > processing another subsequent NEWALG request, the padata_serial_worker() > might find the initial ->refcnt of one and free pd from under that NEWALG > or the associated selftests respectively, leading to "secondary" UAFs such > as in the Oops above. > > Note that as it currently stands, a padata_shell owns a reference on its > associated parallel_data already. So fix the UAF in padata_serial_worker() > by making padata_free_shell() to not unconditionally free the shell's > associated parallel_data, but to properly drop that reference via > padata_put_pd() instead. > > Fixes: 07928d9bfc81 ("padata: Remove broken queue flushing") It looks like this issue goes back to the first padata commit. For instance, pd->refcnt goes to zero after the last _priv is serialized, padata_free is called in another task, and a particularly sluggish padata_reorder call touches pd after. So wouldn't it be Fixes: 16295bec6398 ("padata: Generic parallelization/serialization interface") ? Otherwise, Acked-by: Daniel Jordan <daniel.m.jordan@oracle.com> > Signed-off-by: Nicolai Stange <nstange@suse.de> > --- > kernel/padata.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/padata.c b/kernel/padata.c > index 3bd1e23f089b..0bf8c80dad5a 100644 > --- a/kernel/padata.c > +++ b/kernel/padata.c > @@ -1112,7 +1112,7 @@ void padata_free_shell(struct padata_shell *ps) > > mutex_lock(&ps->pinst->lock); > list_del(&ps->list); > - padata_free_pd(rcu_dereference_protected(ps->pd, 1)); > + padata_put_pd(rcu_dereference_protected(ps->pd, 1)); > mutex_unlock(&ps->pinst->lock); > > kfree(ps); > -- > 2.37.3 >
On Fri, Oct 28, 2022 at 10:35:49AM -0400, Daniel Jordan wrote: > On Wed, Oct 19, 2022 at 10:37:05AM +0200, Nicolai Stange wrote: > > Fixes: 07928d9bfc81 ("padata: Remove broken queue flushing") > > It looks like this issue goes back to the first padata commit. For > instance, pd->refcnt goes to zero after the last _priv is serialized, > padata_free is called in another task, and a particularly sluggish > padata_reorder call touches pd after. > > So wouldn't it be > > Fixes: 16295bec6398 ("padata: Generic parallelization/serialization interface") > > ? I guess not, by my own logic from 2/5. I think it might be Fixes: d46a5ac7a7e2 ("padata: Use a timer to handle remaining objects in the reorder queues")
Daniel Jordan <daniel.m.jordan@oracle.com> writes: > On Wed, Oct 19, 2022 at 10:37:05AM +0200, Nicolai Stange wrote: >> >> Fixes: 07928d9bfc81 ("padata: Remove broken queue flushing") > > It looks like this issue goes back to the first padata commit. For > instance, pd->refcnt goes to zero after the last _priv is serialized, > padata_free is called in another task, and a particularly sluggish > padata_reorder call touches pd after. > > So wouldn't it be > > Fixes: 16295bec6398 ("padata: Generic parallelization/serialization interface") I chose 07928d9bfc81 ("padata: Remove broken queue flushing"), because that one reads like it fixed a couple of much more severe padata lifetime issues, it only missed the relatively minor one addressed here, in a sense. Or to put it the other way around: if one were to backport this patch here, 07928d9bfc81 should probably get picked first, I think. But I'd be fine with any Fixes tag, of course, I don't have a strong opinion on this matter. Thanks! Nicolai > > ? > > Otherwise, > > Acked-by: Daniel Jordan <daniel.m.jordan@oracle.com> > >> Signed-off-by: Nicolai Stange <nstange@suse.de> >> ---
On Wed, Nov 09, 2022 at 02:02:37PM +0100, Nicolai Stange wrote: > Daniel Jordan <daniel.m.jordan@oracle.com> writes: > > > On Wed, Oct 19, 2022 at 10:37:05AM +0200, Nicolai Stange wrote: > >> > >> Fixes: 07928d9bfc81 ("padata: Remove broken queue flushing") > > > > It looks like this issue goes back to the first padata commit. For > > instance, pd->refcnt goes to zero after the last _priv is serialized, > > padata_free is called in another task, and a particularly sluggish > > padata_reorder call touches pd after. > > > > So wouldn't it be > > > > Fixes: 16295bec6398 ("padata: Generic parallelization/serialization interface") > > I chose 07928d9bfc81 ("padata: Remove broken queue flushing"), because > that one reads like it fixed a couple of much more severe padata > lifetime issues, it only missed the relatively minor one addressed here, > in a sense. > > Or to put it the other way around: if one were to backport this patch > here, 07928d9bfc81 should probably get picked first, I think. > > But I'd be fine with any Fixes tag, of course, I don't have a strong > opinion on this matter. Ok, makes sense, your Fixes is fine then. Please put that justification in the changelog for the next version.
diff --git a/kernel/padata.c b/kernel/padata.c index 3bd1e23f089b..0bf8c80dad5a 100644 --- a/kernel/padata.c +++ b/kernel/padata.c @@ -1112,7 +1112,7 @@ void padata_free_shell(struct padata_shell *ps) mutex_lock(&ps->pinst->lock); list_del(&ps->list); - padata_free_pd(rcu_dereference_protected(ps->pd, 1)); + padata_put_pd(rcu_dereference_protected(ps->pd, 1)); mutex_unlock(&ps->pinst->lock); kfree(ps);