Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36918624rwd; Tue, 11 Jul 2023 07:18:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlHUDj8YwDZDHVY7oVEgNoq93m/Bvd1g1U8IQD5sInb6JK+4f+5L+iYtZgfvyT0mVsOmVUlH X-Received: by 2002:a17:906:142:b0:992:2f67:cd2e with SMTP id 2-20020a170906014200b009922f67cd2emr16059695ejh.48.1689085096409; Tue, 11 Jul 2023 07:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689085096; cv=none; d=google.com; s=arc-20160816; b=s8epaU2xjwTVY6AeO1Ps3zbFDhXyIFsvQ1ALLiIaRlAN80jvDWigEWgvQRlK6WRPM6 jyI57WtjQE2rhGO15Fbkg4EHAYsXdv3JO8GpPwJ1oAYBkr7/GhAPRfqp3hHV40rRQBUE HGMQvSHlKN2K6IptHJd9bZISOSi4o60HeklKc4P5ChSrBGcGgSUqdIJaMZjn9IILCLZR VruoGAfWSvICkzozoaroEuveeRovRpuGFixvgctucqKqN85w4mMW/l4xyDt7nbIVbTv9 npTfnOCMZ/xCb+iZ8cGsAs3lv7tmcs8DWdQ3JH7c7nxwAXIec0xaW/AzAMqz2jwJFzt1 ZDUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=RXHIYdVmdQJX5tnkNjy37yeBssRnaU5MoOmNGkfF484=; fh=5wkMzutboah3mIJLA2vngQ+rKosaYb0XpIOjNELWSA0=; b=eWlvmOIxOU+6Soxz+ZKxvzbUkZOaqVoLhxHDDZkS1cCFPOtUVawGUKoHzK0q2PcXXE RMci3v9LaYaaUQWuLdLnBGW22STKJVhTOI8XwRmgytkQ/ueUb3Q7qE4CcnJ6WTtsHOFM cya1u2otbJIWbTZKJt+abuJUMioCal3dEyiCKUxviDyBHMH+fygTkFS7QXUH3fRZ665X PSuYECE2Wb4KEvCJUtcNmIkOqK+0kZxtAznVcDv5Q6A3Wto1dkrE+/X89MqPuI821dsP MZL1Ppxg4JRFOaKor94y1/XZ9uGJCipQWij94gcoHKhRW8Rd3nvTz4ZuNZmNw5g+RBB0 wUQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=DVO93ktx; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=EJTlIqxl; 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 v7-20020a170906338700b009934b1eb56dsi1920196eja.11.2023.07.11.07.17.52; Tue, 11 Jul 2023 07:18:16 -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=DVO93ktx; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=EJTlIqxl; 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 S230195AbjGKNqm (ORCPT + 99 others); Tue, 11 Jul 2023 09:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjGKNqi (ORCPT ); Tue, 11 Jul 2023 09:46:38 -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 71D12E6A; Tue, 11 Jul 2023 06:46:36 -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 0FF911FDA0; Tue, 11 Jul 2023 13:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1689083195; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=RXHIYdVmdQJX5tnkNjy37yeBssRnaU5MoOmNGkfF484=; b=DVO93ktxjFk3VzkffNtwh1rU0QfweANLsy9oVYvFPGIeNVcpRdrrIpFNYcej2rYKY7sNDM bKjN4dQau8CtiYI7D6FON8xDb/M5h8wTke2ei4xM5jMAt+o+bwDX12JNsoetppguRUTmiI 3TOWlE4qXwwHHyr5h/3JYzS4DmEamL4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1689083195; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=RXHIYdVmdQJX5tnkNjy37yeBssRnaU5MoOmNGkfF484=; b=EJTlIqxlmAlFa+9Nk7qpsjsA6kWKHmE0gNx/pb6blh/Evb+jPLWa82Nz2lgRY5oF1+D5vB AEpWeIfOau7q79BA== 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 C1D2D1390F; Tue, 11 Jul 2023 13:46:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NXqMLjpdrWTSYwAAMHmgww (envelope-from ); Tue, 11 Jul 2023 13:46:34 +0000 From: Vlastimil Babka To: Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, Matteo Rizzo , Jann Horn , Andrey Konovalov , Marco Elver , Alexander Potapenko , kasan-dev@googlegroups.com, Kees Cook , linux-hardening@vger.kernel.org, Vlastimil Babka Subject: [PATCH 1/2] mm/slub: remove redundant kasan_reset_tag() from freelist_ptr calculations Date: Tue, 11 Jul 2023 15:46:24 +0200 Message-ID: <20230711134623.12695-3-vbabka@suse.cz> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 Commit d36a63a943e3 ("kasan, slub: fix more conflicts with CONFIG_SLAB_FREELIST_HARDENED") has introduced kasan_reset_tags() to freelist_ptr() encoding/decoding when CONFIG_SLAB_FREELIST_HARDENED is enabled to resolve issues when passing tagged or untagged pointers inconsistently would lead to incorrect calculations. Later, commit aa1ef4d7b3f6 ("kasan, mm: reset tags when accessing metadata") made sure all pointers have tags reset regardless of CONFIG_SLAB_FREELIST_HARDENED, because there was no other way to access the freepointer metadata safely with hw tag-based KASAN. Therefore the kasan_reset_tag() usage in freelist_ptr_encode()/decode() is now redundant, as all callers use kasan_reset_tag() unconditionally when constructing ptr_addr. Remove the redundant calls and simplify the code and remove obsolete comments. Also in freelist_ptr_encode() introduce an 'encoded' variable to make the lines shorter and make it similar to the _decode() one. Signed-off-by: Vlastimil Babka --- These 2 patches build on top of: https://lore.kernel.org/all/20230704135834.3884421-1-matteorizzo@google.com/ mm/slub.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index f8cc47eff742..07edad305512 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -374,22 +374,14 @@ typedef struct { unsigned long v; } freeptr_t; static inline freeptr_t freelist_ptr_encode(const struct kmem_cache *s, void *ptr, unsigned long ptr_addr) { + unsigned long encoded; + #ifdef CONFIG_SLAB_FREELIST_HARDENED - /* - * When CONFIG_KASAN_SW/HW_TAGS is enabled, ptr_addr might be tagged. - * Normally, this doesn't cause any issues, as both set_freepointer() - * and get_freepointer() are called with a pointer with the same tag. - * However, there are some issues with CONFIG_SLUB_DEBUG code. For - * example, when __free_slub() iterates over objects in a cache, it - * passes untagged pointers to check_object(). check_object() in turns - * calls get_freepointer() with an untagged pointer, which causes the - * freepointer to be restored incorrectly. - */ - return (freeptr_t){.v = (unsigned long)ptr ^ s->random ^ - swab((unsigned long)kasan_reset_tag((void *)ptr_addr))}; + encoded = (unsigned long)ptr ^ s->random ^ swab(ptr_addr); #else - return (freeptr_t){.v = (unsigned long)ptr}; + encoded = (unsigned long)ptr; #endif + return (freeptr_t){.v = encoded}; } static inline void *freelist_ptr_decode(const struct kmem_cache *s, @@ -398,9 +390,7 @@ static inline void *freelist_ptr_decode(const struct kmem_cache *s, void *decoded; #ifdef CONFIG_SLAB_FREELIST_HARDENED - /* See the comment in freelist_ptr_encode */ - decoded = (void *)(ptr.v ^ s->random ^ - swab((unsigned long)kasan_reset_tag((void *)ptr_addr))); + decoded = (void *)(ptr.v ^ s->random ^ swab(ptr_addr)); #else decoded = (void *)ptr.v; #endif -- 2.41.0