Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3240688rdg; Tue, 17 Oct 2023 08:32:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcDpG400HsoXcFoQjwH0QEjefnKu68hDJPApwUdZ0e+DU1IUSCKwdMvXXp4y0vC7vGcsVh X-Received: by 2002:a17:902:f550:b0:1ca:8541:e1ea with SMTP id h16-20020a170902f55000b001ca8541e1eamr3158393plf.0.1697556755771; Tue, 17 Oct 2023 08:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697556755; cv=none; d=google.com; s=arc-20160816; b=EyBNksV6fi98pyd6hsq5oSSEKFGhwUpwUASaGvBdepHl4ebsJvjSUwVtNUF2Fxppaa 0c2xLf5+Zp7xyAB5s/SsSIo0bFgAg8ImqzrDAHbezjpFSNSiQbcEXkVwrmSEFKI48sKS gN7Xs5LaAf5cKI/N07xLlmbuuustc+j7yg7uo++gyTlJev6wvkCuaW87w5R2zz/e4xSY n+bWJcl9+iw4Dk44knYrkDg58PSTHbml5AlqYt6nUzlyBlKpKxSGrPivMXph1UAhbBCV LYtVKcFbhXvO4282wsXcVfPNx1n84Wmt90+f0gjCDLdxd264eEhD6zCihVxRza91zbg5 C/gg== 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=7mV3xw9t5Za9HpeoYKVbLOgk3q6fvbFCqTdtB4DJPcA=; fh=/aWmG7eUVQSWeemDG3dMYKxJWfhW0TTVH9zsisI0Gn4=; b=hJJCrbnaz1RREEbj+uQ4eu0Lj3spjJImD4R/z7b1lEcUcTvaiZ1+m59fl+bBAul/bW +uEpvJxbpTapbsh3zgnOjESkzJno6xUnSemdxLOeoOCDJ63P5Y8Wdq+ud2IJjlUyOBHP FnvPTE4w/hT8MLRxUOAkIpVUb5QJC2ERZBaGrYtmfeO934c4Im1lfUa+Vo3SF+2BBH5m 9deQIDs764N6AnVvdqseyyyciBp7Wbq1MT8kLG+prIQEnFBLNxn4EYnmJN2BQZLOxESl beKHcfFIB13FNNVPzxK8ClESwRab7+HocQEewGJ7OgpHuvlrAwlhs+x7Fbwt5DWJKfX/ vmuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gOjHqgEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id kx14-20020a170902f94e00b001c9ff840285si1914731plb.414.2023.10.17.08.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 08:32:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gOjHqgEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 848E980254CB; Tue, 17 Oct 2023 08:32:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344175AbjJQPc2 (ORCPT + 99 others); Tue, 17 Oct 2023 11:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJQPc0 (ORCPT ); Tue, 17 Oct 2023 11:32:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D16292; Tue, 17 Oct 2023 08:32:25 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61EBDC433C8; Tue, 17 Oct 2023 15:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697556744; bh=gEjMKkoJZQgKHA815iyJtPqk+ih8igqa9RyW+EN97CE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gOjHqgEIBPUKbXerOqT4j3GgldYb+fLWbr/jxY2/CGAsZVBJellxxATXsMp0TLFOr v7DueZntYAQQdRmuDg05xw+zEcIsGnVfL0t2k9RoZV3rPTiWvf3rrOcDWN+Dq5ZN2w hTlffSw8MCOHdD8iLUJgRSW/Kb31gGwK9w3+yZRgwNwGQ7zBjZSYadSVHWzIWZZxGF 3P+63BnLCNyqHko13Pdsinh1akIWIeLqUrLNmTnfCr+ue/8bZ+bESAkhdln+oJOEVD M1nAXIw6WEqP0qBhZnp/fSh0RfvyhG+iZxLEsE8lipGQPYpEJ9WjeFPwkRAKGkqbQG wprIGMwCwOz1g== Date: Tue, 17 Oct 2023 08:32:22 -0700 From: Nathan Chancellor To: Josh Poimboeuf Cc: "Kaplan, David" , Borislav Petkov , "linux-kernel@vger.kernel.org" , "linux-tip-commits@vger.kernel.org" , Ingo Molnar , "Peter Zijlstra (Intel)" , "x86@kernel.org" , "llvm@lists.linux.dev" Subject: Re: [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime Message-ID: <20231017153222.GA707258@dev-arch.thelio-3990X> References: <20231012141031.GHZSf+V1NjjUJTc9a9@fat_crate.local> <169713303534.3135.10558074245117750218.tip-bot2@tip-bot2> <20231016211040.GA3789555@dev-arch.thelio-3990X> <20231016212944.GGZS2rSCbIsViqZBDe@fat_crate.local> <20231016214810.GA3942238@dev-arch.thelio-3990X> <20231017052834.v53regh66hspv45n@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231017052834.v53regh66hspv45n@treble> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 08:32:33 -0700 (PDT) On Mon, Oct 16, 2023 at 10:28:34PM -0700, Josh Poimboeuf wrote: > On Tue, Oct 17, 2023 at 04:31:09AM +0000, Kaplan, David wrote: > > I think I found the problem, although I'm not sure the best way to fix it. > > > > When KCSAN is enabled, GCC generates lots of constructor functions named _sub_I_00099_0 which call __tsan_init and then return. The returns in these are generally annotated normally by objtool and fixed up at runtime. But objtool runs on vmlinux.o and vmlinux.o does not include a couple of object files that are in vmlinux, like init/version-timestamp.o and .vmlinux.export.o, both of which contain _sub_I_00099_0 functions. As a result, the returns in these functions are not annotated, and the panic occurs when we call one of them in do_ctors and it uses the default return thunk. > > > > This difference can be seen by counting the number of these functions in the object files: > > $ objdump -d vmlinux.o|grep -c "<_sub_I_00099_0>:" > > 2601 > > $ objdump -d vmlinux|grep -c "<_sub_I_00099_0>:" > > 2603 > > > > If these functions are only run during kernel boot, there is no speculation concern. My first thought is that these two object files perhaps should be built without -mfunction-return=thunk-extern. The use of that flag requires objtool to have the intended behavior and objtool isn't seeing these files. > > > > Perhaps another option would be to not compile these two files with KCSAN, as they are already excluded from KASAN and GCOV it looks like. > > I think the latter would be the easy fix, does this make it go away? Tested-by: Nathan Chancellor Thanks for figuring this out! > diff --git a/init/Makefile b/init/Makefile > index ec557ada3c12..cbac576c57d6 100644 > --- a/init/Makefile > +++ b/init/Makefile > @@ -60,4 +60,5 @@ include/generated/utsversion.h: FORCE > $(obj)/version-timestamp.o: include/generated/utsversion.h > CFLAGS_version-timestamp.o := -include include/generated/utsversion.h > KASAN_SANITIZE_version-timestamp.o := n > +KCSAN_SANITIZE_version-timestamp.o := n > GCOV_PROFILE_version-timestamp.o := n > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux > index 3cd6ca15f390..c9f3e03124d7 100644 > --- a/scripts/Makefile.vmlinux > +++ b/scripts/Makefile.vmlinux > @@ -19,6 +19,7 @@ quiet_cmd_cc_o_c = CC $@ > > ifdef CONFIG_MODULES > KASAN_SANITIZE_.vmlinux.export.o := n > +KCSAN_SANITIZE_.vmlinux.export.o := n > GCOV_PROFILE_.vmlinux.export.o := n > targets += .vmlinux.export.o > vmlinux: .vmlinux.export.o