Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp906096rwi; Mon, 31 Oct 2022 08:56:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6sxj9FnbCanGikwtvhcpp890/Z/5AIif7hoEBAmmA6SWHhD8mQgXhkbACxOxuSDqAEYk4+ X-Received: by 2002:a17:906:7c52:b0:7ad:c9e5:3ecc with SMTP id g18-20020a1709067c5200b007adc9e53eccmr7327253ejp.73.1667231763033; Mon, 31 Oct 2022 08:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667231763; cv=none; d=google.com; s=arc-20160816; b=x7m+NKguT8//gJDFNC8iRnjcymdzPVB0d2zbxR+9k0vECK0xfZrrdkzDzFO4RLstWE iyhMnyYnx8UdD0flcbJ8KztdhMmUGaMyVxlOda01lc4wKxCVpuvNol9wW6iBE7w/TG7K nDDvCqqH1zHsS6tcbX4eapoKq5ckExg1xy5/TH+p5K+ZDJWowGmAY2ES+SxqhxFZAIF0 UWcv8uJwGl6g/opdCGh6MZ1BDInfSvk3xVQWcXREQ17S1pY++RlJt9oTHUmgxaKXVxjV 5WRdcH171lsuJKiZyfKg2lBHEJmGLoz2hIcXgw4AqCXxkWL+xrv4jojWZdDP/ITEJ+Uw Nq9g== 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=TPvWvXv6yMZaf0wVZxcvo68g3rMsA09BUEC3iTc6qFw=; b=R3w0AA5GodR1bqG14F8xGEF9gtG06N43ufaJDM7kEQbuInF9fqON0YLevzoi+E16Z9 2nZZlUTCt2rv+NMiX3TA3BIWOspvHBIz4ZTTWgk487YegWeC4lwtt0xmgPJZ2gbngIZt WNTTyGkjkchZ/Al6Vbiti4n4Ll1BEPZ7gzonkyuEKIBJ9v3OiQpqp/rMepUaiTNDoXdF 715hMm9OXPNYLU1zAhH9Hiz4Sk749r7+3ga9h/Hv9PbSX4o+K+3gmlBd6E2Zk9G8/1vZ U6sJj1IWzcHq6c+G7S93WPov3rKv2uosh0CPlSQm3234O62yE+wxi6OwgnvzdAG3jsnV 6x7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=AbB4efg2; 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 sd37-20020a1709076e2500b007316ac034a1si8218185ejc.831.2022.10.31.08.55.38; Mon, 31 Oct 2022 08:56:03 -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=AbB4efg2; 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 S230197AbiJaPMt (ORCPT + 98 others); Mon, 31 Oct 2022 11:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbiJaPMm (ORCPT ); Mon, 31 Oct 2022 11:12:42 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1279511458; Mon, 31 Oct 2022 08:12:42 -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=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> 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 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.