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
F170594919: D59282.id185462.diff
Sat, Sep 5, 1:48 PM
F170561957: D59282.diff
Sat, Sep 5, 10:23 AM
F170499544: D59282.id185563.diff
Sat, Sep 5, 3:01 AM
F170494428: D59282.id185462.diff
Sat, Sep 5, 2:25 AM
F170483044: D59282.diff
Sat, Sep 5, 1:05 AM
F170464806: D59282.diff
Fri, Sep 4, 11:06 PM
Unknown Object (File)
Fri, Sep 4, 6:47 PM
Unknown Object (File)
Fri, Sep 4, 5:26 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 Skipped
Unit
Tests Skipped

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.