[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190502173716.GD18948@bombadil.infradead.org>
Date: Thu, 2 May 2019 10:37:16 -0700
From: Matthew Wilcox <willy@...radead.org>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Kees Cook <keescook@...omium.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, linux-kernel@...r.kernel.org
Subject: Re: Alloc refcount increments to fail
On Thu, May 02, 2019 at 04:46:44PM +0100, Al Viro wrote:
> On Thu, May 02, 2019 at 08:26:21AM -0700, Matthew Wilcox wrote:
>
> > +/**
> > + * refcount_try_inc - Increment a refcount if it's below INT_MAX
> > + * @r: the refcount to increment
> > + *
> > + * Avoid the counter saturating by declining to increment the counter
> > + * if it is more than halfway to saturation.
> > + */
> > +static inline __must_check bool refcount_try_inc(refcount_t *r)
> > +{
> > + if (refcount_read(r) < 0)
> > + return false;
> > + refcount_inc(r);
> > + return true;
> > +}
>
> So two of those in parallel with have zero protection, won't they?
We check that we're only halfway to saturation; sure we might go a
few dozen steps from INT_MAX towards UINT_MAX, but I have a hard time
believing that we'll get preempted for long enough that we'd get all
the way to UINT_MAX by unchecked increments on other CPUs/threads.
Powered by blists - more mailing lists