Page MenuHomeFreeBSD

sys/rpc: UNIX auth: Fix OOB accesses, notably writes on decode
ClosedPublic

Authored by olce on Tue, Oct 7, 5:14 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 5:32 PM
Unknown Object (File)
Fri, Oct 10, 5:32 PM
Unknown Object (File)
Fri, Oct 10, 12:23 PM
Unknown Object (File)
Fri, Oct 10, 8:28 AM
Unknown Object (File)
Wed, Oct 8, 12:02 PM
Unknown Object (File)
Wed, Oct 8, 6:25 AM
Unknown Object (File)
Wed, Oct 8, 6:07 AM
Unknown Object (File)
Wed, Oct 8, 6:06 AM
Subscribers

Details

Summary

When the received authentication message had more than XU_NGROUPS, we
would write group IDs beyond the end of cr_groups[] in the 'struct
xucred' being filled (as 'ngroups_max' is always greater than
XU_NGROUPS).

For robustness, prevent various OOB accesses that would result from
changes of values of XU_NGROUPS and AUTH_SYS_MAX_GROUPS or a 'struct
xucred' with an invalid 'cr_ngroups' field, even if these cases are
unlikely.

Diff Detail

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

Event Timeline

olce requested review of this revision.Tue, Oct 7, 5:14 PM

Looks ok to me. I'll leave min vs MIN up to you.

sys/rpc/authunix_prot.c
131

Technically, min() compares int and not uint32_t.
It should be ok, but this is why I prefer to use the
MIN() macro that doesn't care about types.

I'll leave it up to you as to whether or not you change it.

This revision is now accepted and ready to land.Sun, Oct 12, 11:50 PM
olce marked an inline comment as done.Mon, Oct 13, 1:01 PM

Looks ok to me. I'll leave min vs MIN up to you.

Changing to MIN(). Yes, MIN() has the advantage that it works regardless of the type, but also the disadvantage that the expressions to compare are expanded twice, which can create useless work or cause side-effects to happen multiple times. I'm pretty sure it doesn't matter in this case, as there's no side-effect and the expressions simple enough for the compiler to be able to factor them out. We could actually have the best of both worlds by changing the definition of MIN(), making use of some GNU extensions, but I don't know if that would be acceptable in sys/param.h. Something for later.

sys/rpc/authunix_prot.c
131

min() takes u_int, not int. It's imin() that takes int.

The day where an architecture with an unsigned int different than uint32_t has yet to come. :-) But I agree with you that we should preferably use a function with the exact type here, even if there's no practical consequence. Please see also the main comment.

olce marked an inline comment as done.Mon, Oct 13, 3:11 PM

Looks ok to me. I'll leave min vs MIN up to you.

Changing to MIN(). Yes, MIN() has the advantage that it works regardless of the type, but also the disadvantage that the expressions to compare are expanded twice, which can create useless work or cause side-effects to happen multiple times. I'm pretty sure it doesn't matter in this case, as there's no side-effect and the expressions simple enough for the compiler to be able to factor them out. We could actually have the best of both worlds by changing the definition of MIN(), making use of some GNU extensions, but I don't know if that would be acceptable in sys/param.h. Something for later.

No need for gnu extensions. MIN is a poster child for _Generic.