From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Kal Conley <kal.conley@dectris.com>
Cc: "Björn Töpel" <bjorn@kernel.org>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
"Jonathan Lemon" <jonathan.lemon@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xsk: Add missing overflow check in xdp_umem_reg
Date: Wed, 8 Mar 2023 16:33:46 +0100 [thread overview]
Message-ID: <4ddd3fe4-ed3c-495e-077c-1ac737488084@intel.com> (raw)
In-Reply-To: <20230308105130.1113833-1-kal.conley@dectris.com>
From: Kal Conley <kal.conley@dectris.com>
Date: Wed, 8 Mar 2023 11:51:30 +0100
> [PATCH] xsk: Add missing overflow check in xdp_umem_reg
You need to mark it properly. It must've been
[PATCH bpf v2] xsk: Add missing overflow check in xdp_umem_reg
instead.
> The number of chunks can overflow u32. Make sure to return -EINVAL on
> overflow.
I'd mention here that cast removal, so that reviewers wouldn't ask why
you did this.
>
> Fixes: bbff2f321a86 ("xsk: new descriptor addressing scheme")
> Signed-off-by: Kal Conley <kal.conley@dectris.com>
> ---
> net/xdp/xdp_umem.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
> index 4681e8e8ad94..02207e852d79 100644
> --- a/net/xdp/xdp_umem.c
> +++ b/net/xdp/xdp_umem.c
> @@ -150,10 +150,11 @@ static int xdp_umem_account_pages(struct xdp_umem *umem)
>
> static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
> {
> - u32 npgs_rem, chunk_size = mr->chunk_size, headroom = mr->headroom;
> bool unaligned_chunks = mr->flags & XDP_UMEM_UNALIGNED_CHUNK_FLAG;
> - u64 npgs, addr = mr->addr, size = mr->len;
> - unsigned int chunks, chunks_rem;
> + u32 chunk_size = mr->chunk_size, headroom = mr->headroom;
> + u64 addr = mr->addr, size = mr->len;
> + u32 chunks_rem, npgs_rem;
> + u64 chunks, npgs;
> int err;
>
> if (chunk_size < XDP_UMEM_MIN_CHUNK_SIZE || chunk_size > PAGE_SIZE) {
> @@ -188,8 +189,8 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
> if (npgs > U32_MAX)
> return -EINVAL;
>
> - chunks = (unsigned int)div_u64_rem(size, chunk_size, &chunks_rem);
> - if (chunks == 0)
> + chunks = div_u64_rem(size, chunk_size, &chunks_rem);
> + if (!chunks || chunks > U32_MAX)
> return -EINVAL;
>
> if (!unaligned_chunks && chunks_rem)
> @@ -202,7 +203,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
> umem->headroom = headroom;
> umem->chunk_size = chunk_size;
> umem->chunks = chunks;
> - umem->npgs = (u32)npgs;
> + umem->npgs = npgs;
> umem->pgs = NULL;
> umem->user = NULL;
> umem->flags = mr->flags;
The code is fine to me.
Please resubmit with the fixed subject and expanded commit message.
I'd also prefer that you sent v3 as a separate mail, *not* as a reply to
this thread.
Thanks,
Olek
next prev parent reply other threads:[~2023-03-08 15:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 17:23 Kal Conley
2023-03-07 17:47 ` Alexander Lobakin
2023-03-07 18:58 ` Kal Cutter Conley
2023-03-08 13:32 ` Alexander Lobakin
2023-03-08 10:51 ` Kal Conley
2023-03-08 15:33 ` Alexander Lobakin [this message]
2023-03-08 18:49 ` Kal Cutter Conley
2023-03-09 16:30 ` 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=4ddd3fe4-ed3c-495e-077c-1ac737488084@intel.com \
--to=aleksander.lobakin@intel.com \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jonathan.lemon@gmail.com \
--cc=kal.conley@dectris.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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®