bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Magnus Karlsson <magnus.karlsson@gmail.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: bpf <bpf@vger.kernel.org>, "Björn Töpel" <bjorn@kernel.org>,
	"Magnus Karlsson" <magnus.karlsson@intel.com>,
	"Jonathan Lemon" <jonathan.lemon@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Maxim Mikityanskiy" <maximmi@mellanox.com>,
	"Network Development" <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf] xsk: fix for xp_aligned_validate_desc() when len == chunk_size
Date: Wed, 28 Apr 2021 11:09:03 +0200	[thread overview]
Message-ID: <fbda6161-41a2-016f-a90f-f3fe5034f200@iogearbox.net> (raw)
In-Reply-To: <CAJ8uoz3fphwV9115NLpOi94w2N0j1Cn3DRJFJ2NvwA91zf+uBw@mail.gmail.com>

On 4/28/21 10:00 AM, Magnus Karlsson wrote:
> On Tue, Apr 27, 2021 at 2:19 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>>
>> When desc->len is equal to chunk_size, it is legal. But
>> xp_aligned_validate_desc() got "chunk_end" by desc->addr + desc->len
>> pointing to the next chunk during the check, which caused the check to
>> fail.
> 
> Thanks Xuan for the fix. Off-by-one error. A classic unfortunately.
> 
> Think your fix also makes it easier to understand the code too, so good.
> 
>> Fixes: 35fcde7f8deb ("xsk: support for Tx")
>> Fixes: bbff2f321a86 ("xsk: new descriptor addressing scheme")
> 
> Just did some quick research and it seems the bug was introduced in
> the bbff2f321a86 commit above, not the first one 35fcde7f8deb. Or am I
> mistaken?
> 
>> Fixes: 2b43470add8c ("xsk: Introduce AF_XDP buffer allocation API")
>> Fixes: 26062b185eee ("xsk: Explicitly inline functions and move definitions")
> 
> And in these two, the code was moved around first to a new function in
> 2b43470add8c, then this function was moved to a new file in
> 26062b185eee. I believe documenting this in your commit message would
> make life simpler for the nice people backporting this fix. Or is this
> implicit in the multiple Fixes tags? Could someone with more
> experience in these things comment please.

Fully agree with Magnus, providing more context in the commit message is
always appreciated. Xuan, please extend and resubmit. Thanks!

> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
> 
>> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>> ---
>>   net/xdp/xsk_queue.h | 7 +++----
>>   1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
>> index 2823b7c3302d..40f359bf2044 100644
>> --- a/net/xdp/xsk_queue.h
>> +++ b/net/xdp/xsk_queue.h
>> @@ -128,13 +128,12 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)
>>   static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
>>                                              struct xdp_desc *desc)
>>   {
>> -       u64 chunk, chunk_end;
>> +       u64 chunk;
>>
>> -       chunk = xp_aligned_extract_addr(pool, desc->addr);
>> -       chunk_end = xp_aligned_extract_addr(pool, desc->addr + desc->len);
>> -       if (chunk != chunk_end)
>> +       if (desc->len > pool->chunk_size)
>>                  return false;
>>
>> +       chunk = xp_aligned_extract_addr(pool, desc->addr);
>>          if (chunk >= pool->addrs_cnt)
>>                  return false;
>>
>> --
>> 2.31.0
>>


      reply	other threads:[~2021-04-28  9:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27 12:19 [PATCH bpf] xsk: fix for xp_aligned_validate_desc() when len == chunk_size Xuan Zhuo
2021-04-28  8:00 ` Magnus Karlsson
2021-04-28  9:09   ` Daniel Borkmann [this message]

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=fbda6161-41a2-016f-a90f-f3fe5034f200@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=magnus.karlsson@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=maximmi@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=yhs@fb.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).