Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp910694rwi; Mon, 31 Oct 2022 08:59:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Q5+TyD/IFF/hElAW5o8bkKG/E4cl2R67uZBsEvj3DuEWlLhOuUVhu8bGgp5Gk3vqx6NTA X-Received: by 2002:a17:907:2bd7:b0:7ad:9ada:a6f3 with SMTP id gv23-20020a1709072bd700b007ad9adaa6f3mr13110890ejc.355.1667231977464; Mon, 31 Oct 2022 08:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667231977; cv=none; d=google.com; s=arc-20160816; b=HOfehpGCXKOpZS6VkFAspiYN5DZQQVaQj1rASOMY2KRUVzAsWFRvkRXmyjMm9EtYXU +bxC73JttwZymL5H4Kh2U/sCq9IFP9+UwkaOCwJIvvbSLCMxbsxIzBAfO0CjhcWCrHci kfFKpMaOfIv7XYK3RjMj9m3BdN03aMkoNb4GMfWPok6jQmLTGi5CVtqEPlT764e2mrXM vX/RMQ7Vj0FFdfJFnsmNzPdsoIkX3f8op1Ae970A9lJnj1AwRmRxjHcowjy7Yk2fClU6 S6SZJKCgzWNJd8Aepx7/9DbLpVGF25Wpg7aAG2JRZTXeTAyfQeRTY/ALn/tKF4y8ZIdX sYLg== 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=W0IxW07wGXfhbxB2t/U5m54gfxyvIPwy+2kvZkeZYCE=; b=0bnlVj21J1XqmtgnOA2oydoX1f8sAnkm3osg1x35brWqLTQlFzR8o9NB4Z+W67X+4n rq1WJuGluLi1U8D4iHKzzNL1pKZk+T+/M/oiQnswBBieo8rLJY1BwbVaJtyFjgdespB/ x6+KUwBDpBxok9vAQ5+gvythXVXk2cF9RheWhtHtO7X0wCL/21msBikH9aB4YsqbUNgi otO8QNaCuh8U4ZIS5tof4rfXKcyPdH2pvEEy1f3G8xwi1tSTh5+zu07WJU5/xw/+Yc0h rNyHP9sjlcIsX4IT8UNlRTOaR90RTDqMGfKGIpsjB1Fqh+SJTqnp9/2MTaGN4Yfyqjxd KZjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UoMTE4fj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w26-20020aa7da5a000000b00462750bbe08si7182320eds.522.2022.10.31.08.59.14; Mon, 31 Oct 2022 08:59:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UoMTE4fj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231929AbiJaPl2 (ORCPT + 98 others); Mon, 31 Oct 2022 11:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbiJaPlK (ORCPT ); Mon, 31 Oct 2022 11:41:10 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB61111C1C; Mon, 31 Oct 2022 08:40:57 -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=W0IxW07wGXfhbxB2t/U5m54gfxyvIPwy+2kvZkeZYCE=; b=UoMTE4fjFILoU9dWuD24Mpq1Cr X7plBmzOKe2nijiZ3IRKHkM6DGiKraDXfGZSMldphtKA52TEdWcvtPGn8jhsXaIB9NnJkJULCx/0a Gabp3e0nNm89mj0YkmqUUH99d0DeNLJDvhF7psO5GCZY+zHPd9gzRpGFWsbGWfIMpzeOJv9sy9E3w vIlbRhqyo+ef2RpQ1CgUTGIIDCv5LN5vA7kJzVoD68eR5e1aXAEP2Oh5df2p16K6v3LgL6OVlcuZ9 W/dgL1qDNoBIDI4aKrC6NZ5vF4NFV+q/tr8/h74NcUDKHsH6k/pEy5n4NgoR8FugxF6DHzeG1t8sx XViht4uA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1opWu7-003muP-Qk; Mon, 31 Oct 2022 15:40:47 +0000 Date: Mon, 31 Oct 2022 15:40:47 +0000 From: Matthew Wilcox To: Kees Cook Cc: Vlastimil Babka , Anders Roxell , 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> <202210310821.9F7AA27D12@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202210310821.9F7AA27D12@keescook> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 31, 2022 at 08:22:50AM -0700, Kees Cook wrote: > On Mon, Oct 31, 2022 at 03:12:33PM +0000, Matthew Wilcox wrote: > > 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. > > Ah-ha! Thank you both! Seems like the first fix should be squashed and > the latter one is separate? Or just put it all together? Yes, I have no objection to Vlastimil's patch as-is. I haven't really reviewed it, just used it as an excuse to look at this code. A fix for the kmap_atomic() problem will necessarily be separate and should be backported separately.