Page MenuHomeFreeBSD

sysvsem: Fix another sequence number wraparound race
ClosedPublic

Authored by markj on Thu, Sep 3, 4:04 PM.
Tags
None
Referenced Files
F174434386: D59347.id185729.diff
Sat, Oct 3, 4:46 AM
F174434381: D59347.id185729.diff
Sat, Oct 3, 4:46 AM
Unknown Object (File)
Fri, Oct 2, 2:52 AM
Unknown Object (File)
Thu, Oct 1, 11:31 AM
Unknown Object (File)
Thu, Oct 1, 9:31 AM
Unknown Object (File)
Thu, Oct 1, 9:31 AM
Unknown Object (File)
Thu, Oct 1, 9:28 AM
Unknown Object (File)
Thu, Oct 1, 9:25 AM

Details

Summary

semop() may sleep waiting for a semaphore. Upon waking up, it checks to
see if the set's sequence number has changed, indicating that the set
was removed. The sequence number is not wide enough to prevent a false
negative due to wraparound, in which case the subsequent access of
semakptr->u.__sem_base[sopptr->sem_num] may be out of bounds. This
race can be leveraged into privilege escalation.

I think the proper fix would be to add a wider sequence number to struct
semid_kernel. However, this would change the layout and so break
applications which define _WANT_SYSVSEM_INTERNALS.

Instead, simply re-validate the set size upon waking up. Move MAC and
permission checks into the loop as well. This still permits false
negatives, but I don't see how we can do better without changing the
ABI.

While here, use semvalid() instead of open-coding its implementation,
convert a couple of flags to be bool, and use a better variable name to
store required permissions.

Reported by: Reo Shiseki
Reported by: Andrew Griffiths

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj held this revision as a draft.
markj changed the visibility from "Public (No Login Required)" to "Subscribers".Thu, Sep 3, 4:04 PM
markj changed the edit policy from "All Users" to "Subscribers".
markj added reviewers: kib, jhb, brooks, secteam.
markj removed subscribers: imp, olce.
markj added subscribers: kib, jhb, brooks, secteam.
markj published this revision for review.Thu, Sep 3, 4:06 PM

Or, the wider seq number array might be added in parallel to the sema array.

markj planned changes to this revision.Fri, Sep 4, 1:13 AM
In D59347#1361768, @kib wrote:

Or, the wider seq number array might be added in parallel to the sema array.

Indeed, I didn't think of that...

New approach: provide an array of 64-bit sequence numbers in parallel with
the main semaphore set array.

This revision is now accepted and ready to land.Mon, Sep 7, 7:16 PM
markj changed the visibility from "Subscribers" to "Public (No Login Required)".Tue, Sep 29, 4:13 PM
markj changed the edit policy from "Subscribers" to "All Users".