Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp23964rdg; Tue, 10 Oct 2023 03:11:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFmnPnI3oqK1ae64wEQp3I9F9eT0TYOb7sDpYRVD6WYuL3e1RV3cbZmDncWv0ndktfeIo+ X-Received: by 2002:a17:90b:3a89:b0:279:9265:725c with SMTP id om9-20020a17090b3a8900b002799265725cmr15666147pjb.5.1696932691482; Tue, 10 Oct 2023 03:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696932691; cv=none; d=google.com; s=arc-20160816; b=ctqlszkfB33IgtxzmsvVm37gd3ji2edq4eSfCq/sEKSj/JLCPgxouUKS0bPMRHw8Xu nd87JiB8KmG98LEOLzdLPsCl9H1DupC47DaehHLl60E/MYXezqzGE6oYbB26ULPsM1L+ ADJuX8RsZQgnXiHdswc5o8OT3ALC/Ytd1ssdNHtQfyNwr5QZajNyhTf9PX6jBYXrjelS 6z/fGOBHHGF8z2QpsyJhn5xlpY9bsWWiAqAvt85N/NAcwanNKsGAfgn7q9I9+gAaBgCj CkR/gq0bLRWxe+lRJkvOjWEQ66Zot38az1ykHc66VgtttztJjeSP8vIeHsUZuDNk1gCf SdnA== 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=oj1axhxOjginGEELIsLjRAtpZ1XYE8QEYtnImm9KFkM=; fh=mUf2ndWDL5c84ldV6DszTy3j42/aMLRyYOLwUcEDGhM=; b=LRlr0krsQ1W3x+Oo+vYGvxxgIaQo+xOGkmNuyX2rlnsFVWqil+onvqH4YEW+e4oczB qC/9VG/B0qmpvZDu8NlnC0z4OUOjjXeK7Ro6JbjVUGwfGv1sp9FZCifL/vHoiuApriNf ZOFkdI9vZA2pdU/LTjYyc+WWViKsihnwoGdUqByikmVqr6jGUWByUN0FE1QzgzZFV5xu x8kvtd3BqmfX5Nwn0mhxAdMPun2Mjlc3TrPE1te+iUNpEM3adtklLMJasja/I5PPr4JW mP1Sq01f05DU9h7nRKXRDacVvcjSj6wT3GjRPzpNMjebJRs9BLIr9qqkRwar0atngRdz 9WeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=gYdO8iqa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id a17-20020a17090abe1100b00277277fd2besi11519183pjs.190.2023.10.10.03.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 03:11:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=gYdO8iqa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id E79ED81444E1; Tue, 10 Oct 2023 03:11:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230125AbjJJKLX (ORCPT + 99 others); Tue, 10 Oct 2023 06:11:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbjJJKLW (ORCPT ); Tue, 10 Oct 2023 06:11:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2052893; Tue, 10 Oct 2023 03:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=oj1axhxOjginGEELIsLjRAtpZ1XYE8QEYtnImm9KFkM=; b=gYdO8iqarQxLHjF7YnORu/ND3n P8Gxkb0rRc1yB37HNKOontKt/9J1jFpVLPPKbEh8Fo31wpLqgJgonUdDmliPmWek0TAKzExJy0pEF 5+BXZCjaTVlX/CwrnMr7nYJ2ZTe7pqq09H8khWEzMP1ob1y57ZotrnJWyYaH1haO5lesiBo95gcED bLNR5ra69pGgy3tbU6IoomsDUHVQCIErONjFJRzX17lUk36DVty7sCzUjpdyjC7HkGE6zM2fVrOwY sZvCBJPxkTQX8xY9qBpODLXVuEEkgcwwgiZfYVswiFF1UqaRAVEjrwt5jxYOLLQJCTz2Lz+wViC21 MGvlPphg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qq9hY-0040qP-NX; Tue, 10 Oct 2023 10:10:57 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 63DD1300392; Tue, 10 Oct 2023 12:10:56 +0200 (CEST) Date: Tue, 10 Oct 2023 12:10:56 +0200 From: Peter Zijlstra To: Borislav Petkov Cc: "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , 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: [PATCH] x86/alternatives: Disable KASAN on text_poke_early() in apply_alternatives() Message-ID: <20231010101056.GF377@noisy.programming.kicks-ass.net> 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=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 10 Oct 2023 03:11:28 -0700 (PDT) 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). > > > It seems that KASAN gets confused when apply_alternatives() patches the > > It seems? > > > 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... somewhere along the line __asan_loadN() gets tripped, this then ends up in kasan_check_range() -> check_region_inline() -> addr_has_metadata(). This latter has: kasan_shadow_to_mem() which is compared against KASAN_SHADOW_START, which includes, as Kirill says __VIRTUAL_MASK_SHIFT. Now, obviously you really don't want boot_cpu_has() in __VIRTUAL_MASK_SHIFT, that would be really bad (Linus recently complained about how horrible the code-gen is around this already, must not make it far worse). Anyway, being half-way through patching X86_FEATURE_LA57 thing *are* inconsistent and I really can't blame things for going sideways. That said, I don't particularly like the patch, I think it should, at the veyr least, cover all of apply_alternatives, not just text_poke_early().