BPF List
 help / color / mirror / Atom feed
From: Paul Houssel <paulhoussel2@gmail.com>
To: paul.houssel@orange.com, "Andrii Nakryiko" <andrii@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Paul Houssel" <paulhoussel2@gmail.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Song Liu" <song@kernel.org>,
	"Martin KaFai Lau" <martin.lau@kernel.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Florian Westphal" <fw@strlen.de>,
	"T.J. Mercier" <tjmercier@google.com>,
	"Li RongQing" <lirongqing@baidu.com>,
	"Paul Chaignon" <paul.chaignon@gmail.com>,
	"D. Wythe" <alibuda@linux.alibaba.com>,
	"Jakub Kicinski" <kuba@kernel.org>
Cc: "Stanislav Fomichev" <sdf@fomichev.me>, bpf@vger.kernel.org
Subject: [PATCH v3 1/2] bpf: render CGROUP_LSM_NUM configurable as a KConfig
Date: Wed,  6 May 2026 17:05:46 +0200	[thread overview]
Message-ID: <20260506150547.767315-2-paulhoussel2@gmail.com> (raw)
In-Reply-To: <20260506150547.767315-1-paulhoussel2@gmail.com>

In include/linux/bpf-cgroup-defs.h, CGROUP_LSM_NUM defines the maximum
number of BPF_PROG_TYPE_LSM programs that can be simultaneously attached
using the `BPF_LSM_CGROUP` attachment type. We set the value to the newly
introduced `CONFIG_CGROUP_LSM_NUM` Kconfig option, allowing users and
distributions to tune this limit at build time rather than relying on a
hardcoded value.

The option ranges from 0 to 300 and defaults to 10, preserving the
existing behaviour. There are currently 273 LSM hooks but this number is
subject to change. I coudn't find a MACRO counting the sum of LSM
interfaces and therefore arbitrarily set the threshold to 300. I am open
to suggestions on how to set this limit dynamically or not.

Signed-off-by: Paul Houssel <paulhoussel2@gmail.com>
---
 include/linux/bpf-cgroup-defs.h |  2 +-
 kernel/bpf/Kconfig              | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/linux/bpf-cgroup-defs.h b/include/linux/bpf-cgroup-defs.h
index c9e6b26abab6..9ab5ca3dbaba 100644
--- a/include/linux/bpf-cgroup-defs.h
+++ b/include/linux/bpf-cgroup-defs.h
@@ -12,7 +12,7 @@ struct bpf_prog_array;
 
 #ifdef CONFIG_BPF_LSM
 /* Maximum number of concurrently attachable per-cgroup LSM hooks. */
-#define CGROUP_LSM_NUM 10
+#define CGROUP_LSM_NUM CONFIG_CGROUP_LSM_NUM
 #else
 #define CGROUP_LSM_NUM 0
 #endif
diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig
index eb3de35734f0..050af0b72651 100644
--- a/kernel/bpf/Kconfig
+++ b/kernel/bpf/Kconfig
@@ -101,4 +101,23 @@ config BPF_LSM
 
 	  If you are unsure how to answer this question, answer N.
 
+config CGROUP_LSM_NUM
+	int "Maximum number of per-cgroup LSM hooks"
+	depends on BPF_LSM
+	depends on CGROUP_BPF
+	range 0 300
+	default 10
+	help
+	  Maximum number of concurrently attachable per-cgroup LSM hooks.
+	  Increasing this value has two memory costs:
+		- 8 bytes per added hook (due to growing
+		cgroup_lsm_atype[] array in kernel/bpf/cgroup.c)
+
+		- 25 bytes per added hook, because each hook adds a value to
+		MAX_CGROUP_BPF_ATTACH_TYPE and thus increases the
+		effective, progs, flags and revisions arrays in struct
+		cgroup_bpf
+
+	  If you are unsure, leave the default value.
+
 endmenu # "BPF subsystem"
-- 
2.54.0


  reply	other threads:[~2026-05-06 15:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 15:05 [PATCH v3 0/2] Introduce CONFIG_CGROUP_LSM_NUM to render BPF_LSM_CGROUP attachment limit configurable Paul Houssel
2026-05-06 15:05 ` Paul Houssel [this message]
2026-05-06 15:52   ` [PATCH v3 1/2] bpf: render CGROUP_LSM_NUM configurable as a KConfig bot+bpf-ci
2026-05-06 16:11     ` Paul Chaignon
2026-05-06 21:08   ` sashiko-bot
2026-05-07 16:39     ` Paul Houssel
2026-05-08 22:16       ` Alexei Starovoitov
2026-05-06 15:05 ` [PATCH v3 2/2] selftests/bpf: add tests to verify the enforcement of CONFIG_CGROUP_LSM_NUM Paul Houssel
2026-05-06 16:05   ` Paul Chaignon
2026-05-06 21:24   ` sashiko-bot
2026-05-06 16:13 ` [PATCH v3 0/2] Introduce CONFIG_CGROUP_LSM_NUM to render BPF_LSM_CGROUP attachment limit configurable Paul Chaignon

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=20260506150547.767315-2-paulhoussel2@gmail.com \
    --to=paulhoussel2@gmail.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=fw@strlen.de \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=martin.lau@kernel.org \
    --cc=paul.chaignon@gmail.com \
    --cc=paul.houssel@orange.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=tjmercier@google.com \
    --cc=yonghong.song@linux.dev \
    /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