From: Stefano Brivio <sbrivio@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 6/8] checksum: use csum_ip4_header() in udp.c and tcp.c
Date: Fri, 16 Feb 2024 15:54:00 +0100 [thread overview]
Message-ID: <20240216155400.1d26ae17@elisabeth> (raw)
In-Reply-To: <53d4a403-0d3f-4aa0-b980-27c2026a468b@redhat.com>
On Fri, 16 Feb 2024 15:17:13 +0100
Laurent Vivier <lvivier@redhat.com> wrote:
> On 2/16/24 10:08, Stefano Brivio wrote:
> > On Wed, 14 Feb 2024 09:56:26 +0100
> > Laurent Vivier <lvivier@redhat.com> wrote:
> >
> >> ...
> >> /**
> >> * udp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addresses
> >> * @eth_d: Ethernet destination address, NULL if unchanged
> >> @@ -579,6 +562,9 @@ static void udp_splice_sendfrom(const struct ctx *c, unsigned start, unsigned n,
> >> *
> >> * Return: size of tap frame with headers
> >> */
> >> +#pragma GCC diagnostic push
> >> +/* ignore unaligned pointer value warning for &b->iph */
> >> +#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
> >> static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport,
> >> const struct timespec *now)
> >> {
> >> @@ -614,13 +600,14 @@ static size_t udp_update_hdr4(const struct ctx *c, int n, in_port_t dstport,
> >> b->iph.saddr = b->s_in.sin_addr.s_addr;
> >> }
> >>
> >> - udp_update_check4(b);
> >> + b->iph.check = csum_ip4_header(&b->iph);
> > Similar comment as I had on v1: I don't think this is safe.
> >
> > If &b->iph is, say, 0x2000, it's all fine: when csum_ip4_header() needs
> > to access, say, ip4h->tot_len, it will dereference 0x2000 and look at
> > 16 bits, 2 bytes into it.
> >
> > If &b->iph is 0x2001, though, csum_ip4_header() will dereference 0x2001
> > and, on some architectures, boom.
>
> I don't understand how &b->iph cannot be aligned as b should be aligned and b is defined
> using udp4_l2_buf_t structure with _attribute__ ((packed, aligned(__alignof__(unsigned
> int)))).
That's because of the size of struct tap_hdr (18 bytes). On, at least,
x86_64, armhf, and i686:
$ pahole passt
[...]
struct udp4_l2_buf_t {
struct sockaddr_in s_in; /* 0 16 */
struct tap_hdr taph; /* 16 18 */
struct iphdr iph; /* 34 20 */
[...]
...we could align the start of 'taph' by adding 2 bytes of padding before
it, note that the size of struct sockaddr_in doesn't depend on the
architecture. But then you can't dereference 'taph', which is probably
even worse.
--
Stefano
next prev parent reply other threads:[~2024-02-16 14:54 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 8:56 [PATCH v2 0/8] Add vhost-user support to passt (part 1) Laurent Vivier
2024-02-14 8:56 ` [PATCH v2 1/8] iov: add some functions to manage iovec Laurent Vivier
2024-02-15 0:24 ` David Gibson
2024-02-15 0:32 ` David Gibson
2024-02-16 5:29 ` Stefano Brivio
2024-02-14 8:56 ` [PATCH v2 2/8] pcap: add pcap_iov() Laurent Vivier
2024-02-15 0:35 ` David Gibson
2024-02-16 5:30 ` Stefano Brivio
2024-02-14 8:56 ` [PATCH v2 3/8] checksum: align buffers Laurent Vivier
2024-02-15 0:40 ` David Gibson
2024-02-14 8:56 ` [PATCH v2 4/8] checksum: add csum_iov() Laurent Vivier
2024-02-15 0:44 ` David Gibson
2024-02-14 8:56 ` [PATCH v2 5/8] util: move IP stuff from util.[ch] to ip.[ch] Laurent Vivier
2024-02-15 2:29 ` David Gibson
2024-02-14 8:56 ` [PATCH v2 6/8] checksum: use csum_ip4_header() in udp.c and tcp.c Laurent Vivier
2024-02-15 2:51 ` David Gibson
2024-02-16 9:08 ` Stefano Brivio
2024-02-16 14:17 ` Laurent Vivier
2024-02-16 14:54 ` Stefano Brivio [this message]
2024-02-16 18:05 ` Laurent Vivier
2024-02-16 18:24 ` Stefano Brivio
2024-02-17 14:22 ` Laurent Vivier
2024-02-17 14:37 ` Stefano Brivio
2024-02-19 2:06 ` David Gibson
2024-02-14 8:56 ` [PATCH v2 7/8] checksum: introduce functions to compute the header part checksum for TCP/UDP Laurent Vivier
2024-02-15 3:12 ` David Gibson
2024-02-14 8:56 ` [PATCH v2 8/8] tap: make tap_update_mac() generic Laurent Vivier
2024-02-15 3:13 ` David Gibson
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=20240216155400.1d26ae17@elisabeth \
--to=sbrivio@redhat.com \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).