Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp844395lqe; Sun, 7 Apr 2024 06:37:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVb85k95Bot4EnmNjDFZ+qIRn2nklWxi0w9JRHnpEfXoCvD8IwYNBY4aZDeHSxcpbslz53/tN/JbsXrAPy2g4xjH3UrBPhiqMG+IIKeEg== X-Google-Smtp-Source: AGHT+IEtdk2OL4C/hraXzYX8obeWKEkaiJfqT0rGw185CTrfpghjL/H4TN3MpEQVtURp2QPspPTn X-Received: by 2002:a05:6512:3ba3:b0:516:cdb6:2ca6 with SMTP id g35-20020a0565123ba300b00516cdb62ca6mr5043892lfv.35.1712497021732; Sun, 07 Apr 2024 06:37:01 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dr19-20020a170907721300b00a519e1b3663si2815108ejc.2.2024.04.07.06.37.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 06:37:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134480-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=Aqe9npec; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-134480-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134480-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4DB821F2161E for ; Sun, 7 Apr 2024 13:37:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48312135A4C; Sun, 7 Apr 2024 13:13:58 +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="Aqe9npec" 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 68E221350DA; Sun, 7 Apr 2024 13:13:57 +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=1712495637; cv=none; b=l/9u1JXuk7u1tVpwSb9bHgs6VJxbWQj/o8v+i3gYuV0X8CN8rP7mCA+XkyBFYVNwxgqAf89zGk1mdx61BJ9cXGOr3hDbsUM6od7+jwl1imcTUkKl+RsTKPHKW/hm6lqHVUpCpDdONd87CqJzQhPp4f7ux3d49kTxnTPp4Zu1xns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495637; c=relaxed/simple; bh=M55eIr8YY923zpvoeCETl20KqAT1p4JYqMDrkBauwig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kgW1RtDUlpN9xDO9NNO2E6M0B9tPeJFuXEW1Hhfce7Au1KE8MkYLaz9Dy0QrUaehI1az4Lkk8KY0dHLPuK0N3hgocbXnV1jGt8a4ztYqrNdJt3O98f1wXiWwqjtLqxHtsizfX6zDk+Njbzu5SRb4tG+S1GGQR0AtnXpcb8tlhC0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aqe9npec; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D8F3C43394; Sun, 7 Apr 2024 13:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712495637; bh=M55eIr8YY923zpvoeCETl20KqAT1p4JYqMDrkBauwig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Aqe9npec8482V1ADit1uyAs5zyQJoEXQMAb9kGEAOHxccklfIK9/XuxBvGw1YQJ67 8nzMHzEbsQjLWN2TCCNLe/7qPiNLqPX1KXmhO9NYvZbPnFZ4eKPcx5ykbmQXM8Vsg3 IDqurLUYZt1UCm9WuNJFUz++xvsVwHTNX1z1LXDBrYsoUOnwJ8in4/XOZZdWQFLWR1 IrPBIpFR7Hv6ZjZ1kUghTWspQAprKPwM3jNcXggZYEhI/EPXoCRpxMQ53HxVRZK2jm DPNxbjxceoSLIZjL2GcjJzULYly7K1IL3YlKhjTbND9DIKXhsx+oJaMPumEQgGZtUs IAFTB71crXtFQ== 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 5.15 10/10] kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries Date: Sun, 7 Apr 2024 09:13:40 -0400 Message-ID: <20240407131341.1052960-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240407131341.1052960-1-sashal@kernel.org> References: <20240407131341.1052960-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 5.15.153 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 47f047458264f..dce4cf55a4b68 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