selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Smalley <stephen.smalley.work@gmail.com>
To: Rahul Sandhu <nvraxn@gmail.com>
Cc: selinux@vger.kernel.org
Subject: Re: Clarification on kernel threads
Date: Mon, 15 Sep 2025 08:16:30 -0400	[thread overview]
Message-ID: <CAEjxPJ4zChtBRmdXr0a7tY3W1DD7BeeDuHzMmE-e6J_u0ivZeQ@mail.gmail.com> (raw)
In-Reply-To: <DCS9NCJ1SZ91.12BXMI96H1ZHW@gmail.com>

On Sun, Sep 14, 2025 at 1:16 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> Hey,
>
> SELinux has the sid kernel, which when used e.g. as following:
> (sidcontext kernel (sys.id sys.role kernel.subj sys.lowlow))
>
> But what privilege level (ring) do kernel threads run in? I can't find
> much clarification, and if a kernel thread runs in ring 0, then SELinux
> isn't of much use at all then given that the thread has complete access
> to both the processor and memory no?

Prior to the introduction of the userspace_initial_context policy
capability (and still true unless it is enabled in your policy and a
separate context is defined for the init SID), the first userspace
task inherited the kernel SID and remained in it until it loads policy
and re-exec's /sbin/init or switches to the init context. The same is
true of usermode helpers. So restricting the kernel SID could be used
to control such tasks before they exec or switch to another context.

SELinux can't protect against errant behavior by actual kernel
threads, as you note, but labeling kernel threads can be used to
protect such threads from unintended accesses, e.g. to prevent them
from exec'ing a userspace program via the usual kernel functions for
execve which apply the SELinux checks, or from reading/writing
untrusted files via the usual kernel functions for reading/writing
which apply the SELinux checks. An actively malicious kernel thread
can obviously bypass those checks altogether (or change the policy to
allow them), but protecting kernel threads from untrusted executables
and files can be useful to defend their integrity.

      reply	other threads:[~2025-09-15 12:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-14  5:15 Clarification on kernel threads Rahul Sandhu
2025-09-15 12:16 ` Stephen Smalley [this message]

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=CAEjxPJ4zChtBRmdXr0a7tY3W1DD7BeeDuHzMmE-e6J_u0ivZeQ@mail.gmail.com \
    --to=stephen.smalley.work@gmail.com \
    --cc=nvraxn@gmail.com \
    --cc=selinux@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).