From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D216B346FBC for ; Fri, 3 Apr 2026 01:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775180740; cv=none; b=lfEtonSB2yGFdeXT2+KReB7oy5cja8iSCtPK68v7UBV+VhyeDscXFkv38EWFffAA3lcsp0BY1r5VuAA5ppYRCKJLwJicI0kJffV7BwhJWib8nKpGZexSR3glWb7DBefHdrlg6+yLzUnaMvz3FH62Hiw1e2MT3UIrkYIElZy1MKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775180740; c=relaxed/simple; bh=P7suTYjdTKQFqNxGneXVP9C7pxbbBFOIaA279vTubs8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cDOyyUFbTV1aSyOSXc4Ayq0zo9LbtGUgw2H7nPUDVNNvzkjU+tCYtPMcWx/uofu9I6yqLNmcwdSEtzIpn3d/lwwWvvaQNFwn1uj2JGwpzsYfECEjWZ/fr0bBnulU+tgBfun+DoUWYkZNfXriBzCrOcyvgDd6+QWlfGnicJTTovM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QxDcrfcP; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QxDcrfcP" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775180726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=umW2Vm01x/TtS9j0msR8qy2xrPc+F174PwIyfAFMorQ=; b=QxDcrfcPnIwYZ+GkdvLAm3cr2R9PYFBnYWL2dyWoeVQZkhJiYBLYTPfsJp4ldkqO0pNq/D OZVqumFAqp7ZyLQ/dG6oKCHoeC8nmT0jk8EKZE8LXdaQMwJGuAiaxaq5EZLEnF+TIUWl9N bL6LVwwVlyUYxevFnI8fPRSJrvT+nqY= From: Jiayuan Chen To: netdev@vger.kernel.org Cc: Jiayuan Chen , Antonius , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jason Xing , Kuniyuki Iwashima , Michal Luczaj , Mina Almasry , Eric Biggers , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexander Duyck , Soheil Hassas Yeganeh , linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH net v2] net: skb: fix cross-cache free of KFENCE-allocated skb head Date: Fri, 3 Apr 2026 09:45:12 +0800 Message-ID: <20260403014517.142550-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT SKB_SMALL_HEAD_CACHE_SIZE is intentionally set to a non-power-of-2 value (e.g. 704 on x86_64) to avoid collisions with generic kmalloc bucket sizes. This ensures that skb_kfree_head() can reliably use skb_end_offset to distinguish skb heads allocated from skb_small_head_cache vs. generic kmalloc caches. However, when KFENCE is enabled, kfence_ksize() returns the exact requested allocation size instead of the slab bucket size. If a caller (e.g. bpf_test_init) allocates skb head data via kzalloc() and the requested size happens to equal SKB_SMALL_HEAD_CACHE_SIZE, then slab_build_skb() -> ksize() returns that exact value. After subtracting skb_shared_info overhead, skb_end_offset ends up matching SKB_SMALL_HEAD_HEADROOM, causing skb_kfree_head() to incorrectly free the object to skb_small_head_cache instead of back to the original kmalloc cache, resulting in a slab cross-cache free: kmem_cache_free(skbuff_small_head): Wrong slab cache. Expected skbuff_small_head but got kmalloc-1k Fix this by always calling kfree(head) in skb_kfree_head(). This keeps the free path generic and avoids allocator-specific misclassification for KFENCE objects. Fixes: bf9f1baa279f ("net: add dedicated kmem_cache for typical/small skb->head") Reported-by: Antonius Closes: https://lore.kernel.org/netdev/CAK8a0jxC5L5N7hq-DT2_NhUyjBxrPocoiDazzsBk4TGgT1r4-A@mail.gmail.com/ Signed-off-by: Jiayuan Chen --- v1->v2: https://lore.kernel.org/netdev/20260402033138.388574-1-jiayuan.chen@linux.dev/ - switch skb_kfree_head() to plain kfree(head) --- net/core/skbuff.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 0e217041958a..43ee86dcf2ea 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1083,10 +1083,7 @@ static int skb_pp_frag_ref(struct sk_buff *skb) static void skb_kfree_head(void *head, unsigned int end_offset) { - if (end_offset == SKB_SMALL_HEAD_HEADROOM) - kmem_cache_free(net_hotdata.skb_small_head_cache, head); - else - kfree(head); + kfree(head); } static void skb_free_head(struct sk_buff *skb) -- 2.43.0