From nobody Mon Jan 22 18:45:25 2024 X-Original-To: dev-commits-src-branches@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 4TJfKx70Bzz57yx5; Mon, 22 Jan 2024 18:45:25 +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 4TJfKx6L3cz4v2Q; Mon, 22 Jan 2024 18:45:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705949125; 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=3e8e0SqRX+sTEw+ITC4hGuVPCGPT41qVM8XEn5KquHY=; b=DNcQ/9ccbx0u1RkYDgIBX/oQm3LWIhIeyyxBcVkv3AInYa/Szs2u5BkNonZqQXuysyPiJi GJyfAFbYztqYD7x8WzfkFybUNNZihs/naxtvSMbts5xlqVaBOPdGxWTMTFfLG4GW0Q1MY5 N5Cb3IuaENOVwA32twWWNWz8KB2iAWcfQdvT/att5vYcCHL8J5kcCKx2DLgDnnAmt6sOlr /1k8hrCMKD9EhkedEhguMYdrEf1zghYyPj58h9OufrnqKsXi3e9h5LiPRYTmf4rg00FPoY obV12aNrwZWsXp8MkiAwhtTCIJAdrWCL8UBv6MMyT3dl5FPYgRQAy5JgswzdTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705949125; 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=3e8e0SqRX+sTEw+ITC4hGuVPCGPT41qVM8XEn5KquHY=; b=eKJtMdX0umS9UTjorjcb8S9kom5PVrTC4KFmuy7KpXwlujqkS7I9k/lWbApqZmvxjW/qm0 gIdXh0WzfdmIFuznnpnUU8HU/KtQrhcli2J1dEzijLcv9c+RZrQxxIoPjbbRR8BKC1136V t4R7e7jHGmo7xZdMHhUGKSKUEYp46RorpmV1kmvYfzrSTbJ8GBYa7RhGsJUQYy+v0nETC4 SKGRkOacQ6rInpKHyg7myaaIrPu8ssEo9KVJdV6Q7glbK52SboH5QGK77Dt20/DUKEdLZC /c38ZdpsD3d7I+UgyOTKyDniBpueI00gn4NNXkRaBTtnBbScnpMii+wcs4YcBg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705949125; a=rsa-sha256; cv=none; b=gpDRbtVTaUd2jnrK8CeEojy2VAk4MY0dRhvFCsuoOm7mTiffrIak010r0312QzLIVSLApJ d1c0HiwzEZV+jqretPLW5Gy2FjNSgCWOZVocP2BpCtI5kQeR+hnIvQjfvr7eEAI8Q9qslQ ef8gHVdLy62qMBHSHIfWXSZ63NTlm3Fb+lnJLkLiOlztnauCltHgoZxQExKm9zL9OgE2bs U+wH60BCUAJI8qPp3o/q0o/L3yHem5RYSUfg+mRmfTY609Jf0ACsgmZea8dQAcwUx8Eo1m V7vk0JkjDhngD7y1b62UtvnGpXPIpckFpJgdeTATHAUzRboSnbLoe6iWfLrRKw== 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 4TJfKx5NPdz1Cjc; Mon, 22 Jan 2024 18:45:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40MIjPaN042760; Mon, 22 Jan 2024 18:45:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40MIjPNl042757; Mon, 22 Jan 2024 18:45:25 GMT (envelope-from git) Date: Mon, 22 Jan 2024 18:45:25 GMT Message-Id: <202401221845.40MIjPNl042757@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 3e27fcf05793 - stable/13 - inpcb: Remove NULL checks of credential references List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 3e27fcf057937ef93258dc4f8e67a308e02f349c Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3e27fcf057937ef93258dc4f8e67a308e02f349c commit 3e27fcf057937ef93258dc4f8e67a308e02f349c Author: Mark Johnston AuthorDate: 2022-11-02 17:03:41 +0000 Commit: Mark Johnston CommitDate: 2024-01-22 18:45:03 +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 (cherry picked from commit ac1750dd143e53225c518bc1ca0462c3fffe10f6) --- 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 61079db56bdb..3f4ad6752aae 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1154,11 +1154,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; @@ -1203,7 +1204,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; } @@ -1244,7 +1245,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; @@ -1305,7 +1306,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; @@ -1421,8 +1422,7 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, faddr = IA_SIN(CK_STAILQ_FIRST(&V_in_ifaddrhead))->sin_addr; IN_IFADDR_RUNLOCK(&in_ifa_tracker); - 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) { IN_IFADDR_RLOCK(&in_ifa_tracker); @@ -1450,10 +1450,9 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, ifp = imo->imo_multicast_ifp; IN_IFADDR_RLOCK(&in_ifa_tracker); 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) @@ -2006,9 +2005,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); } } @@ -2039,9 +2037,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 a153b06a7435..6d7c1d4b65b5 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -764,9 +764,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); } } @@ -797,9 +796,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)