Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Apr 2021 06:49:54 GMT
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 6b8c65318e81 - stable/13 - ipdivert: check that PCB is still valid after taking INPCB_RLOCK.
Message-ID:  <202104060649.1366nsHB067855@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by ae:

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

commit 6b8c65318e81a451b33ed57b84a5495284dcb20f
Author:     Andrey V. Elsukov <ae@FreeBSD.org>
AuthorDate: 2021-03-30 09:31:09 +0000
Commit:     Andrey V. Elsukov <ae@FreeBSD.org>
CommitDate: 2021-04-06 06:47:54 +0000

    ipdivert: check that PCB is still valid after taking INPCB_RLOCK.
    
    We are inspecting PCBs of divert sockets under NET_EPOCH section,
    but PCB could be already detached and we should check INP_FREED flag
    when we took INP_RLOCK.
    
    PR:             254478
    Differential Revision:  https://reviews.freebsd.org/D29420
    
    (cherry picked from commit c80a4b76ceacc5aab322e7ac1407eea8c90cb3b1)
---
 sys/netinet/ip_divert.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c
index 65f1d263b5fa..70d3fbd1f230 100644
--- a/sys/netinet/ip_divert.c
+++ b/sys/netinet/ip_divert.c
@@ -280,6 +280,10 @@ divert_packet(struct mbuf *m, bool incoming)
 		/* XXX why does only one socket match? */
 		if (inp->inp_lport == nport) {
 			INP_RLOCK(inp);
+			if (__predict_false(inp->inp_flags2 & INP_FREED)) {
+				INP_RUNLOCK(inp);
+				continue;
+			}
 			sa = inp->inp_socket;
 			SOCKBUF_LOCK(&sa->so_rcv);
 			if (sbappendaddr_locked(&sa->so_rcv,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104060649.1366nsHB067855>