From: David Miller <davem@davemloft.net>
To: matthew@mjdsystems.ca
Cc: netdev@vger.kernel.org, thiago.macieira@intel.com,
willemdebruijn.kernel@gmail.com, pabeni@redhat.com
Subject: Re: [PATCH net v3] datagram: When peeking datagrams with offset < 0 don't skip empty skbs
Date: Fri, 18 Aug 2017 15:13:32 -0700 (PDT) [thread overview]
Message-ID: <20170818.151332.1551388172093785238.davem@davemloft.net> (raw)
In-Reply-To: <20170818190454.7214-1-matthew@mjdsystems.ca>
From: Matthew Dawson <matthew@mjdsystems.ca>
Date: Fri, 18 Aug 2017 15:04:54 -0400
> Due to commit e6afc8ace6dd5cef5e812f26c72579da8806f5ac ("udp: remove
> headers from UDP packets before queueing"), when udp packets are being
> peeked the requested extra offset is always 0 as there is no need to skip
> the udp header. However, when the offset is 0 and the next skb is
> of length 0, it is only returned once. The behaviour can be seen with
> the following python script:
>
> from socket import *;
> f=socket(AF_INET6, SOCK_DGRAM | SOCK_NONBLOCK, 0);
> g=socket(AF_INET6, SOCK_DGRAM | SOCK_NONBLOCK, 0);
> f.bind(('::', 0));
> addr=('::1', f.getsockname()[1]);
> g.sendto(b'', addr)
> g.sendto(b'b', addr)
> print(f.recvfrom(10, MSG_PEEK));
> print(f.recvfrom(10, MSG_PEEK));
>
> Where the expected output should be the empty string twice.
>
> Instead, make sk_peek_offset return negative values, and pass those values
> to __skb_try_recv_datagram/__skb_try_recv_from_queue. If the passed offset
> to __skb_try_recv_from_queue is negative, the checked skb is never skipped.
> __skb_try_recv_from_queue will then ensure the offset is reset back to 0
> if a peek is requested without an offset, unless no packets are found.
>
> Also simplify the if condition in __skb_try_recv_from_queue. If _off is
> greater then 0, and off is greater then or equal to skb->len, then
> (_off || skb->len) must always be true assuming skb->len >= 0 is always
> true.
>
> Also remove a redundant check around a call to sk_peek_offset in af_unix.c,
> as it double checked if MSG_PEEK was set in the flags.
>
> V2:
> - Moved the negative fixup into __skb_try_recv_from_queue, and remove now
> redundant checks
> - Fix peeking in udp{,v6}_recvmsg to report the right value when the
> offset is 0
>
> V3:
> - Marked new branch in __skb_try_recv_from_queue as unlikely.
>
> Signed-off-by: Matthew Dawson <matthew@mjdsystems.ca>
> Acked-by: Willem de Bruijn <willemb@google.com>
Applied and queued up for -stable, thanks.
prev parent reply other threads:[~2017-08-18 22:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-18 19:04 [PATCH net v3] datagram: When peeking datagrams with offset < 0 don't skip empty skbs Matthew Dawson
2017-08-18 22:13 ` David Miller [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=20170818.151332.1551388172093785238.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=matthew@mjdsystems.ca \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=thiago.macieira@intel.com \
--cc=willemdebruijn.kernel@gmail.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