mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 19:34:43 +01:00
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
This commit is contained in:
1 parent
d0f8e31761
commit
ac1750dd14
2 files changed
+16
-21
No files matched your search
+12
-15
@@ -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 */
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user