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 07B0AC54FCB for ; Mon, 27 Apr 2020 13:38:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BAAB120663 for ; Mon, 27 Apr 2020 13:38:16 +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="B1EBJRVP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BAAB120663 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 857868E0005; Mon, 27 Apr 2020 09:38:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8078F8E0001; Mon, 27 Apr 2020 09:38:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71D7E8E0005; Mon, 27 Apr 2020 09:38:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0234.hostedemail.com [216.40.44.234]) by kanga.kvack.org (Postfix) with ESMTP id 5E1308E0001 for ; Mon, 27 Apr 2020 09:38:16 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1858F21EA for ; Mon, 27 Apr 2020 13:38:16 +0000 (UTC) X-FDA: 76753738992.01.face69_653d1892c173e X-HE-Tag: face69_653d1892c173e X-Filterd-Recvd-Size: 3496 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Apr 2020 13:38:15 +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-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=9UoMgYzM3h0SmuuYcAun6uUW+gxC7pfA5UN/YTDR2z0=; b=B1EBJRVP47y3yK5GB9pE1YLIzA ZJfigSMb5ZIUbxD8wk8m4Tssv8e7CKWZlK+bsX8y2NjDvoZWh7QeDkVQi+8uP1EK5dlxn8nL430UY kbGvuGxH+7vnwXEufD71CqacdleCXtwxAI9CMCNEnUEErVPYgIHWTqJHjHgb2354bFjd3xJCMYrY/ EzntOhjQUJsP8bKXiGGhfJDL/3Tp9FYvGFIFN2LeMu8RjGZCEvMbGlZxIRoXQByzsEDnIN1x5NtBA cKjHm7afLk4Ikb4hxknV+evmvpufJ+mbC2tpgm5Ou++L+TNGH1SIHwcnLj9cvwCoiE/6YVwsu504F 3DH3+E9A==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jT3xY-0000sU-2P; Mon, 27 Apr 2020 13:38:08 +0000 Date: Mon, 27 Apr 2020 06:38:07 -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: <20200427133807.GF29705@bombadil.infradead.org> References: <20200427020212.5222-1-longman@redhat.com> <20200427123814.GE29705@bombadil.infradead.org> <891a7635-9074-d320-9571-74f584401f01@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable 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 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 ("s= lub: > > > > relocate freelist pointer to middle of object"). > > > >=20 > > > > As a result, echoing "1" into the validate sysfs file, e.g. of de= ntry, > > > > may cause a bunch of "Freepointer corrupt" error reports to appea= r with > > > > the system in panic afterwards. > > > >=20 > > > > To fix it, use the check "s->offset =3D=3D s->inuse" instead. > > > I think a little refactoring would make this more clear. > > >=20 > > > unsigned int track_offset(const struct kmem_cache *s) > > > { > > > =A0=A0=A0=A0return s->inuse + (s->offset =3D=3D s->inuse) ? sizeof(= void *) : 0; > > > } > >=20 > > Yes, that was what I am thinking of doing in v2. >=20 > BTW, "+" has a higher priority than "?:". So we need a parenthesis arou= nd > "?:". That seems like a good reason to not use ?: unsigned int track_offset(const struct kmem_cache *s) { if (s->offset !=3D 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?