From: Matthew Wilcox <willy@infradead.org>
To: Waiman Long <longman@redhat.com>
Cc: Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <keescook@chromium.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Changbin Du <changbin.du@gmail.com>
Subject: Re: [PATCH] mm/slub: Fix incorrect checkings of s->offset
Date: Mon, 27 Apr 2020 06:38:07 -0700 [thread overview]
Message-ID: <20200427133807.GF29705@bombadil.infradead.org> (raw)
In-Reply-To: <b4d05ff7-0fe2-67d8-f2a7-6d0c2ab19408@redhat.com>
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?
next prev parent reply other threads:[~2020-04-27 13:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 2:02 Waiman Long
2020-04-27 12:38 ` Matthew Wilcox
2020-04-27 13:18 ` Waiman Long
2020-04-27 13:29 ` Waiman Long
2020-04-27 13:38 ` Matthew Wilcox [this message]
2020-04-27 13:56 ` Waiman Long
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200427133807.GF29705@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=changbin.du@gmail.com \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox