All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 2/5] selinux: restore the context string on -ESTALE retry
@ 2026-11-09 15:37 Christian Göttsche
  2026-11-09 15:37 ` [PATCH v2 3/5] selinux: prevent stale AVC insertions after policy changes Christian Göttsche
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Christian Göttsche @ 2026-11-09 15:37 UTC (permalink / raw)
  To: selinux
  Cc: Paul Moore, Stephen Smalley, Ondrej Mosnacek,
	Christian Göttsche

From: Christian Göttsche <cgzones@googlemail.com>

security_context_to_sid_core() retries the conversion when
sidtab_context_to_sid() returns -ESTALE because a policy reload froze
the sidtab in the meantime.  The retry passes scontext2 to
string_to_context_struct() again, but that function mutates its input:
it replaces the ':' separators with NUL bytes while parsing.  On the
second pass the user field is followed by a NUL instead of a ':', so the
parse fails with -EINVAL for any context, including a perfectly valid
one.

Without force this makes the caller see -EINVAL for a valid context.
With force the (pristine) saved copy gets stored as an uninterpreted,
unmapped context, so a valid context is treated as unlabeled until the
next policy reload.

Restore scontext2 from the caller's buffer before retrying, as
services_convert_context() already does for the same reason.  The
buffer was allocated by kmemdup_nul() with scontext_len + 1 bytes and
the parser never writes past the terminating NUL, so copying
scontext_len bytes restores it exactly.

Fixes: 9ad6e9cb39c6 ("selinux: fix race between old and new sidtab")
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
---
 security/selinux/ss/services.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index a6e4bf262a9e..b1987367e8b0 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1614,6 +1614,8 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
 			context.str = NULL;
 		}
 		context_destroy(&context);
+		/* string_to_context_struct() mutated scontext2, restore it */
+		memcpy(scontext2, scontext, scontext_len);
 		goto retry;
 	}
 	context_destroy(&context);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-09 17:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 15:37 [PATCH v2 2/5] selinux: restore the context string on -ESTALE retry Christian Göttsche
2026-11-09 15:37 ` [PATCH v2 3/5] selinux: prevent stale AVC insertions after policy changes Christian Göttsche
2026-11-09 15:46   ` sashiko-bot
2026-11-09 15:38 ` [PATCH v2 4/5] selinux: keep pending boolean values across policy loads Christian Göttsche
2026-11-09 15:44   ` sashiko-bot
2026-11-09 15:38 ` [PATCH v2 5/5] selinux: do not cache permissive grants after enabling enforcing mode Christian Göttsche
2026-11-09 15:46   ` sashiko-bot
2026-11-09 15:38 ` [PATCH v2 1/5] selinux: zero-initialize permission name array in masked av dump Christian Göttsche
2026-11-09 15:42   ` sashiko-bot
2026-11-09 17:53   ` Stephen Smalley
2026-11-09 15:43 ` [PATCH v2 2/5] selinux: restore the context string on -ESTALE retry sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.