Page MenuHomeFreeBSD

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

Authored by markj on Fri, Mar 14, 12:39 AM.

Details

Reviewers
glebius
zlei
rrs
Group Reviewers
transport
Summary

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.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 62939
Build 59823: arc lint + arc unit

Event Timeline

IMHO, EINVAL would be better than 0. These are quite non-standard sysctls, that use new value as argument. If actually someone uses them incorrectly, better error than return OK.

Those sysctl handlers copy in a pair of sockaddr_in[6] ( pointed by req->newptr) and copy out the xucred, so what's the point of a NULL req->newptr ? Maybe an error EINVAL is better than 0 ?

Ahh @glebius responses faster than me.

It's probably ok to return EINVAL. I was a bit worried that doing so would result in errors from sysctl -a (which is how I found these bugs in the first place), but I think it's ok. Will update.

This revision is now accepted and ready to land.Fri, Mar 14, 12:01 PM

It's probably ok to return EINVAL. I was a bit worried that doing so would result in errors from sysctl -a (which is how I found these bugs in the first place), but I think it's ok. Will update.

No worries. All these sysctl knobs are marked with flag CTLTYPE_OPAQUE, and as per sysctl(8),

-a           List all the currently available values except for those
                  which are opaque or excluded from listing via the
                  CTLFLAG_SKIP flag.  This option is ignored if one or more
                  variable names are specified on the command line.

They should be excluded from sysctl -a.

It's probably ok to return EINVAL. I was a bit worried that doing so would result in errors from sysctl -a (which is how I found these bugs in the first place), but I think it's ok. Will update.

No worries. All these sysctl knobs are marked with flag CTLTYPE_OPAQUE, and as per sysctl(8),

-a           List all the currently available values except for those
                  which are opaque or excluded from listing via the
                  CTLFLAG_SKIP flag.  This option is ignored if one or more
                  variable names are specified on the command line.

They should be excluded from sysctl -a.

Sure, sysctl -ao then. :)

From reading sysctl.c, I believe no error will be printed in this case, but I still need to check.

btw, do you know which programs use this API?

This revision now requires review to proceed.Mon, Mar 17, 7:58 AM
This revision is now accepted and ready to land.Mon, Mar 17, 6:03 PM