Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jarkko Sakkinen" <jarkko@kernel.org>,
	"David Howells" <dhowells@redhat.com>
Cc: keyrings@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	samba-technical@lists.samba.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Anna Schumaker" <anna@kernel.org>,
	"Bharath SM" <bharathsm@microsoft.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"James Bottomley" <James.Bottomley@HansenPartnership.com>,
	"James Morris" <jmorris@namei.org>,
	"Marc Dionne" <marc.dionne@auristor.com>,
	"Mimi Zohar" <zohar@linux.ibm.com>,
	"Namjae Jeon" <linkinjeon@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"Paulo Alcantara" <pc@manguebit.org>,
	"Ronnie Sahlberg" <ronniesahlberg@gmail.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Shyam Prasad N" <sprasad@microsoft.com>,
	"Simon Horman" <horms@kernel.org>,
	"Sumit Garg" <sumit.garg@kernel.org>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Tom Talpey" <tom@talpey.com>,
	"Trond Myklebust" <trondmy@kernel.org>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>
Subject: Re: [RFC PATCH v3 04/11] smb: client: Clear idmap/SPNEGO caches when the last session is unloaded
Date: Fri, 06 Nov 2026 00:54:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-200459@kernel.org> (raw)
In-Reply-To: <20261105005311.804098-5-jarkko@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] smb: client: WQ_MEM_RECLAIM flush dependency violation in sesInfoFree()
- [Medium] smb: client: WARN_ON() on fallible keyring_clear() in cache clear helpers
--

commit 359186c48dde297d60c971ef75e736ee0f7821b6
Author: Jarkko Sakkinen <jarkko@kernel.org>

smb: client: Clear idmap/SPNEGO caches when the last session is unloaded

This commit serializes SMB session count transitions with a mutex and clears
the cifs.idmap and cifs.spnego cache keyrings when the last SMB session is
freed so that cached keys do not keep the module pinned.

> diff --git a/fs/smb/client/cifs_spnego.c b/fs/smb/client/cifs_spnego.c
> index 44c4072756804..939e14e755e52 100644
> --- a/fs/smb/client/cifs_spnego.c
> +++ b/fs/smb/client/cifs_spnego.c
> @@ -190,6 +190,12 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
>  	return spnego_key;
>  }
>  
> +void
> +cifs_spnego_clear_cache(void)
> +{
> +	WARN_ON(keyring_clear(spnego_cred->thread_keyring));
> +}
> +
>  int
>  init_cifs_spnego(void)
>  {
> diff --git a/fs/smb/client/cifsacl.c b/fs/smb/client/cifsacl.c
> index 346899da91eb2..126b976c2547f 100644
> --- a/fs/smb/client/cifsacl.c
> +++ b/fs/smb/client/cifsacl.c
> @@ -539,6 +539,12 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid,
>  	return 0;
>  }
>  
> +void
> +cifs_idmap_clear_cache(void)
> +{
> +	WARN_ON(keyring_clear(root_cred->thread_keyring));
> +}

[Severity: Medium]
As reported by Sashiko on RFC v2 [1], can cifs_spnego_clear_cache() and
cifs_idmap_clear_cache() trigger a WARN_ON() splat (and crash on systems with
panic_on_warn enabled) when memory allocation fails during session teardown?

When sesInfoFree() frees the last session, it calls cifs_idmap_clear_cache()
and cifs_spnego_clear_cache(), which pass the return value of keyring_clear()
directly to WARN_ON().

In security/keys/keyring.c:keyring_clear():

	edit = assoc_array_clear(&keyring->keys, &keyring_assoc_array_ops);
	if (IS_ERR(edit)) {
		ret = PTR_ERR(edit);

And in lib/assoc_array.c:assoc_array_clear(), clearing a non-empty associative
array performs a GFP_KERNEL allocation:

	edit = kzalloc_obj(struct assoc_array_edit);
	if (!edit)
		return ERR_PTR(-ENOMEM);

If this allocation fails under memory pressure, memcg limits, or fault
injection while either keyring contains cached keys, keyring_clear() returns
-ENOMEM and triggers WARN_ON().

Notably, the companion NFSv4 patch in the same series checks the return value
of keyring_clear(), logs with pr_warn_ratelimited(), and skips key_gc_flush()
on failure. Should cifs_idmap_clear_cache() and cifs_spnego_clear_cache()
handle keyring_clear() errors the same way instead of using WARN_ON()?

[ ... ]

> diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c
> index ec28f102ea08a..11c0330be489b 100644
> --- a/fs/smb/client/misc.c
> +++ b/fs/smb/client/misc.c

[ ... ]

> @@ -115,6 +122,14 @@ sesInfoFree(struct cifs_ses *buf_to_free)
>  		kref_put(&iface->refcount, release_iface);
>  	spin_unlock(&buf_to_free->iface_lock);
>  	kfree_sensitive(buf_to_free);
> +
> +	mutex_lock(&cifs_session_mutex);
> +	if (atomic_dec_and_test(&sesInfoAllocCount)) {
> +		cifs_idmap_clear_cache();
> +		cifs_spnego_clear_cache();
> +		key_gc_flush();
> +	}
> +	mutex_unlock(&cifs_session_mutex);
>  }

