netinet: Fix getcred sysctl handlers to do nothing if no input is given

These routines were all assuming that the sysctl handler has some new
value, but this is not the case.  SYSCTL_IN() returns 0 in this
scenario, so they were all operating on an uninitialized address.  This
is mostly harmless, but trips KMSAN checks, so let's fix them.

Reviewed by:	zlei, rrs, glebius
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D49348

(cherry picked from commit 3ff865c6a7948b2cfc01d7056c619145b696700a)
This commit is contained in:
Mark Johnston 2025-03-20 01:33:44 +00:00 committed by Franco Fichtner
parent e0b3614769
commit 801c84ae95
5 changed files with 12 additions and 1 deletions

View file

@ -361,8 +361,9 @@ sctp_getcred(SYSCTL_HANDLER_ARGS)
/* FIX, for non-bsd is this right? */
vrf_id = SCTP_DEFAULT_VRFID;
if (req->newptr == NULL)
return (EINVAL);
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
return (error);

View file

@ -2751,6 +2751,8 @@ tcp_getcred(SYSCTL_HANDLER_ARGS)
struct inpcb *inp;
int error;
if (req->newptr == NULL)
return (EINVAL);
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
return (error);
@ -2793,6 +2795,8 @@ tcp6_getcred(SYSCTL_HANDLER_ARGS)
int mapped = 0;
#endif
if (req->newptr == NULL)
return (EINVAL);
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
return (error);

View file

@ -820,6 +820,8 @@ udp_getcred(SYSCTL_HANDLER_ARGS)
struct inpcb *inp;
int error;
if (req->newptr == NULL)
return (EINVAL);
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
return (error);

View file

@ -375,6 +375,8 @@ sctp6_getcred(SYSCTL_HANDLER_ARGS)
vrf_id = SCTP_DEFAULT_VRFID;
if (req->newptr == NULL)
return (EINVAL);
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
return (error);

View file

@ -609,6 +609,8 @@ udp6_getcred(SYSCTL_HANDLER_ARGS)
struct inpcb *inp;
int error;
if (req->newptr == NULL)
return (EINVAL);
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
return (error);