Message ID | 20231206145744.17277-1-lhenriques@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4158796vqy; Wed, 6 Dec 2023 06:58:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGexsSb/6A0sreui2HhN+CyNGYJBi5rM5J6OfOlJrTOltiDQwRepWj2QVoYGTaZ2dzlB7C8 X-Received: by 2002:a05:6a21:3388:b0:18b:ef96:be44 with SMTP id yy8-20020a056a21338800b0018bef96be44mr769518pzb.26.1701874683584; Wed, 06 Dec 2023 06:58:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701874683; cv=none; d=google.com; s=arc-20160816; b=DhrwTvpOtjl0gHQSI04ub2VCERTyOcUrXdRr/HXM4A3aMUkyQkcNE1C2au95V/y47D zWleoiLU6tjy4q6weTrUNYqy1kc9OzZukiRRmPwJGlgEC+ybwuoaUJR52eHEhk8Kysa5 NyWxpaHoPbQntcDLr4WC1l2KIIS4kRPOaLVdGYlNaW8Iz61ZnduwdAcEq0T5rSOWih30 XIbGNF6mG6CR65333TI/QHbB3vWVipWORAiN6249ggv1gc9P4mgIxxUz3F4mggu0FfTS xnnwa9tB3LfdtF711HUXuxstooFmCI56bUrtFuM4frRHdbuc1xJ5oZm5XRbHLLWOVR42 48+A== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=W1iEqONk/zbDaDJmdYP4h1bjI7CKaBWSU7dA6BrXLIg=; fh=qP3id9se7BdhqsOT8PgHjCtHeBjcSno2UdFxifn4Nuw=; b=R+UPPX+zUrO/ZP7dnwndPiaYe2KjE4Rbq72OT2oFvsI0v+nr+CFN9poil1qzjWWQ+Q SWa1kE5isPeBMNCwr5I9W3Fmgm2lTT7O74lrI8X+1TExQNFGUDnPP3CtSEf607LFE+au f6tbdGY39rfvISwic51rQxIo/zwVfE3JKv3mUTW6ug4i6UmSstDrOyzAWcMio3lxVL+k pFC3p3x6xL+5477IeHfrHCLuVTtM60Yey0DyCuXcqqleqtunYWAPtJvCOb6TfJXvvx3B RrALdZZVB+qmlFSev9HKEV3/mIY1kkg4CV3XlBri5ZBZDNMgOxgvTKThNL4WKDoc/mOR NAOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aKenJujc; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="h+/H8r6W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o17-20020a656151000000b005c1b2e37aeasi22298pgv.384.2023.12.06.06.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 06:58:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aKenJujc; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="h+/H8r6W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 11CD080C8D4F; Wed, 6 Dec 2023 06:57:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379029AbjLFO5p (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Wed, 6 Dec 2023 09:57:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379018AbjLFO5n (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 6 Dec 2023 09:57:43 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4ED3B5; Wed, 6 Dec 2023 06:57:49 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 95C2E1FD16; Wed, 6 Dec 2023 14:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701874667; 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; bh=W1iEqONk/zbDaDJmdYP4h1bjI7CKaBWSU7dA6BrXLIg=; b=aKenJujcJEApG75yiRDSuPOBECArFJf9/amlfRfD4veoUrSAx7mX9tyjh+Pfoupm4/Q2CW AK8eNokOXNKRT1Ve4KZFkVnWUvZ3NhCovynNnW8VDZuR38IBlIpwMWT63Sj0X0bdt0DR62 3WOadVDrCxisHF5JdmDQPJ3gTMdo2bU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701874667; 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; bh=W1iEqONk/zbDaDJmdYP4h1bjI7CKaBWSU7dA6BrXLIg=; b=h+/H8r6WaarZ8hA9GAXKZE4KL0Yf9Jw4qxX9HzieBFF2CDicFgo/PgpkQxaYPfNuiR+2KQ xE/C0m+ddCjMixDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D3117136CD; Wed, 6 Dec 2023 14:57:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id vt8jLuqLcGVBQgAAD6G6ig (envelope-from <lhenriques@suse.de>); Wed, 06 Dec 2023 14:57:46 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 653c8557; Wed, 6 Dec 2023 14:57:45 +0000 (UTC) From: Luis Henriques <lhenriques@suse.de> To: David Howells <dhowells@redhat.com>, Jarkko Sakkinen <jarkko@kernel.org>, Eric Biggers <ebiggers@kernel.org> Cc: keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Henriques <lhenriques@suse.de> Subject: [RFC PATCH] keys: flush work when accessing /proc/key-users Date: Wed, 6 Dec 2023 14:57:44 +0000 Message-ID: <20231206145744.17277-1-lhenriques@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 1.70 X-Spamd-Result: default: False [1.70 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_THREE(0.00)[4]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com] X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 06:57:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784544948051881989 X-GMAIL-MSGID: 1784544948051881989 |
Series |
[RFC] keys: flush work when accessing /proc/key-users
|
|
Commit Message
Luis Henriques
Dec. 6, 2023, 2:57 p.m. UTC
Make sure the garbage collector has been run before cycling through all
the user keys.
Signed-off-by: Luis Henriques <lhenriques@suse.de>
---
Hi!
This patch is mostly for getting some feedback on how to fix an fstest
failing for ext4/fscrypt (generic/581). Basically, the test relies on the
data read from /proc/key-users to be up-to-date regarding the number of
keys a given user currently has. However, this file can't be trusted
because it races against the keys GC.
Using flush_work() seems to work (I can't reproduce the failure), but it
may be overkill. Or simply not acceptable. Maybe, as Eric suggested
elsewhere [1], there could be a synchronous key_put/revoke/invalidate/...,
which would wait for the key GC to do its work, although that probably
would require some more code re-work.
[1] https://lore.kernel.org/all/20231128173734.GD1148@sol.localdomain/
security/keys/gc.c | 6 ++++++
security/keys/internal.h | 1 +
security/keys/proc.c | 1 +
3 files changed, 8 insertions(+)
Comments
Luis Henriques <lhenriques@suse.de> wrote: > This patch is mostly for getting some feedback on how to fix an fstest > failing for ext4/fscrypt (generic/581). Basically, the test relies on the > data read from /proc/key-users to be up-to-date regarding the number of > keys a given user currently has. However, this file can't be trusted > because it races against the keys GC. Unfortunately, I don't think your patch helps. If the GC hasn't started yet, it won't achieve anything and the GC can still be triggered at any time after the flush and thus race. What is it you're actually trying to determine? And is it only for doing the test? David
David Howells <dhowells@redhat.com> writes: > Luis Henriques <lhenriques@suse.de> wrote: > >> This patch is mostly for getting some feedback on how to fix an fstest >> failing for ext4/fscrypt (generic/581). Basically, the test relies on the >> data read from /proc/key-users to be up-to-date regarding the number of >> keys a given user currently has. However, this file can't be trusted >> because it races against the keys GC. > > Unfortunately, I don't think your patch helps. If the GC hasn't started yet, > it won't achieve anything and the GC can still be triggered at any time after > the flush and thus race. > > What is it you're actually trying to determine? > > And is it only for doing the test? OK, let me try to describe what the generic/581 fstest does. After doing a few fscrypt related things, which involve adding and removing keys, the test will: 1. Get the number of keys for user 'fsgqa' from '/proc/key-users' 2. Set the maxkeys to 5 + <keys the user had in 1.> 3. In a loop, try to add 6 new keys, to confirm the last one will fail Most of the time the test passes, i.e., the 6th key fails to be added. However, if, for example, the test is executed in a loop, it is possible to have it fail because the 6th key was successfully added. The reason is, obviously, because the test is racy: the GC can kick-in too late, after the maxkeys is set in step 2. So, this is mostly an issue with the test itself, but I couldn't figure out a way to work around it. Another solution I thought but I didn't look too deep into was to try to move the atomic_dec(&key->user->nkeys); out of the GC, in function key_gc_unused_keys(). Decrementing it synchronously in key_put() (or whatever other functions could schedule GC) should solve the problem with this test. But as I said I didn't went too far looking into that, so I don't really know if that's feasible. Finally, the test itself could be hacked so that the loop in step 3. would update the maxkeys value if needed, i.e. if the current number of keys for the user isn't what was expected in each loop iteration. But even that would still be racy. Cheers,
On Wed, Dec 06, 2023 at 05:55:52PM +0000, Luis Henriques wrote: > David Howells <dhowells@redhat.com> writes: > > > Luis Henriques <lhenriques@suse.de> wrote: > > > >> This patch is mostly for getting some feedback on how to fix an fstest > >> failing for ext4/fscrypt (generic/581). Basically, the test relies on the > >> data read from /proc/key-users to be up-to-date regarding the number of > >> keys a given user currently has. However, this file can't be trusted > >> because it races against the keys GC. > > > > Unfortunately, I don't think your patch helps. If the GC hasn't started yet, > > it won't achieve anything and the GC can still be triggered at any time after > > the flush and thus race. > > > > What is it you're actually trying to determine? > > > > And is it only for doing the test? > > OK, let me try to describe what the generic/581 fstest does. > > After doing a few fscrypt related things, which involve adding and > removing keys, the test will: > > 1. Get the number of keys for user 'fsgqa' from '/proc/key-users' > 2. Set the maxkeys to 5 + <keys the user had in 1.> > 3. In a loop, try to add 6 new keys, to confirm the last one will fail > > Most of the time the test passes, i.e., the 6th key fails to be added. > However, if, for example, the test is executed in a loop, it is possible > to have it fail because the 6th key was successfully added. The reason > is, obviously, because the test is racy: the GC can kick-in too late, > after the maxkeys is set in step 2. > > So, this is mostly an issue with the test itself, but I couldn't figure > out a way to work around it. > > Another solution I thought but I didn't look too deep into was to try to > move the > > atomic_dec(&key->user->nkeys); > > out of the GC, in function key_gc_unused_keys(). Decrementing it > synchronously in key_put() (or whatever other functions could schedule GC) > should solve the problem with this test. But as I said I didn't went too > far looking into that, so I don't really know if that's feasible. > > Finally, the test itself could be hacked so that the loop in step 3. would > update the maxkeys value if needed, i.e. if the current number of keys for > the user isn't what was expected in each loop iteration. But even that > would still be racy. If there was a function that fully and synchronously releases a key's quota, fs/crypto/ could call it before unlinking the key. key_payload_reserve(key, 0) almost does the trick, but it would release the key's bytes, not the key itself. However, that would only fix the flakiness of the key quota for fs/crypto/, not for other users of the keyrings service. Maybe this suggests that key_put() should release the key's quota right away if the key's refcount drops to 0? Either way, note that where fs/crypto/ does key_put() on a whole keyring at once, it would first need to call keyring_clear() to clear it synchronously. A third solution would be to make fs/crypto/ completely stop using 'struct key', and handle quotas itself. It would do it correctly, i.e. synchronously so that the results are predictable. This would likely mean separate accounting, where adding an fscrypt key counts against an fscrypt key quota, not the regular keyrings service quota as it does now. That should be fine, though the same limits might still need to be used, in case users are relying on the sysctls... The last solution seems quite attractive at this point, given the number of times that issues in the keyrings service have caused problems for fs/crypto/. Any thoughts are appreciated, though. - Eric
David, this really needs your feedback. BR, Jarkko On Wed, 2023-12-06 at 14:57 +0000, Luis Henriques wrote: > Make sure the garbage collector has been run before cycling through > all > the user keys. > > Signed-off-by: Luis Henriques <lhenriques@suse.de> > --- > Hi! > > This patch is mostly for getting some feedback on how to fix an > fstest > failing for ext4/fscrypt (generic/581). Basically, the test relies > on the > data read from /proc/key-users to be up-to-date regarding the number > of > keys a given user currently has. However, this file can't be trusted > because it races against the keys GC. > > Using flush_work() seems to work (I can't reproduce the failure), but > it > may be overkill. Or simply not acceptable. Maybe, as Eric suggested > elsewhere [1], there could be a synchronous > key_put/revoke/invalidate/..., > which would wait for the key GC to do its work, although that > probably > would require some more code re-work. > > [1] > https://lore.kernel.org/all/20231128173734.GD1148@sol.localdomain/ > > security/keys/gc.c | 6 ++++++ > security/keys/internal.h | 1 + > security/keys/proc.c | 1 + > 3 files changed, 8 insertions(+) > > diff --git a/security/keys/gc.c b/security/keys/gc.c > index 3c90807476eb..57b5a54490a0 100644 > --- a/security/keys/gc.c > +++ b/security/keys/gc.c > @@ -44,6 +44,12 @@ struct key_type key_type_dead = { > .name = ".dead", > }; > > +void key_flush_gc(void) > +{ > + kenter(""); > + flush_work(&key_gc_work); > +} > + > /* > * Schedule a garbage collection run. > * - time precision isn't particularly important > diff --git a/security/keys/internal.h b/security/keys/internal.h > index 471cf36dedc0..fee1d0025d96 100644 > --- a/security/keys/internal.h > +++ b/security/keys/internal.h > @@ -170,6 +170,7 @@ extern void keyring_restriction_gc(struct key > *keyring, > extern void key_schedule_gc(time64_t gc_at); > extern void key_schedule_gc_links(void); > extern void key_gc_keytype(struct key_type *ktype); > +extern void key_flush_gc(void); > > extern int key_task_permission(const key_ref_t key_ref, > const struct cred *cred, > diff --git a/security/keys/proc.c b/security/keys/proc.c > index d0cde6685627..2837e00a240a 100644 > --- a/security/keys/proc.c > +++ b/security/keys/proc.c > @@ -277,6 +277,7 @@ static void *proc_key_users_start(struct seq_file > *p, loff_t *_pos) > struct rb_node *_p; > loff_t pos = *_pos; > > + key_flush_gc(); > spin_lock(&key_user_lock); > > _p = key_user_first(seq_user_ns(p), &key_user_tree);
Eric Biggers <ebiggers@kernel.org> wrote: > If there was a function that fully and synchronously releases a key's quota, > fs/crypto/ could call it before unlinking the key. key_payload_reserve(key, > 0) almost does the trick, but it would release the key's bytes, not the key > itself. Umm... The point of the quota is that the key is occupying unswappable kernel memory (partly true in the case of big_key) and we need to limit that. Further, the key is not released until it is unlinked. > However, that would only fix the flakiness of the key quota for fs/crypto/, > not for other users of the keyrings service. Maybe this suggests that > key_put() should release the key's quota right away if the key's refcount > drops to 0? That I would be okay with as the key should be removed in short order. Note that you'd have to change the spinlocks on key->user->lock to irq-locking types. Or maybe we can do without them, at least for key gc, and use atomic counters. key_invalidate() should probably drop the quota also. I'm also working up a patch so that key types can be marked for immediate gc if they expire, rather than there being a period (key_gc_delay) in which they cause EKEYEXPIRED rather than ENOKEY to be returned for better indication to userspace as to what's happened when a filesystem op fails to to key problems. > Either way, note that where fs/crypto/ does key_put() on a whole keyring at > once, it would first need to call keyring_clear() to clear it synchronously. What if there's another link on the keyring? Should it still be cleared? Do we need faster disposal of keys? Perhaps keeping a list of keys that need destroying rather than scanning the entire key set for them. We still need to scan non-destroyed keyrings, though, to find the pointers to defunct keys unless I have some sort of backpointer list. David
On Mon, Dec 11, 2023 at 02:02:47PM +0000, David Howells wrote: > Eric Biggers <ebiggers@kernel.org> wrote: > > > If there was a function that fully and synchronously releases a key's quota, > > fs/crypto/ could call it before unlinking the key. key_payload_reserve(key, > > 0) almost does the trick, but it would release the key's bytes, not the key > > itself. > > Umm... The point of the quota is that the key is occupying unswappable kernel > memory (partly true in the case of big_key) and we need to limit that. > Further, the key is not released until it is unlinked. Well, fs/crypto/ no longer uses the keyrings subsystem for the actual keys, as that was far too broken. It just ties into the quota now. So what's needed is a way to release quota synchronously. That might just mean not using the keyrings subsystem at all anymore. > Do we need faster disposal of keys? Perhaps keeping a list of keys that need > destroying rather than scanning the entire key set for them. We still need to > scan non-destroyed keyrings, though, to find the pointers to defunct keys > unless I have some sort of backpointer list. If it's still asynchronous, that doesn't solve the problem. - Eric
Hi David, On Mon, Dec 11, 2023 at 02:02:47PM +0000, David Howells wrote: <snip> > > However, that would only fix the flakiness of the key quota for fs/crypto/, > > not for other users of the keyrings service. Maybe this suggests that > > key_put() should release the key's quota right away if the key's refcount > > drops to 0? > > That I would be okay with as the key should be removed in short order. > > Note that you'd have to change the spinlocks on key->user->lock to irq-locking > types. Or maybe we can do without them, at least for key gc, and use atomic > counters. key_invalidate() should probably drop the quota also. I was trying to help with this but, first, I don't think atomic counters would actually be a solution. For example, we have the following in key_alloc(): spin_lock(&user->lock); if (!(flags & KEY_ALLOC_QUOTA_OVERRUN)) { if (user->qnkeys + 1 > maxkeys || user->qnbytes + quotalen > maxbytes || user->qnbytes + quotalen < user->qnbytes) goto no_quota; } user->qnkeys++; user->qnbytes += quotalen; spin_unlock(&user->lock); Thus, I don't think it's really possible to simply stop using a lock without making these checks+changes non-atomic. As for using spin_lock_irq() or spin_lock_irqsave(), my understanding is that the only places where this could be necessary is in key_put() and, possibly, key_payload_reserve(). key_alloc() shouldn't need that. Finally, why would key_invalidate() require handling quotas? I'm probably just missing some subtlety, but I don't see the user->usage refcount being decremented anywhere in that path (or anywhere else, really). Cheers, -- Luís
diff --git a/security/keys/gc.c b/security/keys/gc.c index 3c90807476eb..57b5a54490a0 100644 --- a/security/keys/gc.c +++ b/security/keys/gc.c @@ -44,6 +44,12 @@ struct key_type key_type_dead = { .name = ".dead", }; +void key_flush_gc(void) +{ + kenter(""); + flush_work(&key_gc_work); +} + /* * Schedule a garbage collection run. * - time precision isn't particularly important diff --git a/security/keys/internal.h b/security/keys/internal.h index 471cf36dedc0..fee1d0025d96 100644 --- a/security/keys/internal.h +++ b/security/keys/internal.h @@ -170,6 +170,7 @@ extern void keyring_restriction_gc(struct key *keyring, extern void key_schedule_gc(time64_t gc_at); extern void key_schedule_gc_links(void); extern void key_gc_keytype(struct key_type *ktype); +extern void key_flush_gc(void); extern int key_task_permission(const key_ref_t key_ref, const struct cred *cred, diff --git a/security/keys/proc.c b/security/keys/proc.c index d0cde6685627..2837e00a240a 100644 --- a/security/keys/proc.c +++ b/security/keys/proc.c @@ -277,6 +277,7 @@ static void *proc_key_users_start(struct seq_file *p, loff_t *_pos) struct rb_node *_p; loff_t pos = *_pos; + key_flush_gc(); spin_lock(&key_user_lock); _p = key_user_first(seq_user_ns(p), &key_user_tree);