Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2370865rdb; Tue, 10 Oct 2023 01:41:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMg5p13GBz9fTI25Ub5Sa+pqKNJ0bsY1jqzsHwRhPdOVGpSoDx93VednzNk1IJBRJmDhZZ X-Received: by 2002:a05:6808:d48:b0:3a9:9bcb:8760 with SMTP id w8-20020a0568080d4800b003a99bcb8760mr22524271oik.39.1696927297455; Tue, 10 Oct 2023 01:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696927297; cv=none; d=google.com; s=arc-20160816; b=aHgzA4jy+HxjkyBm8zGl0rtbs73iWVjOXxOXb5x7jJO9n1exYeZGoz/8jaAMTWUeqH MZ9iXIpMrHOrsavRfUPBhydwI03IkN7ZErXkHblZAh3nmsJO4zo2byJ3j15j4rl8r/TH APVwQ9ZhWevi3NmBN7eZ1GTk0eRnRKn3SuhLegXBPP8creq8iZBAZ8GQhnGPbFt6RQce XwLaZAQVSTdzgVt8gxGfF/xCJMdc5Ne9rvOdv8Uu0NC64V0bgZVsv73zyNiXhQkBfWNk 3o7ubejW80Ev+4Hgoc+1AFsIJPTnwfXqM8flGzZXmC9FcLuOHMbgIdDpslR65M+VyMrJ 7sPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9yvMgqoPGHCM1ICdduxR2Gz0ugbAZLayCGVR1FAVNkI=; fh=Humky4e+hth+m5LjjwqZefHA/L96cUXUrx8t/v+3zX4=; b=AlYRZ9EjCnXr5rFQxc1hS2WB97VwkWoocfFwzcnSlWgoh3Zk2WlJDeYLmkYw64H9I+ TeCdQEiqVXvJY9nb3OWCKUkciCf+yStpxeRseMgjLPwugt4zm4faEobFBCCWwGghWgNJ 1BNFw4JlibbMrZp9Wvryzb2UYsh0/AAOiN04zIsKtfsH07RTly9qyQTZTdCKkhnWylXr 6lse3mryAh8cZ5EmmEx29W6mrfGPYGyVH+RJqTuv+4GRS+zCEIUQw1q98O8uDyvOVI2U GNJCD+0/1/OXpDsF2Ivz2dfK+cH2JP5nZQAV3pEUt37vsF48oiIKDepaFLVdhZPPt9tC HwUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aGywAkpn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c6-20020a6566c6000000b0056a290addadsi11271160pgw.787.2023.10.10.01.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aGywAkpn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 63517808D4B1; Tue, 10 Oct 2023 01:41:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229487AbjJJIlD (ORCPT + 99 others); Tue, 10 Oct 2023 04:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjJJIkw (ORCPT ); Tue, 10 Oct 2023 04:40:52 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B03A4; Tue, 10 Oct 2023 01:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696927250; x=1728463250; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Q/HQZfWfUh0bAp2HPigWMWS7Bdx/WkAzNBzfM90GuJU=; b=aGywAkpnWqe7PtgnuIWmGgcKcmCupCpoWwg+SpWRIVIp6CH9+SbgUZej R1Pc4iBygfltGOZGfIad5N2q/7K2NWSmFeBYA0v7v2yq38n8iGAFCrc7Q Tpd600NMIVEUQgetQDtt/dqBzozpFHB47fdB2gV8Ycc+NLDdl63Tv7DMy dkKEGnhNv7gPYw+c3oGQAl5Ixe4hvyfAQP7xQIiCLq0ParvdcNkSFeKzH vK04NDivZbBjKzYqvke9P5HiVBCofla4utM/tZezcBbKIRSPoAYeGo7C4 udbDkmxyWzkCfo1AK2ddeiRjJ0+FCOBRXWKK4+/9YDKbv9G1dh4N9AKQW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="383220527" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="383220527" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 01:40:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="927059933" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="927059933" Received: from albertmo-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.208.38]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 01:40:45 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id CC6FC10A1A3; Tue, 10 Oct 2023 11:40:41 +0300 (+03) Date: Tue, 10 Oct 2023 11:40:41 +0300 From: "Kirill A. Shutemov" To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , Peter Zijlstra , x86@kernel.org, "H. Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Fei Yang , stable@vger.kernel.org Subject: Re: [PATCH] x86/alternatives: Disable KASAN on text_poke_early() in apply_alternatives() Message-ID: <20231010084041.ut5sshyrofh27yyx@box.shutemov.name> References: <20231010053716.2481-1-kirill.shutemov@linux.intel.com> <20231010081938.GBZSUJGlSvEkFIDnES@fat_crate.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231010081938.GBZSUJGlSvEkFIDnES@fat_crate.local> X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 10 Oct 2023 01:41:33 -0700 (PDT) X-Spam-Level: ** On Tue, Oct 10, 2023 at 10:19:38AM +0200, Borislav Petkov wrote: > On Tue, Oct 10, 2023 at 08:37:16AM +0300, Kirill A. Shutemov wrote: > > On machines with 5-level paging, cpu_feature_enabled(X86_FEATURE_LA57) > > got patched. It includes KASAN code, where KASAN_SHADOW_START depends on > > __VIRTUAL_MASK_SHIFT, which is defined with the cpu_feature_enabled(). > > So use boot_cpu_has(X86_FEATURE_LA57). __VIRTUAL_MASK_SHIFT used in many places. I don't think it is good idea to give up on patching completely. > > It seems that KASAN gets confused when apply_alternatives() patches the > > It seems? Admittedly, I don't understand KASAN well enough. I confirmed my idea indirectly, by patching KASASN_SHADOW_START, as I mentioned. > > KASAN_SHADOW_START users. A test patch that makes KASAN_SHADOW_START > > static, by replacing __VIRTUAL_MASK_SHIFT with 56, fixes the issue. > > > > During text_poke_early() in apply_alternatives(), KASAN should be > > disabled. KASAN is already disabled in non-_early() text_poke(). > > > > It is unclear why the issue was not reported earlier. Bisecting does not > > help. Older kernels trigger the issue less frequently, but it still > > occurs. In the absence of any other clear offenders, the initial dynamic > > 5-level paging support is to blame. > > This whole thing sounds like it is still not really clear what is > actually happening... Maybe KASAN folks can help to understand the situation. -- Kiryl Shutsemau / Kirill A. Shutemov