lkml.org 
[lkml]   [2019]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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;
> > }
> >
> > /**

\
 
 \ /
  Last update: 2019-10-09 13:36    [W:0.046 / U:42.324 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site