Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1197139rwi; Thu, 27 Oct 2022 12:31:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Fq+vpmBGaUdTK9IRM4MxiWJGV0XNqOqCH+fJxpsi+0wb031YSiBiL292ZTBtQzho+pL2R X-Received: by 2002:a05:6a00:8c8:b0:52c:887d:fa25 with SMTP id s8-20020a056a0008c800b0052c887dfa25mr50625386pfu.86.1666899064616; Thu, 27 Oct 2022 12:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666899064; cv=none; d=google.com; s=arc-20160816; b=T3WVYRGDZ+c176El+7MMDuwO7FyjKUDbkptcC/KPSJQ52A23zttinC4CNMj12arjco 55r6zR0C7ihiRlz1PT2HrkxuLJBzz3+633NNea9zU7rbV4PjuBng+kKbzyF1dYITENhn c130ImkyGQ0JhBSncVZRbBsVdG+0yn1aOJErzS/PgRVRki3OSEzh8dE7pkFJbfH+MSwl yvMQBfNxJM5LZlWJLrarsFfZv10lPCFIrWUm8NAntZc877LN6dNEOmqp4re7GkzDOoHn ZouCqCus5WntKFsSbfzTkOwdY8AuSLWn5h5If9XoXqx2gQbxPm8vSaV2pL3fZNofp40y p9mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Xmd8GXOVfbZSYxYq01AYUaxIegxLuQZMi2sQ8kS4z4o=; b=nOhlcfnGExxnCFbBMK/njAxgYz7jiEZQZVEA30R58qfIhEKFX22cdcCQB3nKKHUQZF W2FldVtjv7qiZW65ZN8M9/V25b8TBYQsId+5W1bow1njbKceCZl8SwvDsppPfaeagO2O uhuI9Bowmr3Ba8+5meFMi/LftbeDDi+kgCPlFLjStKo0w265k9g2DDNAUqKxDCHqSEOa PGIgr6aG5uYh9eyvmCxVAmk8QNwKRnId9f5UOd0S7DgWMN9F3Zpt/LAj7jJXPDiZfRnt zpcsH3KsYkb5xB2hQPgUSHTsjsHfPVUjNF34S+ZKXvOUTPt4L66P0MI8t+/s1tOEsqCW hOiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gSR6DQKB; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a625804000000b00562cafb2856si2582390pfb.78.2022.10.27.12.30.49; Thu, 27 Oct 2022 12:31:04 -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=@gmail.com header.s=20210112 header.b=gSR6DQKB; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235904AbiJ0TP2 (ORCPT + 99 others); Thu, 27 Oct 2022 15:15:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234309AbiJ0TPZ (ORCPT ); Thu, 27 Oct 2022 15:15:25 -0400 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 661B429825; Thu, 27 Oct 2022 12:15:22 -0700 (PDT) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-13b23e29e36so3466808fac.8; Thu, 27 Oct 2022 12:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Xmd8GXOVfbZSYxYq01AYUaxIegxLuQZMi2sQ8kS4z4o=; b=gSR6DQKBGvM3MOEzxUB5IKHBXxbtatGQxu1vnR+b5iXeLOGMg8DqWHvRy4izXyFPh/ a2SHVkWyPaIGLJ8WcCglUU4x8iJXahoEFb59xIpfLy379bF//G4oWRnhrEDYlMXwKE/p NFjnqQOtnieWFUffLphIzwQgTDUFVi1iG9WzXvM+utoFgsGyS2/F6nhC8sMSqSDDW8Ed VcRN7Cu52XgjdRVeejlN2HsvX4VKashJZ5T42CfJFa1iHQJfEItE+bpjzRPrei2ms4xM hPRR2SIwSoc8+9IyLsMaddg6z4jobWqmsvdi9aJdVnP0YhnYbLHE4dIiHJeGMz4QWtOE NJng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Xmd8GXOVfbZSYxYq01AYUaxIegxLuQZMi2sQ8kS4z4o=; b=LFxNnjnNengDDSw9V0FGRhgwVRUKGUMy5EcVnVzrZrnUkKx2Cx8QYBqClzpLpGxl7f Dv9JE+B50vMRBuWM1ShkNMRmAYk6z0HsdREZ6sgsd4RQ26Tdgrc3cC9IyfoAiEcKVUdJ LLDmxYbB2FOFE70YUi3SOC96p2IHOUDxr5Y3Ijk/z15WiizWxIpOZynrqpiAVtPB4I2p GFG+7o6fkXVuBi/wSmjuDJzMdxfk9BswjQqxkhxXEoW4I5KtkjAlX7SFy30drZKZWbmv hWgz5KBY66yrhyugH1qpy/p9wg6nA1QeS2D+E0pfwFbTnr7/VWb+mSWS6VyDhCxeYNoX DWXA== X-Gm-Message-State: ACrzQf17NQSeVksgxeFOJ5Kn7SL0FHNt1P+E2O0W5Lj3C/ADqQjQYv0P MVdwWoVL2DArSMTEG6DKwOiSDWSdPn7iO50VQps= X-Received: by 2002:a05:6870:c182:b0:12a:e54e:c6e8 with SMTP id h2-20020a056870c18200b0012ae54ec6e8mr6421188oad.207.1666898121794; Thu, 27 Oct 2022 12:15:21 -0700 (PDT) MIME-Version: 1.0 References: <20221025233421.you.825-kees@kernel.org> In-Reply-To: <20221025233421.you.825-kees@kernel.org> From: Andrey Konovalov Date: Thu, 27 Oct 2022 21:15:10 +0200 Message-ID: Subject: Re: [PATCH v3] mempool: Do not use ksize() for poisoning To: Kees Cook Cc: Vlastimil Babka , David Rientjes , Marco Elver , Vincenzo Frascino , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 Wed, Oct 26, 2022 at 1:36 AM Kees Cook wrote: > > Nothing appears to be using ksize() within the kmalloc-backed mempools > except the mempool poisoning logic. Use the actual pool size instead > of the ksize() to avoid needing any special handling of the memory as > needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE. > > Suggested-by: Vlastimil Babka > Link: https://lore.kernel.org/lkml/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/ > Cc: Andrey Konovalov > Cc: David Rientjes > Cc: Marco Elver > Cc: Vincenzo Frascino > Cc: Andrew Morton > Cc: linux-mm@kvack.org > Signed-off-by: Kees Cook > --- > v3: remove ksize() calls instead of adding kmalloc_roundup_size() calls (vbabka) > v2: https://lore.kernel.org/lkml/20221018090323.never.897-kees@kernel.org/ > v1: https://lore.kernel.org/lkml/20220923202822.2667581-14-keescook@chromium.org/ > --- > mm/mempool.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/mempool.c b/mm/mempool.c > index 96488b13a1ef..54204065037d 100644 > --- a/mm/mempool.c > +++ b/mm/mempool.c > @@ -58,7 +58,7 @@ static void check_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > if (pool->free == mempool_free_slab || pool->free == mempool_kfree) { > - __check_element(pool, element, ksize(element)); > + __check_element(pool, element, (size_t)pool->pool_data); > } else if (pool->free == mempool_free_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; > @@ -81,7 +81,7 @@ static void poison_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) { > - __poison_element(element, ksize(element)); > + __poison_element(element, (size_t)pool->pool_data); > } else if (pool->alloc == mempool_alloc_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; > @@ -112,7 +112,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element) > static void kasan_unpoison_element(mempool_t *pool, void *element) > { > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) > - kasan_unpoison_range(element, __ksize(element)); > + kasan_unpoison_range(element, (size_t)pool->pool_data); > else if (pool->alloc == mempool_alloc_pages) > kasan_unpoison_pages(element, (unsigned long)pool->pool_data, > false); > -- > 2.34.1 > For the KASAN change: Reviewed-by: Andrey Konovalov Thanks!