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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 666ADFA3741 for ; Mon, 31 Oct 2022 15:12:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B45EA8E0001; Mon, 31 Oct 2022 11:12:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF5C56B007E; Mon, 31 Oct 2022 11:12:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E66D8E0001; Mon, 31 Oct 2022 11:12:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 795106B007D for ; Mon, 31 Oct 2022 11:12:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0F991C0BD0 for ; Mon, 31 Oct 2022 15:12:40 +0000 (UTC) X-FDA: 80081586480.11.C38F316 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id F22194000C for ; Mon, 31 Oct 2022 15:12:38 +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=TPvWvXv6yMZaf0wVZxcvo68g3rMsA09BUEC3iTc6qFw=; b=AbB4efg2oN0nlQRcssIl97nOp4 aJBp9PyNs5SQKw2famHTJ4in7RQFV1yUqbz4sYmVMAMPes41F7Q3X4Tz1m8RR/3eLkCwqFNJGAyzo 5bvzi4+MOxZ5cxJ5f+yGKDfdFQ4snxwymgMPNQleo8SUclrsdUiJ825BVB31FJ/SfOBw5JjdXi1Ha NwDwZxfyPLnQReBaA1aonsbAd0vEzehOOrZ9zIZ7yfL7hpUJZ3anvkINNSdwFEgWQF9eOKTtIeDOQ Yl9m4rxWfF5q+o27J61YnjK9k2tkoRps9fdCMZhjqKMOtiGsO6Ysqi01JxwFGDiE9xT0ZzFpD3Pds PYeFYYIA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1opWSn-003ljY-G1; Mon, 31 Oct 2022 15:12:33 +0000 Date: Mon, 31 Oct 2022 15:12:33 +0000 From: Matthew Wilcox To: Vlastimil Babka Cc: Anders Roxell , Kees Cook , kernel test robot , Andrew Morton , David Rientjes , Marco Elver , Vincenzo Frascino , linux-mm@kvack.org, Andrey Konovalov , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v4] mempool: Do not use ksize() for poisoning Message-ID: References: <20221028154823.you.615-kees@kernel.org> <20221031105514.GB69385@mutt> <13c4bd6e-09d3-efce-43a5-5a99be8bc96b@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13c4bd6e-09d3-efce-43a5-5a99be8bc96b@suse.cz> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667229159; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TPvWvXv6yMZaf0wVZxcvo68g3rMsA09BUEC3iTc6qFw=; b=L/+VDaMbkpslfJEzDY3IWudw8MzcmPoX/r/Vf/DQn/3nBaZc8KYxOC76h6b8/ZsQPlep2W FSb6WmDOPj9DuDVIfVmsYc8nUNHEognZpy0hrcTkM7mDDztz2it80PMIM/u6R5T6h1rD2z EoxwDypApANvB9ZfURDq1Et/fn3s6so= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AbB4efg2; dmarc=none; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667229159; a=rsa-sha256; cv=none; b=57JGS1d2m58Kfs4Xjosj2tIN3IJFw07HjDposbEfmLAjXkW7KigmTBm0iIBhqCHq0ffR3O SkOb2q+9V4ZrVBStGkOxOgIdpHOoPaxJ0GTkO/+Mi8TA8EjXWFTMZsXKkk8JHOZfu+cOUz c+kXu948g2YzDp8iD/z1TEP1mGUzXY4= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: F22194000C X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AbB4efg2; dmarc=none; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Stat-Signature: bsnfc8y7aiuaku576154qemskzrpa5ri X-HE-Tag: 1667229158-192541 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, Oct 31, 2022 at 04:00:25PM +0100, Vlastimil Babka wrote: > +++ b/mm/mempool.c > @@ -57,8 +57,10 @@ static void __check_element(mempool_t *pool, void *element, size_t size) > static void check_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > - if (pool->free == mempool_free_slab || pool->free == mempool_kfree) { > + if (pool->free == mempool_kfree) { > __check_element(pool, element, (size_t)pool->pool_data); > + } else if (pool->free == mempool_free_slab) { > + __check_element(pool, element, kmem_cache_size(pool->pool_data)); > } else if (pool->free == mempool_free_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; I had a quick look at this to be sure I understood what was going on, and I found a grotesque bug that has been with us since the introduction of check_element() in 2015. + if (pool->free == mempool_free_pages) { + int order = (int)(long)pool->pool_data; + void *addr = kmap_atomic((struct page *)element); + + __check_element(pool, addr, 1UL << (PAGE_SHIFT + order)); + kunmap_atomic(addr); kmap_atomic() and friends only map a single page. So this is all nonsense for HIGHMEM kernels, GFP_HIGHMEM allocations and order > 0. The consequence of doing that will be calling memset(POISON_INUSE) on random pages that we don't own.