]> git.baikalelectronics.ru Git - kernel.git/commit
selinux: fix context string corruption in convert_context()
authorOndrej Mosnacek <omosnace@redhat.com>
Thu, 3 Oct 2019 13:59:22 +0000 (15:59 +0200)
committerPaul Moore <paul@paul-moore.com>
Thu, 3 Oct 2019 18:13:36 +0000 (14:13 -0400)
commit6f22176a697a691d6f74d80826a9bcfaf8be857d
treee472f908d8afb9593b8858a2bb67e77372b55f81
parent8e9c480d16c46035edf20ed18f2415111f6c898a
selinux: fix context string corruption in convert_context()

string_to_context_struct() may garble the context string, so we need to
copy back the contents again from the old context struct to avoid
storing the corrupted context.

Since string_to_context_struct() tokenizes (and therefore truncates) the
context string and we are later potentially copying it with kstrdup(),
this may eventually cause pieces of uninitialized kernel memory to be
disclosed to userspace (when copying to userspace based on the stored
length and not the null character).

How to reproduce on Fedora and similar:
    # dnf install -y memcached
    # systemctl start memcached
    # semodule -d memcached
    # load_policy
    # load_policy
    # systemctl stop memcached
    # ausearch -m AVC
    type=AVC msg=audit(1570090572.648:313): avc:  denied  { signal } for  pid=1 comm="systemd" scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=process permissive=0 trawcon=73797374656D5F75007400000000000070BE6E847296FFFF726F6D000096FFFF76

Cc: stable@vger.kernel.org
Reported-by: Milos Malik <mmalik@redhat.com>
Fixes: 5d6af24407f1 ("selinux: overhaul sidtab to fix bug and improve performance")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/services.c