From: Martin KaFai Lau <martin.lau@linux.dev>
To: Andrew Kanner <andrew.kanner@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org,
netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com,
syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com,
bjorn@kernel.org, magnus.karlsson@intel.com,
maciej.fijalkowski@intel.com, jonathan.lemon@gmail.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, aleksander.lobakin@intel.com,
xuanzhuo@linux.alibaba.com, ast@kernel.org, hawk@kernel.org,
john.fastabend@gmail.com, daniel@iogearbox.net
Subject: Re: [PATCH bpf v3] net/xdp: fix zero-size allocation warning in xskq_create()
Date: Fri, 6 Oct 2023 16:58:18 -0700 [thread overview]
Message-ID: <eb61966f-8666-80f6-1eab-c89bffe496b8@linux.dev> (raw)
In-Reply-To: <6520971d.a70a0220.758e3.8cf7@mx.google.com>
On 10/6/23 4:24 PM, Andrew Kanner wrote:
>> Thanks for the explanation, so iiuc it means it will overflow the
>> struct_size() first because of the is_power_of_2(nentries) requirement?
>> Could you help adding some comment to explain? Thanks.
>>
> The overflow happens because there's no upper limit for nentries
> (userspace input). Let me add more context, e.g. from net/xdp/xsk.c:
>
> static int xsk_setsockopt(struct socket *sock, int level, int optname,
> sockptr_t optval, unsigned int optlen)
> {
> [...]
> if (copy_from_sockptr(&entries, optval, sizeof(entries)))
> return -EFAULT;
> [...]
> err = xsk_init_queue(entries, q, false);
> [...]
> }
>
> 'entries' is passed to xsk_init_queue() and there're 2 checks: for 0
> and is_power_of_2() only, no upper bound check:
>
> static int xsk_init_queue(u32 entries, struct xsk_queue **queue,
> bool umem_queue)
> {
> struct xsk_queue *q;
>
> if (entries == 0 || *queue || !is_power_of_2(entries))
> return -EINVAL;
>
> q = xskq_create(entries, umem_queue);
> if (!q)
> return -ENOMEM;
> [...]
> }
>
> The 'entries' value is next passed to struct_size() in
> net/xdp/xsk_queue.c. If it's large enough - SIZE_MAX will be returned.
All make sense. I was mostly asking to add a comment at the "if (unlikely(size
== SIZE_MAX)" check to explain this details on why checking SIZE_MAX is enough.
next prev parent reply other threads:[~2023-10-06 23:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-05 19:35 [PATCH bpf v3] net/xdp: fix zero-size allocation warning in xskq_create() Andrew Kanner
2023-10-06 0:40 ` patchwork-bot+netdevbpf
2023-10-06 1:00 ` Martin KaFai Lau
2023-10-06 7:09 ` Andrew Kanner
2023-10-06 17:37 ` Martin KaFai Lau
2023-10-06 23:24 ` Andrew Kanner
2023-10-06 23:58 ` Martin KaFai Lau [this message]
2023-10-07 6:56 ` Andrew Kanner
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=eb61966f-8666-80f6-1eab-c89bffe496b8@linux.dev \
--to=martin.lau@linux.dev \
--cc=aleksander.lobakin@intel.com \
--cc=andrew.kanner@gmail.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=kuba@kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.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 \
--cc=syzbot+b132693e925cbbd89e26@syzkaller.appspotmail.com \
--cc=syzbot+fae676d3cf469331fc89@syzkaller.appspotmail.com \
--cc=xuanzhuo@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).