Page MenuHomeFreeBSD

tests/sys/kern/procdesc.c: mark grandchild var in pdopenpid_capmode() as volatile
ClosedPublic

Authored by kib on Sun, Aug 30, 11:51 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Sep 22, 8:35 PM
Unknown Object (File)
Mon, Sep 21, 3:50 PM
Unknown Object (File)
Mon, Sep 21, 7:36 AM
Unknown Object (File)
Sun, Sep 20, 7:38 PM
Unknown Object (File)
Sun, Sep 20, 2:51 PM
Unknown Object (File)
Sat, Sep 19, 4:28 AM
Unknown Object (File)
Fri, Sep 18, 10:10 PM
Unknown Object (File)
Thu, Sep 17, 4:46 PM
Subscribers

Details

Summary
The variable is written in the child process which shares the address
space with the parent.  The data flow must not be optimized by a compiler.

Fixes:  ddf62c83fc0a ("sys/tests/kern/pdopenpid: pdopenpid(2) is allowed in cap mode")

Diff Detail

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

Event Timeline

kib requested review of this revision.Sun, Aug 30, 11:51 PM

Why not use atomics?

This revision is now accepted and ready to land.Tue, Sep 1, 1:26 PM

Why not use atomics?

I believe that volatile matches the issue I need to prevent, while atomic is not.
There is no race involved there, the accesses are serialized by the residual _exit() call in the child vs. the wait for P_PPWAIT condition to resume of the execution in the parent.
So the problem is that the grandchild variable could be modified in the way that cannot be deduced from the flow control visible to the compiler, and not a race.

The C23 standard explicitly describes the situation as the subject of the volatile semantic:

An object that has volatile-qualified type may be modified in ways unknown to the implementation
or have other unknown side effects. Therefore, any expression referring to such an object shall be
evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.4. Furthermore,
at every sequence point the value last stored in the object shall agree with that prescribed by the
abstract machine, except as modified by the unknown factors mentioned previously.150) What
constitutes an access to an object that has volatile-qualified type is implementation-defined.