Bug 255507 - traceroute6 generates wrong UDP checksum
Summary: traceroute6 generates wrong UDP checksum
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-net (Nobody)
URL: https://reviews.freebsd.org/D30042
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-04-30 08:31 UTC by Zhenlei Huang
Modified: 2021-05-06 15:57 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhenlei Huang 2021-04-30 08:31:29 UTC
Environment: FreeBSD stable/13 host A and FreeBSD host B, connected via router.

This can be reproduced.
Steps to repeat:
1. traceroute6 -nq1 IP6_address_on_host_B
2. On host B, netstat -sp udp | grep 'bad checksum', it shows increasing statistic counter. It can be verified by tcpdump -npvi nic 'ip6 && udp' .


Note:
* If host A is directly connected with host B, then the UDP checksum is correct.
* Some system other then FreeBSD seems not checking UDP checksum before generating ICMP time exceeded, thus to repeat it host B should be FreeBSD system.
Comment 1 Zhenlei Huang 2021-04-30 09:18:49 UTC
I can confirm the regression was introduced in review D25604 .

Proposed patch https://reviews.freebsd.org/D30042
Comment 2 commit-hook freebsd_committer 2021-05-03 17:56:37 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1d712c05370dca8cbf81d1ecd9acd606fdcacaf4

commit 1d712c05370dca8cbf81d1ecd9acd606fdcacaf4
Author:     Zhenlei Huang <zlei.huang@gmail.com>
AuthorDate: 2021-05-03 16:46:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-05-03 17:24:30 +0000

    traceroute6: Properly calculate UDP checksum

    The revision D25604 capsicumize traceroute6. For UDP the send socket was
    changed from SOCK_DGRAM to SOCK_RAW and thus the UDP checksum need be
    calculated by application itself other than the kernel.

    outpacket is filled with zeros by line 707, thus the first round the UDP
    checksum is correct. But subsequent rounds outudp->uh_sum will be left
    with garbage.

    PR:             255507
    Reviewed by:    ae, markj, tuexen
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D30042

 usr.sbin/traceroute6/traceroute6.c | 1 +
 1 file changed, 1 insertion(+)
Comment 3 commit-hook freebsd_committer 2021-05-06 13:00:13 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e183dd501caf03751c96c7c0683ccc3a6c0cd27d

commit e183dd501caf03751c96c7c0683ccc3a6c0cd27d
Author:     Zhenlei Huang <zlei.huang@gmail.com>
AuthorDate: 2021-05-03 16:46:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2021-05-06 12:59:19 +0000

    traceroute6: Properly calculate UDP checksum

    The revision D25604 capsicumize traceroute6. For UDP the send socket was
    changed from SOCK_DGRAM to SOCK_RAW and thus the UDP checksum need be
    calculated by application itself other than the kernel.

    outpacket is filled with zeros by line 707, thus the first round the UDP
    checksum is correct. But subsequent rounds outudp->uh_sum will be left
    with garbage.

    PR:             255507
    Reviewed by:    ae, markj, tuexen
    Differential Revision:  https://reviews.freebsd.org/D30042

    (cherry picked from commit 1d712c05370dca8cbf81d1ecd9acd606fdcacaf4)

 usr.sbin/traceroute6/traceroute6.c | 1 +
 1 file changed, 1 insertion(+)
Comment 4 Mark Johnston freebsd_committer 2021-05-06 15:57:51 UTC
Thanks for the report and patch.