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 779423E0224 for ; Tue, 14 Apr 2026 12:11:29 +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=1776168689; cv=none; b=ucTkkYBwtH1sqfzU/ZRDCVWmuWrHXGoBioIFLrj+OHiyuZ/lOLu3+8ntIg+aETUm6G+re4BirvHyhLu5DaHUavkytPGCARHJHjXB6yWBXhmGVZ9FCYzi+/Jwvihe0LgrJKhBeVU826kcQLdlFCbT6Sb+oqc+IzeCbkvouHBcl8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776168689; c=relaxed/simple; bh=gdRZ0gfxmF+yQ4JngZdqQUNOsFnWzE74ZzfaV9LqRHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EZSAwJr5m0P7Kw/ahugO2BYWuwKWyCo5E/ghrapQ7OOQAo6XErqRE/m9ObnYayFql0WrzM3o1DPbwjykX5e/39AVYInrn1Iu/EX5qzpiM8xZdq+Fm3odnxpgJpMnfau4ibW805iiTwvbRcGu92oOuPiYluZd+JdNuR/khVprXes= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B2SL2e3O; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B2SL2e3O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C4B0C2BCB0; Tue, 14 Apr 2026 12:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776168689; bh=gdRZ0gfxmF+yQ4JngZdqQUNOsFnWzE74ZzfaV9LqRHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B2SL2e3Ooow6zvzADgm3KighTQoOcGg3jLskMdc7oVAzNObA7g8nb09dJsBfAb/Ue qEUwMlNC2/LsuzG4l4DOm7kjSPDIaAbjurgS1sgf7MXMv7LeU5fIR/3RLlDXIF0+L5 iB5koCk8NUR0CTcCplczr8VTuRrwyWbek3C/4DQiJKFga9eGwtLggMO9FjSy+Pf4jV 9mGYsuMC7GJAZXZ22OHYht7b8Kh+cyBZICWgDwMhLZqehWT9o+SCiPuqaQfU2nC/D+ 7QywvDDoW+6PvySf+ddlMqWOWbxj8nq+J1zZYaGt89QBfzO150zaWSONty/w4wy9UN tpfSguVMDLfRw== From: Sasha Levin To: stable@vger.kernel.org Cc: Jiayuan Chen , Antonius , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6.y] net: skb: fix cross-cache free of KFENCE-allocated skb head Date: Tue, 14 Apr 2026 08:11:26 -0400 Message-ID: <20260414121126.588364-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026041339-celery-ribbon-dc62@gregkh> References: <2026041339-celery-ribbon-dc62@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jiayuan Chen [ Upstream commit 0f42e3f4fe2a58394e37241d02d9ca6ab7b7d516 ] 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 [ adapted variable names ] Signed-off-by: Sasha Levin --- 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 4c28954f915fa..c81ef99d39b04 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -943,10 +943,7 @@ static bool skb_pp_recycle(struct sk_buff *skb, void *data, bool napi_safe) static void skb_kfree_head(void *head, unsigned int end_offset) { - if (end_offset == SKB_SMALL_HEAD_HEADROOM) - kmem_cache_free(skb_small_head_cache, head); - else - kfree(head); + kfree(head); } static void skb_free_head(struct sk_buff *skb, bool napi_safe) -- 2.53.0