Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp476835rwi; Wed, 26 Oct 2022 03:30:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/RATdiCPyLwTLZLkHrmI1myF0ZMtlejYMH1w8YCD9LmF1ZthaD/2/b1V6OD7XaJEwBgVd X-Received: by 2002:a50:ff13:0:b0:43e:76d3:63e1 with SMTP id a19-20020a50ff13000000b0043e76d363e1mr39937145edu.271.1666780234157; Wed, 26 Oct 2022 03:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666780234; cv=none; d=google.com; s=arc-20160816; b=jayM5KlR1dFf1QMslRfKUjCUyf2OaOi6ppSrvWhI0YYXkgIzINDRvzlxbueR+9w6NQ +aSmmEbOfJDTbLirPKkyrIOOXYu/YpM8zFICc5a8CrzgxXvjKVtFK2FYnVcofSxOhO6I TcssLebm39ZI7gqafnCecH+spXOPu2JGnM2Lzk4DDQZYehNHngCkJM8KMGGcPm8336E+ 3m2Epy7w5MP5kIFXsq0D0is0T+LDsDy7YCwJ0vN+lowTemLDoyz8CfLmESDJIcZ43PPj /npRJK8RuOtEQx130xftYFAmrus9c8dESEwjSQDmsIouVECX3h8/MENRqkW14L4LD6Qs y8cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=vR6f3Clxj5CrL08Ju/vI52Uneo3/xjRAjpwZPragrGg=; b=rAjX5L9hh0a6lI87IRNhJ81e3VRZ/ZktvHLAxgvW/awK3BHBXktAq2Rr4UcqlukHH7 PJidK/ypC+xkUbt9QelIhNfUXkQKN22Ny/YmhLqC90OTzr7ZAv7m6ezjgWDlBTrXvn0F xXGaZf3dxJr+LK2UZRPj2OHon/Rz13sIj8XqX3fg4V0XTGtdegsnuf7LLi20EKg7gYHY PWTgaokHnJVWV06M5k2LxIKoD6NP4CThZ0HO4+MKq27VSHiIdIwytUXTqfpR99W2xieb oIeL1/vTtEtMDGnL6xFpddvFSh6AxdHZTjSh9OgYCAUTVwciNxZZG3yCw9SSXlSQleR1 71Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=bz4318np; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Y45GjEJ0; 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 g11-20020a056402090b00b00461c74a07c8si1697572edz.343.2022.10.26.03.30.08; Wed, 26 Oct 2022 03:30:34 -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=@suse.cz header.s=susede2_rsa header.b=bz4318np; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Y45GjEJ0; 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 S233068AbiJZKC7 (ORCPT + 99 others); Wed, 26 Oct 2022 06:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbiJZKC4 (ORCPT ); Wed, 26 Oct 2022 06:02:56 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86AB59187B; Wed, 26 Oct 2022 03:02:55 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3ABF91F8B3; Wed, 26 Oct 2022 10:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666778574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vR6f3Clxj5CrL08Ju/vI52Uneo3/xjRAjpwZPragrGg=; b=bz4318npD5LKv6OgOsEgmjuAojToyggPbdIHJs+iX/3aAH9iloZt/lD4hEnPq2JA4M9/HV vfPa7c11Rx6zwnA5+IwCiNsiojNpcQRnIs/pnktGoXBljMw7Lx9Cjm25l90IkoGBfBgb5O 0y4PbMiSoOsh31BaS0/kWFuTCsfhwGA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666778574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vR6f3Clxj5CrL08Ju/vI52Uneo3/xjRAjpwZPragrGg=; b=Y45GjEJ0tLrfb/Pq4dg6Qwyowx3FC6E9SSohCtxbtu8IXqD7Hex+wvaUeRyo4Lg/n28+SS /+6dFeKiTCxAFOCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 12EC913A77; Wed, 26 Oct 2022 10:02:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IYvhA84FWWOEcwAAMHmgww (envelope-from ); Wed, 26 Oct 2022 10:02:54 +0000 Message-ID: Date: Wed, 26 Oct 2022 12:02:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v3] mempool: Do not use ksize() for poisoning Content-Language: en-US To: Kees Cook Cc: Andrey Konovalov , David Rientjes , Marco Elver , Vincenzo Frascino , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20221025233421.you.825-kees@kernel.org> From: Vlastimil Babka In-Reply-To: <20221025233421.you.825-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL,URIBL_BLOCKED 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 10/26/22 01:36, 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 Acked-by: Vlastimil Babka > --- > 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);