The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Thiébaud Weksteen" <tweek@google.com>
To: Paul Moore <paul@paul-moore.com>,
	Stephen Smalley <stephen.smalley.work@gmail.com>,
	 Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Jeffrey Vander Stoep <jeffv@google.com>
Cc: "Thiébaud Weksteen" <tweek@google.com>,
	"Ondrej Mosnacek" <omosnace@redhat.com>,
	"Eric Suen" <ericsu@linux.microsoft.com>,
	"Blaise Boscaccy" <bboscaccy@linux.microsoft.com>,
	"Sid Nayyar" <sidnayyar@google.com>,
	"Neill Kapron" <nkapron@google.com>,
	"Eric Biggers" <ebiggers@google.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"KP Singh" <kpsingh@kernel.org>,
	bpf@vger.kernel.org, selinux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next 3/5] selinux: use kernel sid in security_bpf_*
Date: Thu, 13 Aug 2026 10:26:16 +1000	[thread overview]
Message-ID: <20260813002618.3755631-4-tweek@google.com> (raw)
In-Reply-To: <20260813002618.3755631-1-tweek@google.com>

The security_bpf hooks provides a boolean to indicate if the call is
coming from within the kernel or not. If true, use the kernel SID
instead of relying on the current process SID.

For the token-aware functions, the kernel sid is used to decide on the
access, but the caller remains owner of the object (program or map).

Signed-off-by: Thiébaud Weksteen <tweek@google.com>
---
 security/selinux/hooks.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f197cf476190..e7c5993f6954 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -7181,7 +7181,7 @@ static int selinux_ib_alloc_security(void *ib_sec)
 static int selinux_bpf(int cmd, union bpf_attr *attr,
 		       unsigned int size, bool kernel)
 {
-	u32 sid = current_sid();
+	u32 sid = kernel ? SECINITSID_KERNEL : current_sid();
 	int ret;
 
 	if (selinux_policycap_bpf_token_perms())
@@ -7296,7 +7296,7 @@ static int selinux_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
 	bpfsec->sid = current_sid();
 
 	if (!token)
-		ssid = bpfsec->sid;
+		ssid = kernel ? SECINITSID_KERNEL : bpfsec->sid;
 	else
 		ssid = selinux_bpffs_creator_sid(attr->map_token_fd);
 
@@ -7314,7 +7314,7 @@ static int selinux_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
 	bpfsec->sid = current_sid();
 
 	if (!token)
-		ssid = bpfsec->sid;
+		ssid = kernel ? SECINITSID_KERNEL : bpfsec->sid;
 	else
 		ssid = selinux_bpffs_creator_sid(attr->prog_token_fd);
 
-- 
2.55.0.691.gc56d675ccc-goog


  parent reply	other threads:[~2026-08-13  0:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13  0:26 [PATCH bpf-next 0/5] bpf: Introduce LOADER_LOAD_FD Thiébaud Weksteen
2026-08-13  0:26 ` [PATCH bpf-next 1/5] fs/kernel_read_file,selinux: Add BPF_LOADER constant Thiébaud Weksteen
2026-08-13  1:25   ` bot+bpf-ci
2026-08-13  0:26 ` [PATCH bpf-next 2/5] bpf: Introduce BPF_LOADER_LOAD_FD command Thiébaud Weksteen
2026-08-13  1:40   ` bot+bpf-ci
2026-08-13  0:26 ` Thiébaud Weksteen [this message]
2026-08-13  1:25   ` [PATCH bpf-next 3/5] selinux: use kernel sid in security_bpf_* bot+bpf-ci
2026-08-13  0:26 ` [PATCH bpf-next 4/5] selinux: Add BPF_LOADER_LOAD_FD syscall permission Thiébaud Weksteen
2026-08-13  0:26 ` [PATCH bpf-next 5/5] selftests/bpf: add loader_load_fd tests Thiébaud Weksteen
2026-08-13  1:25   ` bot+bpf-ci

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=20260813002618.3755631-4-tweek@google.com \
    --to=tweek@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bboscaccy@linux.microsoft.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=ebiggers@google.com \
    --cc=ericsu@linux.microsoft.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeffv@google.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nkapron@google.com \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --cc=sidnayyar@google.com \
    --cc=stephen.smalley.work@gmail.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