net: isolate SKB data area allocations
Subsystems (4)
v2 cover net: isolate SKB data area allocations
This is a rather simple series that attempts to address a possible exploitation avenue - the allocation of skbs around the network stack, which frequently get user-controlled contents. Found while doing some amateur exploitation analysis for some other issue, elsewhere.
Patch 0 is a precursor patch that adds a slab allocation helper, patch 1 does the actual bucketing.
v2:
- Pick up A-b, R-b tags (thanks everyone!)
- Cover kmalloc_pfmemalloc as well (Harry)
Pedro Falcato (2):
mm/slab: add a node-track-caller variant for kmem buckets allocation
net: skb: isolate skb data area allocations into a separate bucket
include/linux/slab.h | 7 +++++-- net/core/skbuff.c | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-)
Signature · 1 line
2.54.0
PATCH v2 1/2 mm/slab: add a node-track-caller variant for kmem buckets allocation
This is required by users that want to use kmem buckets, but still desire specifying the NUMA node.
--- include/linux/slab.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/slab.h +5 -2
@@ -1153,8 +1153,11 @@ void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);#define kmem_buckets_alloc (_b, _size, _flags) \ alloc_hooks(__kmalloc_node_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, NUMA_NO_NODE)) -#define kmem_buckets_alloc_track_caller (_b, _size, _flags) \ - alloc_hooks(__kmalloc_node_track_caller_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, NUMA_NO_NODE, _RET_IP_)) +#define kmem_buckets_alloc_node_track_caller (_b, _size, _flags, _node) \ + alloc_hooks(__kmalloc_node_track_caller_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, _node, _RET_IP_)) + +#define kmem_buckets_alloc_track_caller (_b, _size, _flags) \ + kmem_buckets_alloc_node_track_caller(_b, _size, _flags, NUMA_NO_NODE) static __always_inline __alloc_size(1) void *_kmalloc_node_noprof(size_t size, gfp_t flags, int node, kmalloc_token_t token) {
Signature · 1 line
2.54.0
PATCH v2 2/2 net: skb: isolate skb data area allocations into a separate bucket
In reply to Pedro FalcatoSKB data area allocations (as done from alloc_skb()) use kmalloc(). These allocations can be variably sized and their contents can be more or less controlled from userspace, which makes them useful for attackers that want to overwrite a use-after-free'd object from the same kmalloc slab (which often just requires the sizes to roughly match into the same kmalloc bucket). [0] is an easy example of an exploit that uses netlink skb allocation to target another similarly-sized accidentally freed object.
While other mitigations like CONFIG_RANDOM_KMALLOC_CACHES exist, these are probabilistic. Use the existing kmem buckets API to further isolate these allocations in a guaranteed fashion, when CONFIG_SLAB_BUCKETS=y.
--- net/core/skbuff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/core/skbuff.c +6 -2
@@ -584,6 +584,8 @@ struct sk_buff *napi_build_skb(void *data, unsigned int frag_size) }EXPORT_SYMBOL (napi_build_skb); +static kmem_buckets *skb_data_buckets__ro_after_init ; +static void *kmalloc_pfmemalloc (size_t obj_size,gfp_t flags,int node) {if (!gfp_pfmemalloc_allowed (flags))
@@ -591,7 +593,8 @@ static void *kmalloc_pfmemalloc(size_t obj_size, gfp_t flags, int node)if (!obj_size)return kmem_cache_alloc_node (net_hotdata.skb_small_head_cache, flags, node); -return kmalloc_node_track_caller (obj_size, flags, node); +return kmem_buckets_alloc_node_track_caller (skb_data_buckets, obj_size, + flags, node); }/*
@@ -632,7 +635,7 @@ static void *kmalloc_reserve(unsigned int *size, gfp_t flags, int node,* Try a regular allocation, when that fails and we're not entitled * to the reserves, fail. */ - obj =kmalloc_node_track_caller (obj_size, + obj =kmem_buckets_alloc_node_track_caller (skb_data_buckets, obj_size, flags | __GFP_NOMEMALLOC | __GFP_NOWARN, node);if (likely (obj))
@@ -5213,6 +5216,7 @@ void __init skb_init(void)0 ,SKB_SMALL_HEAD_HEADROOM , NULL); + skb_data_buckets =kmem_buckets_create ("skb_data" ,SLAB_PANIC ,0 ,INT_MAX ,NULL );skb_extensions_init (); }
Signature · 1 line
2.54.0
Jakub Kicinski
maintainerQuoted 1 line · On Thu, 11 Jun 2026 13:46:40 +0100 Pedro Falcato wrote:
Subject: [PATCH net-next v2 0/2] net: isolate SKB data area allocations
This doesn't apply to net-next, does patch 2 not apply to mm? If neither tree can take both - maybe MM can take the first patch by itself and we will queue patch 2 after the changes propagate during the merge window?
Vlastimil Babka (SUSE)
maintainerQuoted 5 lines · Jakub Kicinski
Quoted 1 line · On Thu, 11 Jun 2026 13:46:40 +0100 Pedro Falcato wrote:
Subject: [PATCH net-next v2 0/2] net: isolate SKB data area allocations
This doesn't apply to net-next, does patch 2 not apply to mm? If neither tree can take both - maybe MM can take the first patch by
OK I'll take the first patch through the slab tree in the planned second next week's PR.
Quoted 2 lines
itself and we will queue patch 2 after the changes propagate during the merge window?
Quoted 5 lines · Vlastimil Babka (SUSE)
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Thu, 11 Jun 2026 13:46:40 +0100 Pedro Falcato wrote:
Subject: [PATCH net-next v2 0/2] net: isolate SKB data area allocations
This doesn't apply to net-next, does patch 2 not apply to mm?
Ugh, annoying - really should have rebased on net-next precisely (vs just linux-next).
Quoted 4 lines
Quoted 1 line
If neither tree can take both - maybe MM can take the first patch by
OK I'll take the first patch through the slab tree in the planned second next week's PR.
Thanks!
Quoted 4 lines
Quoted 3 lines
itself and we will queue patch 2 after the changes propagate during the merge window?
It's all the same to me, I'll have to resubmit the patches when the merge window closes. So whatever is easier on the maintainers side sounds good to me :)
Signature · 1 line
Pedro