[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5e529523-c3ea-954e-a0d0-70d9e2345dda@redhat.com>
Date: Mon, 27 Apr 2020 09:56:28 -0400
From: Waiman Long <longman@...hat.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: Christoph Lameter <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Kees Cook <keescook@...omium.org>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Changbin Du <changbin.du@...il.com>
Subject: Re: [PATCH] mm/slub: Fix incorrect checkings of s->offset
On 4/27/20 9:38 AM, Matthew Wilcox wrote:
> On Mon, Apr 27, 2020 at 09:29:41AM -0400, Waiman Long wrote:
>> On 4/27/20 9:18 AM, Waiman Long wrote:
>>> On 4/27/20 8:38 AM, Matthew Wilcox wrote:
>>>> On Sun, Apr 26, 2020 at 10:02:12PM -0400, Waiman Long wrote:
>>>>> In a couple of places in the slub memory allocator, the code uses
>>>>> "s->offset" as a check to see if the free pointer is put right
>>>>> after the
>>>>> object. That check is no longer true with commit 3202fa62fb43 ("slub:
>>>>> relocate freelist pointer to middle of object").
>>>>>
>>>>> As a result, echoing "1" into the validate sysfs file, e.g. of dentry,
>>>>> may cause a bunch of "Freepointer corrupt" error reports to appear with
>>>>> the system in panic afterwards.
>>>>>
>>>>> To fix it, use the check "s->offset == s->inuse" instead.
>>>> I think a little refactoring would make this more clear.
>>>>
>>>> unsigned int track_offset(const struct kmem_cache *s)
>>>> {
>>>> return s->inuse + (s->offset == s->inuse) ? sizeof(void *) : 0;
>>>> }
>>> Yes, that was what I am thinking of doing in v2.
>> BTW, "+" has a higher priority than "?:". So we need a parenthesis around
>> "?:".
> That seems like a good reason to not use ?:
>
> unsigned int track_offset(const struct kmem_cache *s)
> {
> if (s->offset != s->inuse)
> return s->inuse;
> return s->inuse + sizeof(void *);
> }
>
> Also this needs a comment about why we're doing this ... something about
> the freelist pointer, I think?
>
I can see a simple if-else to make it easier to read.
Thanks,
Longman
Powered by blists - more mailing lists