From patchwork Mon Mar 3 22:24:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blaise Boscaccy X-Patchwork-Id: 13999560 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AA891F0E5B; Mon, 3 Mar 2025 22:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741040678; cv=none; b=hRanXVnesaOZuxFJ13pKinvtDUI59xWjwPaaHx6RV+ji3UwCz9isK0YSqHvlF1GidEo0f8AEWUAiUkXaazGgYE0+SbPatxtL+/IFc+bTMzGwVIWHJYtTVZmYwoisIVt5/Bmj4AdQ8gfM1mU9MYVX0El3SWNn3ob/W/O3bTcgYEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741040678; c=relaxed/simple; bh=SaNxT4G3peWWAdisrKpx0p2x4jH98gYd2FM4Hy56mgQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bkGrgug9AiqqHT6DmsxURFG+7RJivlJ6qOSqJCSIX/a9AgT0pBcuuDpvjB7sFmbtd04cGsOW0d1hSiDCsXEy9+b/jm4w+77vXJG7hx+uV9yve/Jwy0EwDa4I96dvbqG44b70KOfE9ma2oYySMQxm6jKFJVeiIUW6XRk6emIk1s8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=GlKkRPmy; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="GlKkRPmy" Received: from narnia.corp.microsoft.com (unknown [167.220.2.28]) by linux.microsoft.com (Postfix) with ESMTPSA id E91F02110486; Mon, 3 Mar 2025 14:24:25 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E91F02110486 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1741040676; bh=hwTZqZPuxCEL290JXbO8DS7toEDrCkSnLhZ5WPM1hvY=; h=From:To:Subject:Date:From; b=GlKkRPmyU48gE3YpgV7lYsj1NrnTod/1A21ycg8bIS9BQqQOXvAKueBYn2t17yTnX OtucV5CFcLwn+pFpjvJaRtcqjmLuY00VLUofepI1csXB9Lo/jDHzrkf7StuZl9jnCY wd71kpKLDX8SELNDg7wUtCZw6IM1rGtaL3tGbizU= From: Blaise Boscaccy To: Paul Moore , James Morris , "Serge E. Hallyn" , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Stephen Smalley , Ondrej Mosnacek , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, selinux@vger.kernel.org, bboscaccy@linux.microsoft.com Subject: [PATCH 0/1 v3] security: Propagate caller information in bpf hooks Date: Mon, 3 Mar 2025 14:24:03 -0800 Message-ID: <20250303222416.3909228-1-bboscaccy@linux.microsoft.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hello, While trying to implement an eBPF gatekeeper program, we ran into an issue whereas the LSM hooks are missing some relevant data. Certain subcommands passed to the bpf() syscall can be invoked from either the kernel or userspace. Additionally, some fields in the bpf_attr sruct contain pointers, and depending on where the subcommand was invoked, could point to either user or kernel memory. One example of this, is the bpf_prog_load subcommand and it's fd_array. This data is made available and used by the verifier, but not made available to the LSM subsystem. This patchset simply exposes that information to applicable LSM hooks. Change list: - v2 -> v3 - reorder params so that the new boolean flag is the last param - fixup function signatures in bpf selftests - v1 -> v2 - Pass a boolean flag in lieu of bpfptr_t Revisions: - v2 https://lore.kernel.org/bpf/20250228165322.3121535-1-bboscaccy@linux.microsoft.com/ - v1 https://lore.kernel.org/bpf/20250226003055.1654837-1-bboscaccy@linux.microsoft.com/ Blaise Boscaccy (1): security: Propagate caller information in bpf hooks include/linux/lsm_hook_defs.h | 6 +++--- include/linux/security.h | 12 ++++++------ kernel/bpf/syscall.c | 10 +++++----- security/security.c | 15 +++++++++------ security/selinux/hooks.c | 6 +++--- tools/testing/selftests/bpf/progs/rcu_read_lock.c | 3 ++- .../selftests/bpf/progs/test_cgroup1_hierarchy.c | 4 ++-- .../selftests/bpf/progs/test_kfunc_dynptr_param.c | 6 +++--- .../testing/selftests/bpf/progs/test_lookup_key.c | 2 +- .../selftests/bpf/progs/test_ptr_untrusted.c | 2 +- .../selftests/bpf/progs/test_task_under_cgroup.c | 2 +- .../selftests/bpf/progs/test_verify_pkcs7_sig.c | 2 +- 12 files changed, 37 insertions(+), 33 deletions(-)