Page MenuHomeFreeBSD

sysvsem: Fix another sequence number wraparound race
ClosedPublic

Authored by markj on Thu, Sep 3, 4:04 PM.
Tags
None
Referenced Files
F174221204: D59347.id188011.diff
Thu, Oct 1, 11:31 AM
F174209652: D59347.id185716.diff
Thu, Oct 1, 9:31 AM
F174209651: D59347.id185717.diff
Thu, Oct 1, 9:31 AM
F174209326: D59347.id186154.diff
Thu, Oct 1, 9:28 AM
F174209047: D59347.diff
Thu, Oct 1, 9:25 AM
Unknown Object (File)
Wed, Sep 30, 11:10 AM
Unknown Object (File)
Wed, Sep 30, 11:10 AM
Unknown Object (File)
Wed, Sep 30, 10:51 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".