[PATCH bpf-next 0/2] Limit local storage value size to max kmalloc_nolock() allocation

From: Jonathan Bastari Thamrin via B4 Relay

Date: Wed Nov 04 2026 - 06:45:19 EST


BPF local storage elements are allocated using kmalloc_nolock()
but map creation is still allowed with values up to kmalloc()'s
larger limit. BPF_LOCAL_STORAGE_MAX_VALUE_SIZE is changed to be
based on KMALLOC_MAX_CACHE_SIZE instead and maps with larger
values fail on creation with E2BIG. Cgroup storage
(BPF_MAP_TYPE_CGROUP_STORAGE) uses the previous limit since it
allocates with kmalloc().

A selftest is also added to both find the largest task storage
size and test that this value can be stored. It also checks
that the size is at least 4096 to check that the limit isn't too
low.

---
Jonathan Bastari Thamrin (2):
bpf: Limit local storage value size to max kmalloc_nolock() allocation
selftests/bpf: Test local storage max value size

include/linux/bpf_local_storage.h | 10 +--
kernel/bpf/local_storage.c | 13 +++-
.../selftests/bpf/prog_tests/task_local_storage.c | 87 ++++++++++++++++++++++
3 files changed, 103 insertions(+), 7 deletions(-)
---
base-commit: d346f59069676eda84b3313cbd2c2ab21045d3ee
change-id: 20261104-local-storage-max-c3709fcd6fbc

Best regards,
--
Jonathan Bastari Thamrin <thamrinjonathan@xxxxxxxxx>