From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 832132727E2; Mon, 13 Apr 2026 16:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776096805; cv=none; b=LjS7J/yhbEw/kYwGZp8tMlZzwhNeC70QUsMuiql2b1cjGFCviLCf95KG9N77s6LgIKnWG3E8wGwJyNdzYgRvrlXcBUTwdNidzfcwk0goi2b31xSzYr+k649p0bq8H0gNmITlKe5GL7tgx7qW3SOiEXV7cm54dvUDn1eXXhUrDvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776096805; c=relaxed/simple; bh=HR4WGOHO4h78dKoLwnAlfbPQUzkoLu/7Iewlq67UjHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cQKzwRo3wmX68lvEpsEcD/O1Ac5pz0fdR9BiEvmz+xQHOvFa69ig0ZEoRZ3lpiheJVCxcc1YLJ4iAzxJ5TC948Jn/norxPxKJQtYMJZr8ErsDlowNcofeRbW+HUyC2gmK4n11BfjurtjLhE+QOCkQPkv/Z1rcIRHVfYj3KTNRdE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CLj8SEgE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CLj8SEgE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19ADCC2BCAF; Mon, 13 Apr 2026 16:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776096805; bh=HR4WGOHO4h78dKoLwnAlfbPQUzkoLu/7Iewlq67UjHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLj8SEgEC1lYKBgNHQ6eJhnmhQtDO1eclN6n6X3Hfriayq2XWfuTcvk8RX+dA9AJg FxxIgDrRkJgFgbCM5YDRp/k18yhVtK72G+zcS6HAzkJsRyRyLbtwt9FlRCWURd0A48 E4wGQdcvbkDEn2CghFiwjel89Bn+GhPo27vyIiGg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Antonius , Jiayuan Chen , Eric Dumazet , Jakub Kicinski Subject: [PATCH 6.12 69/70] net: skb: fix cross-cache free of KFENCE-allocated skb head Date: Mon, 13 Apr 2026 18:01:04 +0200 Message-ID: <20260413155730.752968421@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155728.181580293@linuxfoundation.org> References: <20260413155728.181580293@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiayuan Chen commit 0f42e3f4fe2a58394e37241d02d9ca6ab7b7d516 upstream. 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 Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20260403014517.142550-1-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/skbuff.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1072,10 +1072,7 @@ static int skb_pp_frag_ref(struct sk_buf 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)