mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ilia Gavrilov <Ilia.Gavrilov@infotecs.ru>
To: Alexander Lobakin <aleksander.lobakin@intel.com>,
	Magnus Karlsson <magnus.karlsson@intel.com>
Cc: Song Yoong Siang <yoong.siang.song@intel.com>,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	"Stanislav Fomichev" <sdf@fomichev.me>,
	Simon Horman <horms@kernel.org>, Jakub Kicinski <kuba@kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>
Subject: Re: [lvc-project] [PATCH net v2] xsk: Fix overflow in descriptor validation
Date: Wed, 15 Oct 2025 08:12:20 +0000	[thread overview]
Message-ID: <9e946bb9-2629-485e-ae89-5aa8c4930a4d@infotecs.ru> (raw)
In-Reply-To: <20251007140645.3199133-1-Ilia.Gavrilov@infotecs.ru>

On 10/7/25 17:06, Ilia Gavrilov wrote:
> The desc->len value can be set up to U32_MAX. If umem tx_metadata_len
> option is also set, the value of the expression
> 'desc->len + pool->tx_metadata_len' can overflow and validation
> of the incorrect descriptor will be successfully passed.
> This can lead to a subsequent chain of arithmetic overflows
> in the xsk_build_skb() function and incorrect sk_buff allocation.
> 
> To reproduce the overflow, this piece of userspace code can be used:
>        struct xdp_umem_reg umem_reg;
>        umem_reg.addr = (__u64)(void *)umem;
>        ...
>        umem_reg.chunk_size = 4096;
>        umem_reg.tx_metadata_len = 16;
>        umem_reg.flags = XDP_UMEM_TX_METADATA_LEN;
>        setsockopt(sfd, SOL_XDP, XDP_UMEM_REG, &umem_reg, sizeof(umem_reg));
>        ...
> 
>        xsk_ring_prod__reserve(tq, batch_size, &idx);
> 
>        for (i = 0; i < nr_packets; ++i) {
>                struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(tq, idx + i);
>                tx_desc->addr = packets[i].addr;
>                tx_desc->addr += umem->tx_metadata_len;
>                tx_desc->options = XDP_TX_METADATA;
>                tx_desc->len = UINT32_MAX;
>        }
> 
>        xsk_ring_prod__submit(tq, nr_packets);
>        ...
>        sendto(sfd, NULL, 0, MSG_DONTWAIT, NULL, 0);
> 
> Found by InfoTeCS on behalf of Linux Verification Center
> (linuxtesting.org) with SVACE.
> 
> Fixes: 341ac980eab9 ("xsk: Support tx_metadata_len")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ilia Gavrilov <Ilia.Gavrilov@infotecs.ru>
> ---
> v2: Add a repro
>  net/xdp/xsk_queue.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
> index f16f390370dc..b206a8839b39 100644
> --- a/net/xdp/xsk_queue.h
> +++ b/net/xdp/xsk_queue.h
> @@ -144,7 +144,7 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
>  					    struct xdp_desc *desc)
>  {
>  	u64 addr = desc->addr - pool->tx_metadata_len;
> -	u64 len = desc->len + pool->tx_metadata_len;
> +	u64 len = (u64)desc->len + pool->tx_metadata_len;
>  	u64 offset = addr & (pool->chunk_size - 1);
>  
>  	if (!desc->len)
> @@ -165,7 +165,7 @@ static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool,
>  					      struct xdp_desc *desc)
>  {
>  	u64 addr = xp_unaligned_add_offset_to_addr(desc->addr) - pool->tx_metadata_len;
> -	u64 len = desc->len + pool->tx_metadata_len;
> +	u64 len = (u64)desc->len + pool->tx_metadata_len;
>  
>  	if (!desc->len)
>  		return false;

Hi, Alexander, Magnus!

I'm sorry to bother you.
Will this patch be applied or rejected?

  reply	other threads:[~2025-10-15  8:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07 14:06 Ilia Gavrilov
2025-10-15  8:12 ` Ilia Gavrilov [this message]
2025-10-15 10:25   ` [lvc-project] " Alexander Lobakin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e946bb9-2629-485e-ae89-5aa8c4930a4d@infotecs.ru \
    --to=ilia.gavrilov@infotecs.ru \
    --cc=aleksander.lobakin@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=stable@vger.kernel.org \
    --cc=yoong.siang.song@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®