[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191009113535.GC2359@hirez.programming.kicks-ass.net>
Date: Wed, 9 Oct 2019 13:35:35 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Will Deacon <will@...nel.org>
Cc: linux-kernel@...r.kernel.org, Kees Cook <keescook@...omium.org>,
Ingo Molnar <mingo@...nel.org>,
Elena Reshetova <elena.reshetova@...el.com>,
Ard Biesheuvel <ard.biesheuvel@...aro.org>,
Hanjun Guo <guohanjun@...wei.com>,
Jan Glauber <jglauber@...vell.com>
Subject: Re: [PATCH v3 05/10] lib/refcount: Improve performance of generic
REFCOUNT_FULL code
On Wed, Oct 09, 2019 at 11:25:08AM +0200, Peter Zijlstra wrote:
> On Mon, Oct 07, 2019 at 04:46:58PM +0100, Will Deacon wrote:
> > static inline __must_check bool refcount_sub_and_test(int i, refcount_t *r)
> > {
> > + int old = atomic_fetch_sub_release(i, &r->refs);
> >
> > + if (old == i) {
> > smp_acquire__after_ctrl_dep();
> > return true;
> > }
> >
> > + if (unlikely(old - i < 0)) {
> > + refcount_set(r, REFCOUNT_SATURATED);
> > + WARN_ONCE(1, "refcount_t: underflow; use-after-free.\n");
> > + }
>
> I'm failing to see how this preserves REFCOUNT_SATURATED for
> non-underflow. AFAICT this should have:
>
> if (unlikely(old == REFCOUNT_SATURATED || old - i < 0))
Hmm, that is not sufficient, since you can be arbitrarily far away from
it due to all the races (and add/sub really suck as a refcount
interface). The same will make fixing the cmpxchg loops like
dec_not_one() 'interesting'.
It is important though; to keep saturated, otherwise something that can
do INT_MAX+n actual increments will get freed after INT_MAX decrements
and still have n 'proper' references, *whoopsie*.
>
> > + return false;
> > }
> >
> > /**
Powered by blists - more mailing lists