Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp843267lqe; Sun, 7 Apr 2024 06:34:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWNvnL3lRM8Z9kVrZAzpzwzhGCKEmFvO6dVWVCT5uezKPqeOi9uuJWcGd+4hh3YzHUKVV7PmZWOdhBDXC5yYem2GOUM5CQfzdPgELad5A== X-Google-Smtp-Source: AGHT+IHxn9YlL4hUnAGKiWRPhFkDZjl/l0vubyVJh2OGSMtQnRoVyFg0fpQlNG84pqGe9W2enqBM X-Received: by 2002:a17:902:e804:b0:1e2:90c6:839a with SMTP id u4-20020a170902e80400b001e290c6839amr7935142plg.31.1712496853029; Sun, 07 Apr 2024 06:34:13 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l18-20020a170902d05200b001e291d7331fsi4465713pll.21.2024.04.07.06.34.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 06:34:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134470-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=D4+ckiN1; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-134470-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B5193280294 for ; Sun, 7 Apr 2024 13:34:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C2DD130A5E; Sun, 7 Apr 2024 13:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D4+ckiN1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C113130A4C; Sun, 7 Apr 2024 13:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495619; cv=none; b=UUiXkTrYODJLrxXNCdNDkCXY61KAbNXjwtO7cymBkThp4tJehDEchHmy7v+kpMDxKnh30QoM/BGZ+RrK+Fpv1fELtT0qbiePWdlnXb+97IpkPM2EY6FJlpjtU3GzUDjYxj5UagtiNewKOxbJP4l3frmXCTH8WtFfHej8beiAIvM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495619; c=relaxed/simple; bh=pWY5KBPRHC/DMNF2eOT2XhEVxqzLGgWzS978Y/5K94k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HNLEtfPxt5JDbVUHityE6VdroFsVtauwLhMwiJ7+QGT9K7Pjg5vXybKPu4sLEdXUoHD1GIx7pd8n1kM6Zb++kHNi90DeWAtmuy0JeOSxNRg+wvtegYLgWpklEdrfuY1Ee7bdF6iuS8E9KNk0xByPh79lvQNKzJH/Cl/+3Iq/4uQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D4+ckiN1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96B2FC433B1; Sun, 7 Apr 2024 13:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712495618; bh=pWY5KBPRHC/DMNF2eOT2XhEVxqzLGgWzS978Y/5K94k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D4+ckiN1N/bfTEC8vwDBFD7Ep+viWetfGdarXXdgoIOAOR1bodpSl7ZzC1/6V5z8b F0YARMp2bIfRDGWmXwUxvg40Zl64Fmn5vhUATn/QYULm4BhAF6ypmbxkMPjluiAPQt n5hkFMjMUim6H6Ila6N8aMz7/edYShrBiTiLt05O2HdLtMMWRfIMjw3mST4ZABWSkE eilFIAbRjWJx/vdv6+4k1yIy4Vs5yfzf7WVUHDD23bObCalY/tUdbpUIuEeNa5StHX uJWInX7jTJmxLF1OqoLrCbrUWIaVnv0FQwx2CAU1Bz6f/uhjyFDqh9xqd3LvmjvP7P yek+NHh+sTZ/w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Borislav Petkov (AMD)" , Paul Menzel , Nikolay Borisov , Marco Elver , Masahiro Yamada , Sasha Levin , linux-kbuild@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 13/13] kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries Date: Sun, 7 Apr 2024 09:13:12 -0400 Message-ID: <20240407131316.1052393-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240407131316.1052393-1-sashal@kernel.org> References: <20240407131316.1052393-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.84 Content-Transfer-Encoding: 8bit From: "Borislav Petkov (AMD)" [ Upstream commit 54babdc0343fff2f32dfaafaaa9e42c4db278204 ] When KCSAN and CONSTRUCTORS are enabled, one can trigger the "Unpatched return thunk in use. This should not happen!" catch-all warning. Usually, when objtool runs on the .o objects, it does generate a section return_sites which contains all offsets in the objects to the return thunks of the functions present there. Those return thunks then get patched at runtime by the alternatives. KCSAN and CONSTRUCTORS add this to the object file's .text.startup section: ------------------- Disassembly of section .text.startup: ... 0000000000000010 <_sub_I_00099_0>: 10: f3 0f 1e fa endbr64 14: e8 00 00 00 00 call 19 <_sub_I_00099_0+0x9> 15: R_X86_64_PLT32 __tsan_init-0x4 19: e9 00 00 00 00 jmp 1e <__UNIQUE_ID___addressable_cryptd_alloc_aead349+0x6> 1a: R_X86_64_PLT32 __x86_return_thunk-0x4 ------------------- which, if it is built as a module goes through the intermediary stage of creating a .mod.c file which, when translated, receives a second constructor: ------------------- Disassembly of section .text.startup: 0000000000000010 <_sub_I_00099_0>: 10: f3 0f 1e fa endbr64 14: e8 00 00 00 00 call 19 <_sub_I_00099_0+0x9> 15: R_X86_64_PLT32 __tsan_init-0x4 19: e9 00 00 00 00 jmp 1e <_sub_I_00099_0+0xe> 1a: R_X86_64_PLT32 __x86_return_thunk-0x4 ... 0000000000000030 <_sub_I_00099_0>: 30: f3 0f 1e fa endbr64 34: e8 00 00 00 00 call 39 <_sub_I_00099_0+0x9> 35: R_X86_64_PLT32 __tsan_init-0x4 39: e9 00 00 00 00 jmp 3e <__ksymtab_cryptd_alloc_ahash+0x2> 3a: R_X86_64_PLT32 __x86_return_thunk-0x4 ------------------- in the .ko file. Objtool has run already so that second constructor's return thunk cannot be added to the .return_sites section and thus the return thunk remains unpatched and the warning rightfully fires. Drop KCSAN flags from the mod.c generation stage as those constructors do not contain data races one would be interested about. Debugged together with David Kaplan and Nikolay Borisov . Reported-by: Paul Menzel Closes: https://lore.kernel.org/r/0851a207-7143-417e-be31-8bf2b3afb57d@molgen.mpg.de Signed-off-by: Borislav Petkov (AMD) Tested-by: Paul Menzel # Dell XPS 13 Reviewed-by: Nikolay Borisov Reviewed-by: Marco Elver Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/Makefile.modfinal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 3af5e5807983a..650d59388336f 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -23,7 +23,7 @@ modname = $(notdir $(@:.mod.o=)) part-of-module = y quiet_cmd_cc_o_c = CC [M] $@ - cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV), $(c_flags)) -c -o $@ $< + cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV) $(CFLAGS_KCSAN), $(c_flags)) -c -o $@ $< %.mod.o: %.mod.c FORCE $(call if_changed_dep,cc_o_c) -- 2.43.0