From nobody Wed Nov 02 17:47:11 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N2Z8b4n4zz4gVnB; Wed, 2 Nov 2022 17:47:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N2Z8b4KcXz41bN; Wed, 2 Nov 2022 17:47:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667411231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=el2oqhyiB3KknKI4R1peev/vmrnbr+2/K8K1R1U76Vk=; b=FODA3+NxoeBn6I0H7IkRXNbABHf4lXV0SOgKklySISoKruu4mq7+ZFB3nfm8ZmeNHpyF3y BW4JBG+YwgKg+Z0VxIig7t/1yApiX8W8NIqr0k+ugrhwj8st/ryY7W/q4QfDxNECReWJvP xBHKB41qYnpWLxmVvgYyEhFHTfcjnwhU3MQ6WMWjqZl/tNGWSheKmYpL80mgUJIEsdsRb8 t8G/7vKvkoJGB4hx/hYV+GdcV+dpt6O4hUOeNdWuSCLe/WtHifBEhEg024ejoytBV7+6++ W5JAbFeb5w0Vrls7/fWe4XJv57xGkSO875TACagRY9jlH7XvqBav24twD/3q1A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4N2Z8b3Rdhz14Tw; Wed, 2 Nov 2022 17:47:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2A2HlBl9022580; Wed, 2 Nov 2022 17:47:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A2HlBqM022579; Wed, 2 Nov 2022 17:47:11 GMT (envelope-from git) Date: Wed, 2 Nov 2022 17:47:11 GMT Message-Id: <202211021747.2A2HlBqM022579@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: ac1750dd143e - main - inpcb: Remove NULL checks of credential references List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ac1750dd143e53225c518bc1ca0462c3fffe10f6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667411231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=el2oqhyiB3KknKI4R1peev/vmrnbr+2/K8K1R1U76Vk=; b=pzLpaU7dRGN/WgL3wSXLZdOihrcD6JrrnkHWSDWz2+yNtSJAXV3HWWx48gFuQooC/aQC/F 2tjQywPaBdavsaevCDintOs+EezT3QO1gNMmYdmaYuUSCPvwNrr7YArQya6qX8YXBpPeS8 cN+gzvKHbX2x+nLotJ2Gt2B4n87nQM1qXd10KP3hfm4AyadXyCpxpVRlnKGqhPegFEh1KB mVnlQhfWFGWeFWtCv+ZDvV53RBkg3Cd5Y6w0nHsSYjuLZ+CVQB5go7CbfW000TIjbWaFPF vfw2XgZWp6uopi8uRUZ0YB19U0ur2lRKXnotDnwED6CxNNq3nj2t5mu46m99JQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667411231; a=rsa-sha256; cv=none; b=w4imRaGYGNpSt+C/7mwchGjwd2vjRbHupsUulN6doVBOZBRCJHQgG2n5VWwLknuRloeP5H z09eKMCVch2hLUy4UFH1ndnkzDhdVVpU5F/d4YkZRRlaBZB9CJVUXZFVAAUlp+bXD+wsZL oxUKoq04K7nAx305nzl/OVakIDck0yeVG7T41e3eRJQ+FvJcrIl3RpUGxCjWaMLL3vlPQQ Ls+KUSpMMRYE8jPWmjwEC00dDPBwDOIRFW64SSHkqCYSya3d/qvZymYzbIMrZEq+9MWiZY L+H3QjMnsBtdP2L7P1S/YptAdFk3wNVQiuXGQrZ26ycPymeZyK8lrtFFiPaQ+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ac1750dd143e53225c518bc1ca0462c3fffe10f6 commit ac1750dd143e53225c518bc1ca0462c3fffe10f6 Author: Mark Johnston AuthorDate: 2022-11-02 17:03:41 +0000 Commit: Mark Johnston CommitDate: 2022-11-02 17:46:24 +0000 inpcb: Remove NULL checks of credential references Some auditing of the code shows that "cred" is never non-NULL in these functions, either because all callers pass a non-NULL reference or because they unconditionally dereference "cred". So, let's simplify the code a bit and remove NULL checks. No functional change intended. Reviewed by: glebius MFC after: 1 week Sponsored by: Modirum MDPay Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37025 --- sys/netinet/in_pcb.c | 27 ++++++++++++--------------- sys/netinet6/in6_pcb.c | 10 ++++------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 95db8f22f1fe..39d147464cfa 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1130,11 +1130,12 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr, NET_EPOCH_ASSERT(); KASSERT(laddr != NULL, ("%s: laddr NULL", __func__)); + /* * Bypass source address selection and use the primary jail IP * if requested. */ - if (cred != NULL && !prison_saddrsel_ip4(cred, laddr)) + if (!prison_saddrsel_ip4(cred, laddr)) return (0); error = 0; @@ -1179,7 +1180,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr, goto done; } - if (cred == NULL || !prison_flag(cred, PR_IP4)) { + if (!prison_flag(cred, PR_IP4)) { laddr->s_addr = ia->ia_addr.sin_addr.s_addr; goto done; } @@ -1220,7 +1221,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr, struct ifnet *ifp; /* If not jailed, use the default returned. */ - if (cred == NULL || !prison_flag(cred, PR_IP4)) { + if (!prison_flag(cred, PR_IP4)) { ia = (struct in_ifaddr *)nh->nh_ifa; laddr->s_addr = ia->ia_addr.sin_addr.s_addr; goto done; @@ -1281,7 +1282,7 @@ in_pcbladdr(struct inpcb *inp, struct in_addr *faddr, struct in_addr *laddr, if (ia == NULL) ia = ifatoia(ifa_ifwithaddr(sintosa(&dst))); - if (cred == NULL || !prison_flag(cred, PR_IP4)) { + if (!prison_flag(cred, PR_IP4)) { if (ia == NULL) { error = ENETUNREACH; goto done; @@ -1392,8 +1393,7 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, if (faddr.s_addr == INADDR_ANY) { faddr = IA_SIN(CK_STAILQ_FIRST(&V_in_ifaddrhead))->sin_addr; - if (cred != NULL && - (error = prison_get_ip4(cred, &faddr)) != 0) + if ((error = prison_get_ip4(cred, &faddr)) != 0) return (error); } else if (faddr.s_addr == (u_long)INADDR_BROADCAST) { if (CK_STAILQ_FIRST(&V_in_ifaddrhead)->ia_ifp->if_flags & @@ -1418,10 +1418,9 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, if (imo->imo_multicast_ifp != NULL) { ifp = imo->imo_multicast_ifp; CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { - if ((ia->ia_ifp == ifp) && - (cred == NULL || + if (ia->ia_ifp == ifp && prison_check_ip4(cred, - &ia->ia_addr.sin_addr) == 0)) + &ia->ia_addr.sin_addr) == 0) break; } if (ia == NULL) @@ -2067,9 +2066,8 @@ in_pcblookup_local(struct inpcbinfo *pcbinfo, struct in_addr laddr, /* * Found? */ - if (cred == NULL || - prison_equal_ip4(cred->cr_prison, - inp->inp_cred->cr_prison)) + if (prison_equal_ip4(cred->cr_prison, + inp->inp_cred->cr_prison)) return (inp); } } @@ -2100,9 +2098,8 @@ in_pcblookup_local(struct inpcbinfo *pcbinfo, struct in_addr laddr, */ CK_LIST_FOREACH(inp, &phd->phd_pcblist, inp_portlist) { wildcard = 0; - if (cred != NULL && - !prison_equal_ip4(inp->inp_cred->cr_prison, - cred->cr_prison)) + if (!prison_equal_ip4(inp->inp_cred->cr_prison, + cred->cr_prison)) continue; #ifdef INET6 /* XXX inp locking */ diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 176a5227c9a1..3a3c4043f749 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -749,9 +749,8 @@ in6_pcblookup_local(struct inpcbinfo *pcbinfo, struct in6_addr *laddr, IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && inp->inp_lport == lport) { /* Found. */ - if (cred == NULL || - prison_equal_ip6(cred->cr_prison, - inp->inp_cred->cr_prison)) + if (prison_equal_ip6(cred->cr_prison, + inp->inp_cred->cr_prison)) return (inp); } } @@ -782,9 +781,8 @@ in6_pcblookup_local(struct inpcbinfo *pcbinfo, struct in6_addr *laddr, */ CK_LIST_FOREACH(inp, &phd->phd_pcblist, inp_portlist) { wildcard = 0; - if (cred != NULL && - !prison_equal_ip6(cred->cr_prison, - inp->inp_cred->cr_prison)) + if (!prison_equal_ip6(cred->cr_prison, + inp->inp_cred->cr_prison)) continue; /* XXX inp locking */ if ((inp->inp_vflag & INP_IPV6) == 0)