Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3321950rdg; Tue, 17 Oct 2023 10:52:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjBddUcqbWeOCYu30iNf52nXqbX6z84/HoLBZFs4MiNVvDiqocfihnZLW54NUpcP1WDtJJ X-Received: by 2002:a05:6a00:218f:b0:68a:54e5:24e6 with SMTP id h15-20020a056a00218f00b0068a54e524e6mr3263450pfi.8.1697565171261; Tue, 17 Oct 2023 10:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697565171; cv=none; d=google.com; s=arc-20160816; b=bM9Mdzrg6ctjbUjQ5VTKmsSW+B1yQXcZhjUbBxE1rEMmKy/mGVlwjibZl3SYbqwNxk FIm19G3CxQyucEoaflaqXC7he0B+J+2c4jSNTZLEWmTCLOLbaLkKFi9DpmW8yVS0X7LJ w3bPlljbAiN95lxjDNDmmf2M+byU949ZsJp/wbcXWtxdbshPpB5AnMwgL1vl0OeqGHqH 5DL86jtU/Alv5Gp2TtSMJeCb5RXyjhp8lBzmjR7uoiQeRm+ix/P9rG4MtSCJCaVlH/IO 20+rI7OU2xton5fBnB/7pwJvZIOqnQhobPiRnhkKSFEBIeB7uNKk0MeOy8jx1Lb8tAKE y1sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=6QO7THutm9DbzDFqvBo8CeUszTWk5DcsXoee7Ok6T8A=; fh=pt0k4uCyojabaO/abXkeDeTWofuEzJ+wukq1sHzP004=; b=KUe0aCL/52SXdGOxaZRfaCwxT0F4cB583QdFxHxU11KFeUuPNHFmiROcE8Yzg1Agu1 rcdJiqEhH3xNV2npdHXNGBFDBSr8lj3u0GWzfVTFpYdJlQD2+7hMhAexTngyue6xPOB9 ZhUo5PLSIuHTc1Uy3BuBfnfNnELlY8liSojQF+jX+TyXuvNaZw0WBS9fnshtmHkbdfbA pz0z2PTuzhjQSnje70NYqlWRncPQJd/yJyB6ihJQ+26b8qd65GsWJQbaU9Z0Z/xzJzpc Ts6Wfor0O/wu/HJrt7A3DaiD2niNg8vKYIfgh3yd1dz/rQzsp9/LzXhp5nNzOa6EPql3 uQCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oPfwVabj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="Y/BqD6Pe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x15-20020aa7956f000000b006be5a6cd3f3si1984353pfq.285.2023.10.17.10.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 10:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oPfwVabj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="Y/BqD6Pe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 4C201805F2EC; Tue, 17 Oct 2023 10:52:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbjJQRwd (ORCPT + 99 others); Tue, 17 Oct 2023 13:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbjJQRwc (ORCPT ); Tue, 17 Oct 2023 13:52:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD7190; Tue, 17 Oct 2023 10:52:30 -0700 (PDT) Date: Tue, 17 Oct 2023 17:52:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697565148; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6QO7THutm9DbzDFqvBo8CeUszTWk5DcsXoee7Ok6T8A=; b=oPfwVabj4mW8EPgc5AFNhLZFbW0ejqgqBMimVX7IJc56hO1syU0gQrIgpGGhhHHqBCeDUp 3cTNVxAzWyXbnuWF7RWuEYf9wj38rVTLio4mVKuPyF5Iog+ddyYbplcrrsVeBxqUYfDgnQ b+dMu7jnaH4E408vOwF2zD+TjvZrJ9borL2b6xcM7SB0W2uPlMPJFjW0Lhu/5mT2p6QihK Tbukq3QF/+AgphxyQZX8gWEI8/LqCtg2RLIM6QqnA281cgUAu9SCiP+zmGgObochO/dlpx yCXTaJ8yacQMaz9ANA2kUwYwY4cY7zzwccXkyqFiIj6Vxa+J3lk6D1AKlvZh8w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697565148; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6QO7THutm9DbzDFqvBo8CeUszTWk5DcsXoee7Ok6T8A=; b=Y/BqD6PeQzzmg4hdzlsMQ+V3wbWrXeoNcMwBQsMYiTInE/hpKu49yAZLIeXe3qLo13q+Hk HUgd6aA42rG7UJCA== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/bugs] x86/retpoline: Make sure there are no unconverted return thunks due to KCSAN Cc: Nathan Chancellor , Josh Poimboeuf , "Borislav Petkov (AMD)" , Nick Desaulniers , Marco Elver , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231017165946.v4i2d4exyqwqq3bx@treble> References: <20231017165946.v4i2d4exyqwqq3bx@treble> MIME-Version: 1.0 Message-ID: <169756514789.3135.9006141912388432463.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 17 Oct 2023 10:52:48 -0700 (PDT) The following commit has been merged into the x86/bugs branch of tip: Commit-ID: 28860182b7d88e5be76f332c34377288ad08e87a Gitweb: https://git.kernel.org/tip/28860182b7d88e5be76f332c34377288ad08e87a Author: Josh Poimboeuf AuthorDate: Tue, 17 Oct 2023 09:59:46 -07:00 Committer: Borislav Petkov (AMD) CommitterDate: Tue, 17 Oct 2023 19:46:04 +02:00 x86/retpoline: Make sure there are no unconverted return thunks due to KCSAN Enabling CONFIG_KCSAN causes the undefined opcode exception diagnostic added by 91174087dcc7 ("x86/retpoline: Ensure default return thunk isn't used at runtime") which is supposed to catch unconverted, default return thunks, to fire. The resulting panic is triggered by the UD2 instruction which gets patched into __x86_return_thunk() when alternatives are applied. After that point, the default return thunk should no longer be used. As David Kaplan describes in his debugging of the issue, it is caused by a couple of KCSAN-generated constructors which aren't processed by objtool: "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." Fix it by disabling KCSAN on version-timestamp.o and .vmlinux.export.o so the extra functions don't get generated. KASAN and GCOV are already disabled for those files. [ bp: Massage commit message. ] Fixes: 91174087dcc7 ("x86/retpoline: Ensure default return thunk isn't used at runtime") Closes: https://lore.kernel.org/lkml/20231016214810.GA3942238@dev-arch.thelio-3990X/ Reported-by: Nathan Chancellor Signed-off-by: Josh Poimboeuf Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Nick Desaulniers Acked-by: Marco Elver Tested-by: Nathan Chancellor Link: https://lore.kernel.org/r/20231017165946.v4i2d4exyqwqq3bx@treble --- init/Makefile | 1 + scripts/Makefile.vmlinux | 1 + 2 files changed, 2 insertions(+) diff --git a/init/Makefile b/init/Makefile index ec557ad..cbac576 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 3cd6ca1..c9f3e03 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