From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 3EF985A027B for ; Fri, 16 Feb 2024 15:54:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708095283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a7TrWH2TpnshPmf7TsxYt1gqSDfuW2aJ+6vXAw9CW08=; b=N/DBH7v9Bb0ziMmX/uTS98Kjpsuu+9WePUkjEoojEpDXMln//fbfADm2LUL+5LSxiI+Cxc ml+30ZVv9HfL/TfoMshWOEsz/sxSDyid2d41QRs6JFKi2YBNdZOuZyBWpNqCqsQHmX3O6p +p+ktg6/971OwCY4WhQorahIPI8hcYk= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-bPd0g2yLMqCzMRFPVNwfVw-1; Fri, 16 Feb 2024 09:54:41 -0500 X-MC-Unique: bPd0g2yLMqCzMRFPVNwfVw-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-563f8cf9f56so299201a12.1 for ; Fri, 16 Feb 2024 06:54:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708095279; x=1708700079; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=a7TrWH2TpnshPmf7TsxYt1gqSDfuW2aJ+6vXAw9CW08=; b=jJZZiyT8MrDHBF+1A33mnKWbJpz6kAOOgzuhGRA9C+1mIgFW+fU3P6Teus5Dmx8x90 DBNmNFbl4++CPKzuq45Y4auFj75rTwTZa2zFiZ1crU9vlabH87iXtsCUNOCLRElrmenR NELVVM8CVYUWL0owFpOyRL1a4zaJp7BGMk4YK0JJwQmWUHhzN7wu5twHlhpJLHYMlcDP rLVZ5uUS9cv8EDWSHJRvcYo1fS+vO2YsXttJkHab8M39iBkXRgxM+djOeEukVTB57EPx C2N034rsopy45bjpJVhZ0SGeiShkaSOkrjBlEaklzjsUd5D1LRy9VixSgJYvteem4u0d 03PQ== X-Gm-Message-State: AOJu0YzmnvALuFxdB21+78lIQ7Fo9PT3sHj14IFwHKlb74VxZit0oX8X 8yKb9nbuOYLzB6A6g6jN2xR/Hy2Xrn11GKcxbQYlCUB24txaxiblZ1F9f19jAuufPheHrjAWQqP l3V0yRheqjEGKyEgtpkUwkXdJ3bRIoGUxZAxrDniho9YSpLeuhF0QDgu/KcuP4JGpf+OfeLFfo2 Yee6kS52VjfLxMePUHFGH7ayFwRlYGydZ1JQM= X-Received: by 2002:aa7:d148:0:b0:563:c54e:f7 with SMTP id r8-20020aa7d148000000b00563c54e00f7mr2940458edo.17.1708095279102; Fri, 16 Feb 2024 06:54:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8sSRnapBjLfh2q1OEMisolmIgSoQq15NZbtNqQjVMe2DEYu8uKPtEYYdApL42nIae7nPt1A== X-Received: by 2002:aa7:d148:0:b0:563:c54e:f7 with SMTP id r8-20020aa7d148000000b00563c54e00f7mr2940444edo.17.1708095278662; Fri, 16 Feb 2024 06:54:38 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id q3-20020a056402248300b0056213094d7bsm45443eda.69.2024.02.16.06.54.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2024 06:54:38 -0800 (PST) Date: Fri, 16 Feb 2024 15:54:00 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v2 6/8] checksum: use csum_ip4_header() in udp.c and tcp.c Message-ID: <20240216155400.1d26ae17@elisabeth> In-Reply-To: <53d4a403-0d3f-4aa0-b980-27c2026a468b@redhat.com> References: <20240214085628.210783-1-lvivier@redhat.com> <20240214085628.210783-7-lvivier@redhat.com> <20240216100805.040826b3@elisabeth> <53d4a403-0d3f-4aa0-b980-27c2026a468b@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SL72FO7C3YK2LQGQFFLDHTUUAB3CM7M3 X-Message-ID-Hash: SL72FO7C3YK2LQGQFFLDHTUUAB3CM7M3 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 16 Feb 2024 15:17:13 +0100 Laurent Vivier wrote: > On 2/16/24 10:08, Stefano Brivio wrote: > > On Wed, 14 Feb 2024 09:56:26 +0100 > > Laurent Vivier 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