From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Chengen Du <chengen.du@canonical.com>, willemdebruijn.kernel@gmail.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, kaber@trash.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v6] af_packet: Handle outgoing VLAN packets without hardware offloading
Date: Sun, 09 Jun 2024 16:21:23 -0400 [thread overview]
Message-ID: <66660ec3f3e22_8dbbb294ed@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <CAPza5qfuNhDbhV9mau9RE=cNKMwGtJcx4pmjkoHNwpfysnw5yw@mail.gmail.com>
Chengen Du wrote:
> Hi,
>
> I would like to provide some additional explanations about the patch.
>
>
> On Sat, Jun 8, 2024 at 10:54 AM Chengen Du <chengen.du@canonical.com> wrote:
> >
> > The issue initially stems from libpcap. The ethertype will be overwritten
> > as the VLAN TPID if the network interface lacks hardware VLAN offloading.
> > In the outbound packet path, if hardware VLAN offloading is unavailable,
> > the VLAN tag is inserted into the payload but then cleared from the sk_buff
> > struct. Consequently, this can lead to a false negative when checking for
> > the presence of a VLAN tag, causing the packet sniffing outcome to lack
> > VLAN tag information (i.e., TCI-TPID). As a result, the packet capturing
> > tool may be unable to parse packets as expected.
> >
> > The TCI-TPID is missing because the prb_fill_vlan_info() function does not
> > modify the tp_vlan_tci/tp_vlan_tpid values, as the information is in the
> > payload and not in the sk_buff struct. The skb_vlan_tag_present() function
> > only checks vlan_all in the sk_buff struct. In cooked mode, the L2 header
> > is stripped, preventing the packet capturing tool from determining the
> > correct TCI-TPID value. Additionally, the protocol in SLL is incorrect,
> > which means the packet capturing tool cannot parse the L3 header correctly.
> >
> > Link: https://github.com/the-tcpdump-group/libpcap/issues/1105
> > Link: https://lore.kernel.org/netdev/20240520070348.26725-1-chengen.du@canonical.com/T/#u
> > Fixes: 393e52e33c6c ("packet: deliver VLAN TCI to userspace")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Chengen Du <chengen.du@canonical.com>
> > ---
> > net/packet/af_packet.c | 57 ++++++++++++++++++++++++++++++++++++++++--
> > 1 file changed, 55 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> > index ea3ebc160e25..8cffbe1f912d 100644
> > --- a/net/packet/af_packet.c
> > +++ b/net/packet/af_packet.c
> > @@ -538,6 +538,43 @@ static void *packet_current_frame(struct packet_sock *po,
> > return packet_lookup_frame(po, rb, rb->head, status);
> > }
> >
> > +static u16 vlan_get_tci(struct sk_buff *skb)
> > +{
> > + struct vlan_hdr vhdr, *vh;
> > + u8 *skb_orig_data = skb->data;
> > + int skb_orig_len = skb->len;
> > +
> > + skb_push(skb, skb->data - skb_mac_header(skb));
> > + vh = skb_header_pointer(skb, ETH_HLEN, sizeof(vhdr), &vhdr);
> > + if (skb_orig_data != skb->data) {
> > + skb->data = skb_orig_data;
> > + skb->len = skb_orig_len;
> > + }
>
>
> The reason for not directly using skb_header_pointer(skb,
> skb_mac_header(skb) + ETH_HLEN, ...) to get the VLAN header is due to
> the check logic in skb_header_pointer. In the SOCK_DGRAM and
> PACKET_OUTGOING scenarios, the offset can be a negative number, which
> causes the check logic (i.e., likely(hlen - offset >= len)) in
> __skb_header_pointer() to not work as expected.
The calculation is still correct?
I think that this is not the first situation where negative offsets
can be given to skb_header_pointer.
> While it is possible to modify __skb_header_pointer() to handle cases
> where the offset is negative, this change could affect a wider range
> of code.
next prev parent reply other threads:[~2024-06-09 20:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 2:53 [PATCH v6] af_packet: Handle outgoing VLAN packets without hardware offloading Chengen Du
2024-06-08 3:07 ` Chengen Du
2024-06-09 20:21 ` Willem de Bruijn [this message]
2024-06-10 15:33 ` Chengen Du
2024-06-10 23:23 ` Willem de Bruijn
2024-06-09 20:19 ` Willem de Bruijn
2024-06-10 15:06 ` Chengen Du
2024-06-10 23:18 ` Willem de Bruijn
2024-06-12 8:47 ` Chengen Du
2024-06-12 14:07 ` Willem de Bruijn
2024-06-13 13:47 ` Chengen Du
2024-06-14 9:39 ` Willem de Bruijn
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=66660ec3f3e22_8dbbb294ed@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=chengen.du@canonical.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kaber@trash.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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