From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D80F5C55199 for ; Mon, 27 Apr 2020 12:38:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D22420575 for ; Mon, 27 Apr 2020 12:38:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YEifZSnG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D22420575 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 306A68E0005; Mon, 27 Apr 2020 08:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 290018E0001; Mon, 27 Apr 2020 08:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 130B88E0005; Mon, 27 Apr 2020 08:38:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id EE1D08E0001 for ; Mon, 27 Apr 2020 08:38:23 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96B8F824934B for ; Mon, 27 Apr 2020 12:38:23 +0000 (UTC) X-FDA: 76753588086.18.angle53_f0ac7dff2b09 X-HE-Tag: angle53_f0ac7dff2b09 X-Filterd-Recvd-Size: 3711 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Apr 2020 12:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EuRhLbbvYOXOrh6HVR76MSxpSBl6WWX0ew76Qupr1wM=; b=YEifZSnG2+vxDAj47M85s2A2UR wP+on33fQ5OgOXw3OvJt8BOjyWWxlewDkHuZv4F+6Dl9sWC+JNEGU+VGPcpKH6+t5VclSucHVCJJ+ WbqfnobcX+KTb30eCnaiMawJpq0UXwJdLpLQOpueAK7m/Z1eQCqY3ZSJaDdkVKrXMeeboWSgNede3 WqIz5nCs68IPEjR4b5U8vjeQcDtYB/Wosolpf7/uVZep5pY+FH0CJ0erY/y1wa4zX+jc1n7XKxg/p Ym2yTCQxt8gWaPWSmE+X9R7RojyOSvdG57mXbD4YiSGmYurV7MgNnwkvjEPHcgX2p4kVBnlThmKiZ pH5u1TGA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jT31b-0001jt-14; Mon, 27 Apr 2020 12:38:15 +0000 Date: Mon, 27 Apr 2020 05:38:14 -0700 From: Matthew Wilcox To: Waiman Long Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Changbin Du Subject: Re: [PATCH] mm/slub: Fix incorrect checkings of s->offset Message-ID: <20200427123814.GE29705@bombadil.infradead.org> References: <20200427020212.5222-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200427020212.5222-1-longman@redhat.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; } > @@ -556,10 +556,8 @@ static struct track *get_track(struct kmem_cache *s, void *object, > { > struct track *p; > > - if (s->offset) > - p = object + s->offset + sizeof(void *); > - else > - p = object + s->inuse; > + p = object + s->inuse + > + ((s->offset == s->inuse) ? sizeof(void *) : 0); p = object + track_offset(s); > return p + alloc; > } > @@ -693,10 +691,8 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p) > print_section(KERN_ERR, "Redzone ", p + s->object_size, > s->inuse - s->object_size); > > - if (s->offset) > - off = s->offset + sizeof(void *); > - else > - off = s->inuse; > + off = s->inuse + > + ((s->offset == s->inuse) ? sizeof(void *) : 0); off = track_offset(s); > @@ -826,7 +822,7 @@ static int check_pad_bytes(struct kmem_cache *s, struct page *page, u8 *p) > { > unsigned long off = s->inuse; /* The end of info */ > > - if (s->offset) > + if (s->offset == s->inuse) > /* Freepointer is placed after the object. */ > off += sizeof(void *); unsigned long off = track_offset(s);