Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp907594rwi; Mon, 31 Oct 2022 08:57:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5t1FaUe98Nmmb8du73H2YlUSszeAyuBK+8Nh+tpaX93GwpR+4LROU6Xj2KDQlAXJp39pZ3 X-Received: by 2002:a17:906:730d:b0:78e:9ca5:3269 with SMTP id di13-20020a170906730d00b0078e9ca53269mr13888978ejc.366.1667231832638; Mon, 31 Oct 2022 08:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667231832; cv=none; d=google.com; s=arc-20160816; b=0/2RDVqOGkKGjVMCg2ViLtYNJf4cRLsxV2gE1wTmjt34Akd2YdZ2YQRkIWWlNBsSiL sSYyqMLcrvXU+/j4/mB7fKPPIJqShoXsLt2Rk7xsqN3w5uNGmwMLawEZzzE9EEWdWHgF RUlSAwYgiKa/2Dhm7JvhG5LopHlHIQqUvBlQ5pzuUH4U5hYtiy140Hzg0POqQf1PM/vT JupiL4H/55IKcdQ27Iit0IeXDoy71XncSce2cNPxFgWyojhi6JsHYroOd8w/P9H/ZWxu 4/sqqfb2n1QYG/B2M8+VDbh0Go+Cch6ABQ4IxO0wqWnTrIu7AGWGq8bDA8j865/R3904 ujZQ== 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=1dA0Bpm+EerGxQeSwdhCiLJP6Ims7gljy+o1neN8bH8=; b=d23zR1M8LvA6PxpF4G6opMTV0qH/VFhkITE2rAElkdJ/kcN+QmQvWNl3x916kS17gj 1FFOrWB9EMzRaQIvkwNeSTM0+SAoOZoErMp0Gtf8kForeekk/IR068tZR7ZUwdLP8N+1 LmVI09/IrT8AeZNDAA6CSb0fqJ6Gax1dz4Y443k7OpiVJVrUGq6CHbWUjwwYOI0dmpEo DF8+zR73JMoOtwYf4fKeh9f+PHVqWMV2d5Ew5nVhAW0MaJtfdwvx95gZ4beNWELukKtl N7NoZQO3fAlxS9rSNt7d9zYsmsKRvwGZCnu47idX/uPhDu2Bf0aDOrU/jNKLQwbSB6EU RQUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gjPYLPBI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw11-20020a1709066a0b00b00781ea213f99si8661687ejc.173.2022.10.31.08.56.49; Mon, 31 Oct 2022 08:57:12 -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=@chromium.org header.s=google header.b=gjPYLPBI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbiJaPW4 (ORCPT + 98 others); Mon, 31 Oct 2022 11:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231537AbiJaPWx (ORCPT ); Mon, 31 Oct 2022 11:22:53 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 493BD11828 for ; Mon, 31 Oct 2022 08:22:52 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id 17so6707652pfv.4 for ; Mon, 31 Oct 2022 08:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1dA0Bpm+EerGxQeSwdhCiLJP6Ims7gljy+o1neN8bH8=; b=gjPYLPBI8i200feYZ0JN7kv2xudySLuBdbVovx/88OFxLGQQTOQWlxUGIvUnQ1sIhW r3QH48FVEHI29WRQkXmuX2eostBHqqet+VmrrFCrL6byOPZ0NS1Z5PjnsjyvPJQ1GyvO YF/8OVMsGxxEgVOrDjqyfq/nkRGstOx/8Bci0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1dA0Bpm+EerGxQeSwdhCiLJP6Ims7gljy+o1neN8bH8=; b=fcUB14Yr8a72oDSi+xORq1BaRouKuys0jdzzvBQD/zPNODTeQT4LPNV+C3A7ISDfsJ P0DPmI4coAUgbGzhEJ2WcowCihQcE5l8W36vC7AgzE4kMycdTZkHEe6iUBUV2DUIhUgA zTq5Evr4x+k9+9LB3crqQVCmy/7Rjg0Jx/qC76WYU7ATHqRuIU64yVkMHqXZ27okjnnm RDIjMwTGtpPRnW7CkceNoecwor9MvMeFMTXCF63ppBC2Rd5SnrsbXqZ604moQyYdCYq5 Ox23JKkWIb7yj8cEinN6/wMEJPGO3gN887aFy79hktFv0Rz/6IPQoUIYbhceMo89Xymt kkMg== X-Gm-Message-State: ACrzQf3esTxmiwbMWB5/Jmbqp0pyvGwM4fqIBpP+3GAQGIzbCj00gZke 4zkHIloQlCx9YhTfpiFlZMML/A== X-Received: by 2002:a05:6a00:15c3:b0:56c:e8d0:aaf1 with SMTP id o3-20020a056a0015c300b0056ce8d0aaf1mr14868603pfu.75.1667229771778; Mon, 31 Oct 2022 08:22:51 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id ix2-20020a170902f80200b001869efb722csm4585853plb.215.2022.10.31.08.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 08:22:51 -0700 (PDT) Date: Mon, 31 Oct 2022 08:22:50 -0700 From: Kees Cook To: Matthew Wilcox 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: <202210310821.9F7AA27D12@keescook> 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: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 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? -- Kees Cook