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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDB77C433EF for ; Fri, 1 Oct 2021 14:07:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 65B0061439 for ; Fri, 1 Oct 2021 14:07:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 65B0061439 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D572294010E; Fri, 1 Oct 2021 10:07:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE08E9400E4; Fri, 1 Oct 2021 10:07:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B816294010E; Fri, 1 Oct 2021 10:07:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0158.hostedemail.com [216.40.44.158]) by kanga.kvack.org (Postfix) with ESMTP id A6B979400E4 for ; Fri, 1 Oct 2021 10:07:13 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5D9D38249980 for ; Fri, 1 Oct 2021 14:07:13 +0000 (UTC) X-FDA: 78648045546.32.B3B1C3A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 86E4F9000727 for ; Fri, 1 Oct 2021 14:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=v+V/r4h62iC1rLKsrgjisVTgoRvyIjeKcO+78KSD2u0=; b=VnlExgmhWtdxvYcUEVXhVCT9Qk T4cMuYA8ClUydes7ClaGaL+wnYjI04npl7GXoOG50t1Koma97//S5Nb7p3IB8gnWkn5EcGelp+wwb fwfJpyzHUMhVgeo+2dXD4x6SSwmVEG1lyCkhbcDVJeSBTR3Fsd5ovrT06uTr7PasXMHeQGh5RkCW9 PMdx67+T/F8r79PU5A+6DnnR/cw9wRZADlsSr+Lt0sZ8m2rU1j06rZcSu8LO/nDVwZ3qqR6T5JHg5 CGsFK213eb+tiMXUl3fRNGe7yqnWSAGJj0Tsd8hQjg3K3ySv53OeAD506E+A/X6yYfxKBpGMISj19 hB6CzlKQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mWJAS-00Dxk8-98; Fri, 01 Oct 2021 14:06:04 +0000 Date: Fri, 1 Oct 2021 15:05:40 +0100 From: Matthew Wilcox To: Andrey Konovalov Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , kasan-dev , Linux Memory Management List , LKML Subject: Re: [PATCH] kasan: Fix tag for large allocations when using CONFIG_SLAB Message-ID: References: <20211001024105.3217339-1-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 86E4F9000727 X-Stat-Signature: pn7icf37fu4ph6ko9yw6468t63wscmhn Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VnlExgmh; dmarc=none; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1633097232-762077 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 Fri, Oct 01, 2021 at 03:29:29PM +0200, Andrey Konovalov wrote: > On Fri, Oct 1, 2021 at 4:42 AM Matthew Wilcox (Oracle) > wrote: > > > > If an object is allocated on a tail page of a multi-page slab, kasan > > will get the wrong tagbecause page->s_mem is NULL for tail pages. > > Interesting. Is this a known property of tail pages? Why does this > happen? I failed to find this exception in the code. Yes, it's a known property of tail pages. kmem_getpages() calls __alloc_pages_node() which returns a pointer to the head page. All the tail pages are initialised to point to the head page. Then in alloc_slabmgmt(), we set ->s_mem of the head page, but we never set ->s_mem of the tail pages. Instead, we rely on people always passing in the head page. I have a patch in the works to change the type from struct page to struct slab so you can't make this mistake. That was how I noticed this problem. > The tag value won't really be "wrong", just unexpected. But if s_mem > is indeed NULL for tail pages, your fix makes sense. > > > I'm not quite sure what the user-visible effect of this might be. > > Everything should work, as long as tag values are assigned > consistently based on the object address. OK, maybe this doesn't need to be backported then? Actually, why subtract s_mem in the first place? Can we just avoid that for all tag calculations?