[Severity: High]
As reported by Sashiko on RFC v2 [2], does calling key_gc_flush() from
sesInfoFree() cause a WQ_MEM_RECLAIM workqueue flush dependency violation when
the final session reference is dropped from a cifsiod_wq worker?

When keyring_clear() unlinks cached keys, it schedules assoc_array_rcu_cleanup
via call_rcu(). Inside security/keys/gc.c:key_gc_flush():

void key_gc_flush(void)
{
	do {
		rcu_barrier();
	} while (flush_work(&key_gc_work));
}

rcu_barrier() runs assoc_array_rcu_cleanup() -> keyring_free_object() ->
key_put(), which schedules key_gc_work on the default system workqueue (which
does not have WQ_MEM_RECLAIM set), and key_gc_flush() then calls
flush_work(&key_gc_work).

In fs/smb/client/cifsfs.c:init_cifs(), cifsiod_wq is allocated with
WQ_MEM_RECLAIM:

	cifsiod_wq = alloc_workqueue("cifsiod",
				     WQ_FREEZABLE | WQ_MEM_RECLAIM | WQ_PERCPU,
				     0);

Because cifs_kill_sb() does not flush cifsiod_wq before calling cifs_umount(),
background work items running on cifsiod_wq can outlive unmount and drop the
last reference to struct cifs_ses, including:

  mchan_mount_work_fn() -> mchan_mount_free() -> cifs_put_smb_ses()
  smb2_reconnect_server() -> cifs_put_tcon() / cifs_put_smb_ses()
  smb2_cancelled_close_fid() -> cifs_put_tcon()
  cifs_ses_oplock_break() -> cifs_put_smb_ses()

When any of those workers drops the final reference, __cifs_put_smb_ses() ->
sesInfoFree() -> key_gc_flush() -> flush_work(&key_gc_work) flushes a
!WQ_MEM_RECLAIM workqueue from a WQ_MEM_RECLAIM worker, triggering WARN_ONCE()
in kernel/workqueue.c:check_flush_dependency() and risking a memory-reclaim
deadlock.

[1] https://lore.kernel.org/r/20261103030226.2685251-6-jarkko@kernel.org
[2] https://lore.kernel.org/r/20261103030226.2685251-6-jarkko@kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261105005311.804098-1-jarkko@kernel.org?part=4

  reply	other threads:[~2026-11-06  0:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  0:52 [RFC PATCH v3 00/11] KEYS: Sanitize the garbage collector Jarkko Sakkinen
2026-11-05  0:53 ` [RFC PATCH v3 01/11] KEYS: Add key_gc_flush() for draining RCU callbacks Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 02/11] dns_resolver: Move the key type into a separate module Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 03/11] NFSv4: Clear idmap keyring cache when the last client unloads Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 04/11] smb: client: Clear idmap/SPNEGO caches when the last session is unloaded Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot [this message]
2026-11-05  0:53 ` [RFC PATCH v3 05/11] s390/cert_store: Start tracking subsystem keys Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 06/11] KEYS: trusted: TEE: Disable sysfs bind attributes Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 07/11] KEYS: trusted: TEE: Synchronize session lifetime Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 08/11] rxrpc: Move key types to their own module Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 09/11] KEYS: Pin the backing kernel module for a key type Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 10/11] KEYS: Remove key_type_dead Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  0:53 ` [RFC PATCH v3 11/11] KEYS: key_garbage_collector(): process in chunks Jarkko Sakkinen
2026-11-06  0:54   ` sashiko-bot
2026-11-05  1:04 ` [RFC PATCH v3 00/11] KEYS: Sanitize the garbage collector Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-200459@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=agordeev@linux.ibm.com \
    --cc=anna@kernel.org \
    --cc=bharathsm@microsoft.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cel@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=jarkko@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=pabeni@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=serge@hallyn.com \
    --cc=sprasad@microsoft.com \
    --cc=sumit.garg@kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox