skbuff: Introduce slab_build_skb()
Subsystems (5)
PATCH v2 1/1 skbuff: Introduce slab_build_skb()
syzkaller reported:
BUG: KASAN: slab-out-of-bounds in __build_skb_around+0x235/0x340 net/core/skbuff.c:294 Write of size 32 at addr ffff88802aa172c0 by task syz-executor413/5295
For bpf_prog_test_run_skb(), which uses a kmalloc()ed buffer passed to build_skb().
When build_skb() is passed a frag_size of 0, it means the buffer came from kmalloc. In these cases, ksize() is used to find its actual size, but since the allocation may not have been made to that size, actually perform the krealloc() call so that all the associated buffer size checking will be correctly notified. Split this logic out into a new interface, slab_build_skb(), but leave the original 0 checking for now to catch any stragglers.
---
Is this what you had in mind for this kind of change?
v2: introduce separate helper (kuba)
v1: https://lore.kernel.org/netdev/[email protected]/
--- drivers/net/ethernet/broadcom/bnx2.c | 2 +- drivers/net/ethernet/qlogic/qed/qed_ll2.c | 2 +- include/linux/skbuff.h | 1 + net/bpf/test_run.c | 2 +- net/core/skbuff.c | 52 +++++++++++++++++++++-- 5 files changed, 52 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnx2.c +1 -1
@@ -3045,7 +3045,7 @@ bnx2_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u8 *data,dma_unmap_single (&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,DMA_FROM_DEVICE ); - skb =build_skb (data,0 ); + skb =slab_build_skb (data);if (!skb) {kfree (data); goto error;
drivers/net/ethernet/qlogic/qed/qed_ll2.c +1 -1
@@ -200,7 +200,7 @@ static void qed_ll2b_complete_rx_packet(void *cxt,dma_unmap_single (&cdev->pdev->dev, buffer->phys_addr, cdev->ll2->rx_size,DMA_FROM_DEVICE ); - skb =build_skb (buffer->data,0 ); + skb =slab_build_skb (buffer->data);if (!skb) {DP_INFO (cdev,"Failed to build SKB\n" );kfree (buffer->data);
include/linux/skbuff.h +1 -0
@@ -1253,6 +1253,7 @@ struct sk_buff *build_skb_around(struct sk_buff *skb,void skb_attempt_defer_free (struct sk_buff *skb);struct sk_buff *napi_build_skb (void *data,unsigned int frag_size); +struct sk_buff *slab_build_skb (void *data);/** * alloc_skb - allocate a network buffer
net/bpf/test_run.c +1 -1
@@ -1130,7 +1130,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, }sock_init_data (NULL , sk); - skb =build_skb (data,0 ); + skb =slab_build_skb (data);if (!skb) {kfree (data);kfree (ctx);
net/core/skbuff.c +48 -4
66 lines not on this page · raw message
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 1 line · On Wed, 7 Dec 2022 16:02:13 -0800 Kees Cook wrote:
Is this what you had in mind for this kind of change?
nice, thanks a lot!
the only thing left to do is kdoc updates:
- the existing kdocs should no longer mention frag_size == 0
- kdoc on the slab_build_skb() should say:
/* build_skb() variant which can operate on slab buffers.
* Note that this should be used sparingly as slab buffers
* cannot be combined efficiently by GRO!
*/
But this can all be done by us in a follow up, there's probably more cleaning we can do in those kdocs.
Quoted 2 lines
v2: introduce separate helper (kuba)
v1: https://lore.kernel.org/netdev/[email protected]/