]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
selinux: refactor mls_context_to_sid() and make it stricter
authorJann Horn <jannh@google.com>
Mon, 6 Aug 2018 21:19:32 +0000 (23:19 +0200)
committerPaul Moore <paul@paul-moore.com>
Wed, 5 Sep 2018 21:47:09 +0000 (17:47 -0400)
commit95ffe194204ae3cef88d0b59be209204bbe9b3be
treea31906d241c0bc898d412423cf97ce8905f0347c
parent7bb185edb0306bb90029a5fa6b9cff900ffdbf4b
selinux: refactor mls_context_to_sid() and make it stricter

The intended behavior change for this patch is to reject any MLS strings
that contain (trailing) garbage if p->mls_enabled is true.

As suggested by Paul Moore, change mls_context_to_sid() so that the two
parts of the range are extracted before the rest of the parsing. Because
now we don't have to scan for two different separators simultaneously
everywhere, we can actually switch to strchr() everywhere instead of the
open-coded loops that scan for two separators at once.

mls_context_to_sid() used to signal how much of the input string was parsed
by updating `*scontext`. However, there is actually no case in which
mls_context_to_sid() only parses a subset of the input and still returns
a success (other than the buggy case with a second '-' in which it
incorrectly claims to have consumed the entire string). Turn `scontext`
into a simple pointer argument and stop redundantly checking whether the
entire input was consumed in string_to_context_struct(). This also lets us
remove the `scontext_len` argument from `string_to_context_struct()`.

Signed-off-by: Jann Horn <jannh@google.com>
[PM: minor merge fuzz in convert_context()]
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/mls.c
security/selinux/ss/mls.h
security/selinux/ss/services.c