Re: [PATCH] cgroup: pids: use {READ,WRITE}_ONCE for pids->limit operations
From: Aleksa Sarai
Date: Mon Oct 14 2019 - 11:59:51 EST
On 2019-10-14, Tejun Heo <tj@xxxxxxxxxx> wrote:
> On Sat, Oct 12, 2019 at 12:05:39PM +1100, Aleksa Sarai wrote:
> > Because pids->limit can be changed concurrently (but we don't want to
> > take a lock because it would be needlessly expensive), use the
> > appropriate memory barriers.
>
> I can't quite tell what problem it's fixing. Can you elaborate a
> scenario where the current code would break that your patch fixes?
As far as I can tell, not using *_ONCE() here means that if you had a
process changing pids->limit from A to B, a process might be able to
temporarily exceed pids->limit -- because pids->limit accesses are not
protected by mutexes and the C compiler can produce confusing
intermediate values for pids->limit[1].
But this is more of a correctness fix than one fixing an actually
exploitable bug -- given the kernel memory model work, it seems like a
good idea to just use READ_ONCE() and WRITE_ONCE() for shared memory
access.
[1]: https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
Attachment:
signature.asc
Description: PGP signature