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 E5096ECAAA1 for ; Mon, 31 Oct 2022 15:22:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BFB88E0003; Mon, 31 Oct 2022 11:22:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56FD06B0081; Mon, 31 Oct 2022 11:22:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4374F8E0003; Mon, 31 Oct 2022 11:22:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1F1496B0080 for ; Mon, 31 Oct 2022 11:22:54 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AD90A1C5C8A for ; Mon, 31 Oct 2022 15:22:53 +0000 (UTC) X-FDA: 80081612226.25.91DB85C Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf18.hostedemail.com (Postfix) with ESMTP id 2E8541C0014 for ; Mon, 31 Oct 2022 15:22:52 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id b29so10922996pfp.13 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=sOOx57Vx+59+Y+HIYCS6wXEQHq1kSUCN1OsY7WedG/E2QQ+lFh28PBJ827pozzKrKy Y95pK2rx4YA7LCUg0Y5KYzf7heBsQl6nYrZg0a1gyOe2lxE7+5x71auJLltE7keZIOdU vhCYpdhervxcEOsCbPsh9btr5DtOLDYIyCkmw8OS7N3WA2pGvdrUaD1R/nlyQKjYIq5O MwJe9rEVP8suARdiiCKXAoGakDhOX9Pc6tNNQSfuKb02nAZvVIvyXygVX1NCdhQUSqB7 RyYKCroolTbAYfe4GVnOyCNBoldHbnl6a5eNsmxOMq4pBCFTrnd/d44Q8Pa+Ynoj6Kbn /BoA== X-Gm-Message-State: ACrzQf2642hP1jgy/gZCMLHngNvGu3ZL2i6UIQpI+OT5mBYFshuMZ0+t avYNDb7Lxs2tZnLFvV6+rz9ycw== X-Google-Smtp-Source: AMsMyM50aXJ7r3X1z4lItzTdn18aYnYoL2XL75pwhE733EavEAKX8Wh7vM2fmh4Pg1j/uaWxqzL6Hw== 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: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667229773; 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=1dA0Bpm+EerGxQeSwdhCiLJP6Ims7gljy+o1neN8bH8=; b=y8smcOB1KvroqBJOdqzJMmg+J8OikIkjLotyWIzF6m3Y8SOzMEpQkGlABrYh2FA03zNgvv TcVvf+6rIlVz1YIlu4KSzLX/RW/Ic8bJFvgwGfT4BS1ph9STbJ7mswgaZzektV2bXjrFRt PnAl+oxg+ZsFRdkMHi/R+rCadV+3Su4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gjPYLPBI; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf18.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.182 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667229773; a=rsa-sha256; cv=none; b=MUaOAC7cPJIeU24yQKou8cAyGwT3ySyLkDFHZdIcvFVxS2TG2pFBDP/p9aeJVi3Olf9Efr IQkAFRU18bxxlyxCFX4HNgFMq2SWY38/4Oopw/a2TFtjYJl/MbqUaAsonOvHr28FTsTYo8 jaIyWT6loedQxX0D7h9lc5+TouU/kL0= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2E8541C0014 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gjPYLPBI; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf18.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.182 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Stat-Signature: fqipdkxs3urqjb4iexwytkh1fah4o6k4 X-HE-Tag: 1667229772-365216 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, 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 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