RE: [PATCH 01/15] sched: convert sighand_struct.count to refcount_t
From: Reshetova, Elena
Date: Mon Oct 23 2017 - 06:22:24 EST
> On Fri, 20 Oct 2017, Elena Reshetova wrote:
>
> > atomic_t variables are currently used to implement reference
> > counters with the following properties:
> > - counter is initialized to 1 using atomic_set()
> > - a resource is freed upon counter reaching zero
> > - once counter reaches zero, its further
> > increments aren't allowed
> > - counter schema uses basic atomic operations
> > (set, inc, inc_not_zero, dec_and_test, etc.)
> >
> > Such atomic variables should be converted to a newly provided
> > refcount_t type and API that prevents accidental counter overflows
> > and underflows. This is important since overflows and underflows
> > can lead to use-after-free situation and be exploitable.
> >
> > The variable sighand_struct.count is used as pure reference counter.
>
> This still does not mention that atomic_t != recfcount_t ordering wise and
> why you think that this does not matter in that use case.
>
>
> And looking deeper:
>
> > @@ -1381,7 +1381,7 @@ static int copy_sighand(unsigned long clone_flags,
> struct task_struct *tsk)
> > struct sighand_struct *sig;
> >
> > if (clone_flags & CLONE_SIGHAND) {
> > - atomic_inc(¤t->sighand->count);
> > + refcount_inc(¤t->sighand->count);
> > return 0;
>
> > void __cleanup_sighand(struct sighand_struct *sighand)
> > {
> > - if (atomic_dec_and_test(&sighand->count)) {
> > + if (refcount_dec_and_test(&sighand->count)) {
>
> How did you make sure that these atomic operations have no other
> serialization effect and can be replaced with refcount?
What serialization effects? Are you taking about smth else than memory
ordering?
For memory ordering my current hope is that we can just make refcount_t
to use same strict atomic primitives and then it would not make any difference.
I think this would be the simplest way for everyone since I think even some maintainers
are having issues understanding all the implications of "relaxed" ordering.
Best Regards,
Elena
>
> I complained about that before and Peter explained it to you in great
> length, but you just resend the same thing again. Where is the correctness
> analysis? Seriously, for this kind of stuff it's not sufficient to use a
> coccinelle script and copy boiler plate change logs and be done with it.
>
> Thanks,
>
> tglx