Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Enzo Matsumiya <ematsumiya@suse.de>
To: linux-cifs@vger.kernel.org
Cc: smfrench@gmail.com, pc@manguebit.com, ronniesahlberg@gmail.com,
	sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
	henrique.carvalho@suse.com, Enzo Matsumiya <ematsumiya@suse.de>
Subject: [PATCH 2/3] cifs.upcall: namespace-aware key authority
Date: Mon, 29 Jun 2026 17:21:44 -0300	[thread overview]
Message-ID: <20260629202145.97856-2-ematsumiya@suse.de> (raw)
In-Reply-To: <20260629202145.97856-1-ematsumiya@suse.de>

spnego key is allocated before switching namespaces (i.e. as root/host
credentials), but instantiation is done only later.

If we have successfully switched user namespaces, key instantiation
returns EPERM because credentials have changed.

Call keyctl_assume_authority() after switching NS/UID/GID so key is
instantiated with correct creds.

Signed-off-by: Enzo Matsumiya <ematsumiya@suse.de>
---
 cifs.upcall.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/cifs.upcall.c b/cifs.upcall.c
index 8a207544cf48..3f56c69cae28 100644
--- a/cifs.upcall.c
+++ b/cifs.upcall.c
@@ -1539,6 +1539,7 @@ int main(const int argc, char *const argv[])
 	krb5_ccache ccache = NULL;
 	unsigned expire_time = DNS_RESOLVER_DEFAULT_TIMEOUT;
 	const char *key_descr = NULL;
+	bool same_ns = true;
 
 	hostbuf[0] = '\0';
 
@@ -1688,6 +1689,7 @@ int main(const int argc, char *const argv[])
 	if (arg->upcall_target == UPTARGET_APP || arg->upcall_target == UPTARGET_UNSPECIFIED) {
 		syslog(LOG_INFO, "upcall_target=app, switching namespaces to application thread");
 		arg->upcall_target = UPTARGET_APP;
+		same_ns = in_same_user_ns(getpid(), arg->pid);
 		rc = switch_to_process_ns(arg->pid);
 		if (rc == -1) {
 			syslog(LOG_ERR, "unable to switch to process namespace: %s", strerror(errno));
@@ -1756,6 +1758,27 @@ int main(const int argc, char *const argv[])
 	if (rc)
 		goto out;
 
+	/*
+	 * Keyring keys' credentials are per user NS.  If we switched user namespaces, we need to
+	 * re-acquire authority (with correct UID/GID) over it so we're able to instantiate it
+	 * later (in setup_key()).
+	 */
+	if (!same_ns) {
+		errno = 0;
+		rc = keyctl_assume_authority(key);
+
+		/*
+		 * EINPROGRESS and ENOENT are non-fatal in most cases.
+		 * keyctl_instantiate() (in setup_key()) will fail if something was really
+		 * unexpected.
+		 */
+		if (rc < 0 && errno != EINPROGRESS && errno != ENOENT) {
+			syslog(LOG_ERR, "keyctl_assume_authority: %s", strerror(errno));
+			rc = 1;
+			goto out;
+		}
+	}
+
 	rc = krb5_init_context(&context);
 	if (rc) {
 		syslog(LOG_ERR, "unable to init krb5 context: %ld", rc);
-- 
2.54.0


  reply	other threads:[~2026-06-29 20:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 20:21 [PATCH 1/3] cifs.upcall: fix regression with krb5 + creduid Enzo Matsumiya
2026-06-29 20:21 ` Enzo Matsumiya [this message]
2026-06-29 20:21 ` [PATCH 3/3] cifs.upcall: add support for different PID namespaces Enzo Matsumiya
2026-06-29 21:05 ` [PATCH 1/3] cifs.upcall: fix regression with krb5 + creduid Paulo Alcantara

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=20260629202145.97856-2-ematsumiya@suse.de \
    --to=ematsumiya@suse.de \
    --cc=bharathsm@microsoft.com \
    --cc=henrique.carvalho@suse.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=pc@manguebit.com \
    --cc=ronniesahlberg@gmail.com \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.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