Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp640067rdg; Wed, 11 Oct 2023 00:47:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrlyXJ0BRbCEG7TIbzo+0RIpfYRk5WXffW1x57xCwVBaObTp0k3tl2Z5qlPqSAbVb6OEU3 X-Received: by 2002:a05:6a00:2d10:b0:68f:ea5d:1f70 with SMTP id fa16-20020a056a002d1000b0068fea5d1f70mr23478630pfb.14.1697010420774; Wed, 11 Oct 2023 00:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697010420; cv=none; d=google.com; s=arc-20160816; b=ka3rqwin7sDxrsZWo/IzVjOyl3UXHPxoLjjL9J/YJ8q5ib6k4uVuSfKzh9jp9Gtlty fDQCGqyyZNRAfd62yAZnblG3Btex/J7699lm85ZTEIYCynif6LC3Mncp0rt0Ioo9TBUf ZFO9BJfaIIm26gjNQYIZ9HEgeb9fW1MbFWZ/0jmAbELG/+ZspwHjBOmW3rqMdP8FZT7g Yp7d7YEH8Rv2uw4e6y1UQMyf5y/jBj24XB30h3kUFg+WzeDux/4Io9qlf+4L7DiWnkr5 PJxGybzLEGj9+I+oflEBqniEtbq/NX0So0V3+RuUg51isFwk+JvT1YvPZhYmhav4lDBb yyTQ== 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=61isM1aH9tWSRneo34EFdKetusAPfy8ZA6xHY6hutnw=; fh=0jdiGLdX2nZnZBw7jbPihs/xBeWIj01/5aUTE880zHw=; b=IAAyaAwgeygNdzBSzAMhHpuuqKSYHfSuD1U7KbxdCxZmxJY+sioabOwvD/5JW1yXec l7jw0rCVA00se848Pv0im0u6f11fhKL4Je68fqDd1ofYcsu7zN9A9hVorV04izQsoAKM vGadHzEm/Li7uDz3V1f4byILnIgyt0RNngb4R5Rez1bK8/UC/sk7t6tvSTfJjUsdR+n5 9VzTdL+3GFJyCEHyhB12CR6jWO1WDsoJjmQMk/UFghDDNs1li8Vkatnp3USQQJ2lILRX 9U7Nuc9MbxnVBiMJWt9a3ZhL8NKUpPXUQSchYJ1BePvl+EXZ7YY82kv5JwEl3sauXoRK AMww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=jwICPp03; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id w8-20020a63f508000000b00563d791d978si13794088pgh.750.2023.10.11.00.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 00:47:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=jwICPp03; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 539828025AC5; Wed, 11 Oct 2023 00:46:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345091AbjJKHqt (ORCPT + 99 others); Wed, 11 Oct 2023 03:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjJKHqr (ORCPT ); Wed, 11 Oct 2023 03:46:47 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3493698; Wed, 11 Oct 2023 00:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=61isM1aH9tWSRneo34EFdKetusAPfy8ZA6xHY6hutnw=; b=jwICPp03S1haGCDCXZYFoqMdLe UZE55NvzirG/CnXpvK74lkt1+aTJ+Hpj6G1mvD78sldy+GA7sVz049I77lzzAcgQs23H9CbmlSB93 ponfAMWWkDcR9DhNf4HvWxIInj4lJ+fBuvqKGuUDEe3b62skraMBN9LMonbIKmBi3fG9CI0ryGGiO aR87ynqpq7vCJX7c68nAxbdpMe/3IllqQt8qSbJJE5Yuuxg3hYS2pyjRqwhBK1MX+kzeGPecC47yK VFrOqlCUvwsJI8dpDAytuOFO2qsYdM7MsI0m4j1VSCrAuDAOwQ0Gj9uQ5mDxss4V7D9DNd0iGgQ44 2SlbY4DA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qqTv5-0003uD-0t; Wed, 11 Oct 2023 07:46:17 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 63E7530026F; Wed, 11 Oct 2023 09:46:16 +0200 (CEST) Date: Wed, 11 Oct 2023 09:46:16 +0200 From: Peter Zijlstra To: "Kirill A. Shutemov" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , 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: [PATCHv2] x86/alternatives: Disable KASAN in apply_alternatives() Message-ID: <20231011074616.GL14330@noisy.programming.kicks-ass.net> References: <20231011065849.19075-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231011065849.19075-1-kirill.shutemov@linux.intel.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 00:46:58 -0700 (PDT) X-Spam-Level: ** On Wed, Oct 11, 2023 at 09:58:49AM +0300, Kirill A. Shutemov wrote: > Fei has reported that KASAN triggers during apply_alternatives() on > 5-level paging machine: > Urgh @ KASAN splat, can't we summarize that? > > 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(). > > KASAN gets confused when apply_alternatives() patches the > KASAN_SHADOW_START users. A test patch that makes KASAN_SHADOW_START > static, by replacing __VIRTUAL_MASK_SHIFT with 56, fixes the issue. > > Disable KASAN while kernel patches alternatives. > > Signed-off-by: Kirill A. Shutemov > Reported-by: Fei Yang > Fixes: 6657fca06e3f ("x86/mm: Allow to boot without LA57 if CONFIG_X86_5LEVEL=y") > Cc: stable@vger.kernel.org > --- > > v2: > - Move kasan_disable/_enable_current() to cover whole loop, not only > text_poke_early(); > - Adjust commit message. > > --- > arch/x86/kernel/alternative.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c > index 517ee01503be..b4cc4d7c0825 100644 > --- a/arch/x86/kernel/alternative.c > +++ b/arch/x86/kernel/alternative.c > @@ -403,6 +403,17 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start, > u8 insn_buff[MAX_PATCH_LEN]; > > DPRINTK(ALT, "alt table %px, -> %px", start, end); > + > + /* > + * In the case CONFIG_X86_5LEVEL=y, KASAN_SHADOW_START is defined using > + * cpu_feature_enabled(X86_FEATURE_LA57) and is therefore patched here. > + * During the process, KASAN becomes confused and triggers because of partial LA57 convertion .. > + * a false-positive out-of-bound report. > + * > + * Disable KASAN until the patching is complete. > + */ > + kasan_disable_current(); > + > /* > * The scan order should be from start to end. A later scanned > * alternative code can overwrite previously scanned alternative code. > @@ -452,6 +463,8 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start, > > text_poke_early(instr, insn_buff, insn_buff_sz); > } > + > + kasan_enable_current(); > } Other than that, ACK.