Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1353831pxb; Fri, 1 Oct 2021 08:54:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFSD4sabA0+BSz/msRcGoAD21D0eW8Vo48BUBTY77pOSh3JmznrxacCFnDI39aM4dbR2ML X-Received: by 2002:a65:684d:: with SMTP id q13mr7449083pgt.208.1633103665801; Fri, 01 Oct 2021 08:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633103665; cv=none; d=google.com; s=arc-20160816; b=BzLOyyGZ5WxlQAl2XFBeWv5UQTgtGTkrLdhIE4iPpqDVWqHhJ1w1pzT+stWTRBqGqL QojazveGNFlNUFWfDoZMnjCjasv2twWJF3mtd7W9/nK6N+dJ3B2qCn276fSczYxSkYQs Y8rMCk0iz/7FVOD0vfgSU4sFMm5ioN92EidY1acd/tmLzB3ETQu5wYae0kNAXek0BrLQ 9gTCAljnvb8hNOFpQE5hBVDJV4XcB/tQd9apChZRs5f/IVxHcoJN3xPtwESUPnIquyVr SCrq7JcZJrK5TQExlCsOdpdvxNrgI6APSCuc8mq0cG16TF5omT2eyLVc4sRSO3KcxeQ+ DhsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=v+V/r4h62iC1rLKsrgjisVTgoRvyIjeKcO+78KSD2u0=; b=g0uW5mOuGctXP8ivXOO/K9IKSdSqeDbARdf87opObdiNT1vI5uf3FPfRDEhx3cq5pF Pm68fF9XZTjwrmdSeeboBxGPgeZQMZSb4qjjVxmYcBzq5AhDaWxxoKFRSjWRyZCwMu5C WbmGMfIkoKNcHu8fK63XfERaFoSXLf+cLT82T/y2rtdBHlsliyQiEsmjHphYo13WU77k jeftAX3akcm0IvMKv33XNtbz3JMeh5WagzZWKvYNWCeF3yWrc0x4+RmGEVw/PIzANiE7 1/+/lA12L+ZKYwrQHWGMwflHsPrW8z4uIeW7Bbx3b7SiaOd5IY0yYO9e8HTVFSlxnVxv TlVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VnlExgmh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si2171186plb.431.2021.10.01.08.54.12; Fri, 01 Oct 2021 08:54:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VnlExgmh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353924AbhJAOI6 (ORCPT + 99 others); Fri, 1 Oct 2021 10:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353565AbhJAOI4 (ORCPT ); Fri, 1 Oct 2021 10:08:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E858C061775 for ; Fri, 1 Oct 2021 07:07:12 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?