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 02498C38A2D for ; Wed, 26 Oct 2022 10:08:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 862EF8E0002; Wed, 26 Oct 2022 06:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 813E98E0001; Wed, 26 Oct 2022 06:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DABA8E0002; Wed, 26 Oct 2022 06:08:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5EC0C8E0001 for ; Wed, 26 Oct 2022 06:08:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2A548120EE1 for ; Wed, 26 Oct 2022 10:08:21 +0000 (UTC) X-FDA: 80062675602.22.C6E64E1 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf06.hostedemail.com (Postfix) with ESMTP id 7D2B4180004 for ; Wed, 26 Oct 2022 10:08:20 +0000 (UTC) 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 A50F21FD56; Wed, 26 Oct 2022 10:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666778898; 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=ydCAob6HgvCPbdGA0ZiQNvtk9HMlJx1K6t67HVDCx50=; b=YI5GTSYVG7SoPkKtH+gaPhNVnDYCgRS+tITStru1wyr5Oav9xj+vaFThl611BiJY5CkE64 pdQecRmv0CeM0LgqeeQKyy+HgCgwugF9y4kChQaDnbML9sdPJ6fISGml6MsYITGOIOD46I Y2VrrCcIFo9LhT63BGbd6P/mr7p5TNk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666778898; 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=ydCAob6HgvCPbdGA0ZiQNvtk9HMlJx1K6t67HVDCx50=; b=yug+nQgGF+SZyMiDYzkikmyve8mwQg/6I2cldGUxiFfwIRKSaNwKRZ0ghhxDlIhu4YXkaV OoA3+QvB4Jt1tqCg== 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 678D813A77; Wed, 26 Oct 2022 10:08:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2faMFxIHWWMpdgAAMHmgww (envelope-from ); Wed, 26 Oct 2022 10:08:18 +0000 Message-ID: Date: Wed, 26 Oct 2022 12:08:18 +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 From: Vlastimil Babka To: Kees Cook , Andrew Morton Cc: Andrey Konovalov , David Rientjes , Marco Elver , Vincenzo Frascino , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20221025233421.you.825-kees@kernel.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666778900; a=rsa-sha256; cv=none; b=vIJazC/cBHurZlOclWPVNLdwGXSQTHyEP0bdaFSFgBbDUi2cV+I4ZgL6tA6/d/cFE0m3M0 V7vvHQ1ohVInbTE9NF4l4PyNQH/2ZKlWH4DOjbU+f6+46NSuUamfeqg/16EP95tl6KyrHS h7ID8zximl6Xtq5O72uhf+CuORUuHUI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=YI5GTSYV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yug+nQgG; dmarc=none; spf=pass (imf06.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666778900; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ydCAob6HgvCPbdGA0ZiQNvtk9HMlJx1K6t67HVDCx50=; b=lQ46OD1y5jjqQU5H01QTinpS9dwzIcZ8d545665IDzaAMRTG1DIO9hSPp6OBfJChpLt1kV DtZdJqLTqG9X2ETEqblGSTISLAQ2k7ZqVopCtxZ/2ya37V5wVk6OAMl9MZus6jwzlzgx21 krFRW+NDOXy4LbDMg017idlLqwlUo6U= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7D2B4180004 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=YI5GTSYV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yug+nQgG; dmarc=none; spf=pass (imf06.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Stat-Signature: jwa7skiumiaz9f9763h81131coarptkp X-HE-Tag: 1666778900-607998 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 10/26/22 12:02, Vlastimil Babka wrote: > 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 Ah and since the subject was updated too, note this is supposed to replace/fixup the patch in mm-unstable: mempool-use-kmalloc_size_roundup-to-match-ksize-usage.patch >> --- >> 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); >