Summary: | in_pcblookup_hash_locked: invalid local address panic on sendto(2) to ipv4-mapped | ||||||
---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Benjamin Jacobs <freebsd> | ||||
Component: | kern | Assignee: | Michael Tuexen <tuexen> | ||||
Status: | Closed FIXED | ||||||
Severity: | Affects Many People | CC: | ae, freebsd, glebius, markj, net, tuexen | ||||
Priority: | --- | Keywords: | crash | ||||
Version: | 14.0-CURRENT | Flags: | tuexen:
mfc-stable14+
|
||||
Hardware: | Any | ||||||
OS: | Any | ||||||
Attachments: |
|
Description
Benjamin Jacobs
2023-09-21 21:52:26 UTC
This problem is also found by syzkaller in https://syzkaller.appspot.com/bug?extid=81ccc423a2737ed031ac. (In reply to Michael Tuexen from comment #1) if that is that the case, so we have to cc markj@? ;) (In reply to Mina Galić from comment #2) I don't think he is responsible for all bug found by syzkaller... You can add him, but I think glebius@ did a lot of improvements in the inp area and he is on the bug. I can take a look. I guess, https://syzkaller.appspot.com/bug?extid=c8e3dac881bba85bc029 is also related. Both seem to be a consequence of not handling mapped addresses correctly. ^Triage: former assignee net@ added to the CC list. Is this the same problem that I tried to fix in https://reviews.freebsd.org/D39215? I lost track of that revision, sorry. Note that there's a test case in D39216. (In reply to Mark Johnston from comment #6) Hi Mark, thanks for the pointers, wasn't aware of it. I'll plan to work on the PR this Friday and will let you know. Best regards Michael (In reply to Mark Johnston from comment #6) I tested your patch in review D39215 and it resolves the issues. However, in other places inp_vflag is modified when using mapped addresses. I have done this dance in review D42031 and it resolves the panic, too. This seems to be consistent. I'm not sure which one is the correct approach. Is the intention of review D39215 than such a inp_vflag is not necessary anymore and can be removed from the other places? (In reply to Mark Johnston from comment #6) Hi, yes it does seem to be that same issue. (In reply to Michael Tuexen from comment #8) My 2 cents: the version flag is indeed tricky because - as noted by Mark in its revision - an AF_INET6 UDP socket can transition back and forth between v4 and v6 (either by using connect() and/or sendto). I'm not sure either that getting rid of it is the right approach because the code ends up having to pass around an extra flag argument all over the place. But there are also some unclear locking rules, as stated in the comment around the in_pcb stuff, which makes the whole concept far from trivial for me to understand :) Nonetheless, I made a patch in a way for me to have something working. But it does seem all very hacky and ugly to carry an argument for "it is actually a v4-mapped" flag to all callers, and callers of callers, of the in_pcb_lport_dest. Also I did not completely understood the implication w.r.t. the handling of wildcard addresses. And possible concurrency issues are likely not addressed. Anyway, that might be of interest to you. Side note: it is trivial to trigger the bug using "sysctl net.inet6.ip6.v6only=0; drill @::ffff:8.8.8.8 freebsd.org" Created attachment 245375 [details]
Adds a flag argument to in_pcb_lport_dest to support v4-mapped
What about adding extra inp_vflag for mapped pcbs? So that in_pcb.c code can tell regular IPv4 inpcb from mapped one? (In reply to Gleb Smirnoff from comment #11) Why? Don't we know the state right now from inp_vflag? We just adapt the value to the usage of the inp. A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=abca3ae7734f664ee9c5edc7a9d3a17e29180bdb commit abca3ae7734f664ee9c5edc7a9d3a17e29180bdb Author: Michael Tuexen <tuexen@FreeBSD.org> AuthorDate: 2023-10-07 13:56:00 +0000 Commit: Michael Tuexen <tuexen@FreeBSD.org> CommitDate: 2023-10-07 13:56:00 +0000 udp: fix sending of IPv4-mapped addresses The inp_vflags field must be adjusted during the call of in_pcbbind_setup(). This is consistent with the other places in the code, but not elegant at all. PR: 274009 Reported by: syzbot+81ccc423a2737ed031ac@syzkaller.appspotmail.com Reported by: syzbot+c8e3dac881bba85bc029@syzkaller.appspotmail.com Reviewed by: markj, rrs, rscheff MFC after: 3 days Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D42031 sys/netinet/udp_usrreq.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8209af15a6994d52276be05380e0c0b7ae117cea commit 8209af15a6994d52276be05380e0c0b7ae117cea Author: Michael Tuexen <tuexen@FreeBSD.org> AuthorDate: 2023-10-07 13:56:00 +0000 Commit: Michael Tuexen <tuexen@FreeBSD.org> CommitDate: 2023-10-13 20:13:44 +0000 udp: fix sending of IPv4-mapped addresses The inp_vflags field must be adjusted during the call of in_pcbbind_setup(). This is consistent with the other places in the code, but not elegant at all. PR: 274009 Reported by: syzbot+81ccc423a2737ed031ac@syzkaller.appspotmail.com Reported by: syzbot+c8e3dac881bba85bc029@syzkaller.appspotmail.com Reviewed by: markj, rrs, rscheff Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D42031 (cherry picked from commit abca3ae7734f664ee9c5edc7a9d3a17e29180bdb) sys/netinet/udp_usrreq.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) A commit in branch releng/14.0 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=f28965bcaa1f7f1bd3d855f5c025daeb445d07a7 commit f28965bcaa1f7f1bd3d855f5c025daeb445d07a7 Author: Michael Tuexen <tuexen@FreeBSD.org> AuthorDate: 2023-10-07 13:56:00 +0000 Commit: Michael Tuexen <tuexen@FreeBSD.org> CommitDate: 2023-10-13 21:29:47 +0000 udp: fix sending of IPv4-mapped addresses The inp_vflags field must be adjusted during the call of in_pcbbind_setup(). This is consistent with the other places in the code, but not elegant at all. PR: 274009 Approved by: re (gjb) Reported by: syzbot+81ccc423a2737ed031ac@syzkaller.appspotmail.com Reported by: syzbot+c8e3dac881bba85bc029@syzkaller.appspotmail.com Reviewed by: markj, rrs, rscheff Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D42031 (cherry picked from commit abca3ae7734f664ee9c5edc7a9d3a17e29180bdb) (cherry picked from commit 8209af15a6994d52276be05380e0c0b7ae117cea) sys/netinet/udp_usrreq.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) |