Received: by 2002:ab2:f03:0:b0:1ef:ffd0:ce49 with SMTP id i3csp45652lqf; Tue, 26 Mar 2024 13:52:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXG6ir+8ggGBe0jimYGh0NqgehAfP3CNejyEggGEH0+9mmb4+95wmFycwLyBDIaODgrhW5l0jEkhYfB5q0tPeNTC0crbIIoe312+Wpgfg== X-Google-Smtp-Source: AGHT+IF37+/G844jRRFmWnikfGX5GJeN/CF+o1XCgL046Bef36so90LKV8Z64ex1kUXv72i8r/1V X-Received: by 2002:a17:907:d15:b0:a4d:f8d7:8546 with SMTP id gn21-20020a1709070d1500b00a4df8d78546mr2241752ejc.7.1711486376844; Tue, 26 Mar 2024 13:52:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711486376; cv=pass; d=google.com; s=arc-20160816; b=oQucrEf9bIpkpZosMUAo7GL3MdMiadZhxPoY6ryWaN9JlZyoXDcOlubY02ifTmi8xt nbHpwlJpEl1EzqFtbDgRuVMlCUdk2UEDgt1IQTBTCrIKJyuPjG/RMfIzQpkayYSwccTp ZmAGm5X5TffUhwpTRM17S6EbgjIiZbrXe760KBM8i6Yh1lIjZyWHmcXBqDXmYPoTdgiv opFgzwgoRvFfnSndN4ldlXeBvAC0X8MDJmSwZnxclFoB/Dw1mUilKD64rmHJ1bevmG3q yheBru+Ge5F3q+6LlkEog6L3nWhedRBNwFwGKEjvv4HU3TMYx8QS9bstFNnxUAA/QLnU eULA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=WXbMV//iCVDcmmeY0RArWtkZ2QeUzFh9TWNfWy7C9Pk=; fh=EFW/+0F/f0JbhnSVKCA7b/6Zc2CYLRaEdFjQ8ZbuWcE=; b=jJJ1P3YbFxZN8PVkkCbsqhxuNt8/bHnaI6hBAIRB8i+M7JkdAlcJRANi0FHXu4hiVq prFlnigm9XBPfofOcbD9tvvy0Yr9Flq4ykk5+uaRiWMuYHET1B8O86XkSw88EtJ0Psr5 kDeBK3NgIcQSlwSJ7FS8R/W+87tiFrqCy6M0QWING2QwGYqAF/421kduC4fXmMvIy9qI Zm4uljJZDbKBpCwusT5SY9oKcCwsimFra1YT/Y8xpGkqtjo2eZn/LdZzq5AVlCfiBKa+ OiNE4sfxtXiZNFo2hR1IstvuQ8fDcgEXdU5ZT8HXn4lhnfGsM1vk+fDEq7TeuswnIt4w VH2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AQ9F7CAy; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-119945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w3-20020a170906b18300b00a44d19c4051si3788194ejy.409.2024.03.26.13.52.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 13:52:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119945-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=pass header.i=@google.com header.s=20230601 header.b=AQ9F7CAy; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-119945-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119945-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 6B90C1F849FE for ; Tue, 26 Mar 2024 20:42:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C56CD71B53; Tue, 26 Mar 2024 20:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AQ9F7CAy" Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37C082CA8 for ; Tue, 26 Mar 2024 20:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711485751; cv=none; b=ORqXkRZqb6ZfWnQyPtj2prZ78K/o9XWyV/E2IdXPN52MDZhQGu+2HQiv+OuCx6wWYqh5sfaXbnoJSGu81IeLEgX8C26jXj2P1k8a7UAMkoydgMtSQxTLkX+OdJSx5FO1ZIo+A88WGiZqmeMd4cjIYVsx/LXBO26MiUdtBTSMiho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711485751; c=relaxed/simple; bh=pLHWzs987kbANZLhWn+OVDYNz1mbnSNZ0ZnNwiv7Qs4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=A2pSRc1Gp6oDoBBXw4LSFTws5fb3wFFmBbR8hvXsaYp5jn8xGKs10OoxhyQ3sA1kgiaYfMiXnE4igLpXkXo4wcGQQ+KyeWN1brFPNk+o3vM8bWa7M2y3nZ1CYSa39jXoCxyGdFlYwwpn6kYWfkdNHk+dIzg1ftfJ4n61KOWjp9Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AQ9F7CAy; arc=none smtp.client-ip=209.85.221.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f172.google.com with SMTP id 71dfb90a1353d-4d438e141d5so111917e0c.0 for ; Tue, 26 Mar 2024 13:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711485749; x=1712090549; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=WXbMV//iCVDcmmeY0RArWtkZ2QeUzFh9TWNfWy7C9Pk=; b=AQ9F7CAyYu031wbKs1aGnu9bXs392xQBUMzvA2w60O7IGoAQyjJ0PUzN6j8QKyNi8L 3mE2HQSCx7+icQ/359I52RxjMKy4cgxedF+WZeyTpD1ZaUjM3gJQ1On75CNUl5xJ8Nnl EeCFTfFICgcPD3tngZicsaJZLhYfOEnygZeWJFQZkl8u3h53ZKvWdi12Kzs7AuKY1w66 OCOJHsIUaBZZod3TCCEoFrnuZ8po0nZaW9NjiRzdrXWWvj6EZaSU/e9HzKzsnjGdWTf5 f2hwY6UZz8zwzBFhGHSyRpcM/YuDfGNCfiABAz4idshPyq+z4zN/dkoBXjImak3o3Ws3 2lpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711485749; x=1712090549; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WXbMV//iCVDcmmeY0RArWtkZ2QeUzFh9TWNfWy7C9Pk=; b=O8buDPMycYbYceD45bqnHhX9d4mUN5XVNFzlJC2L8mTpf/F6MjNJjXYTpwCfWzmEzZ IHZHv4uoRFUWyJNWSSJMy+h2ICqH15p10Jj4A99xBVSGLC6icWVABarOarda5vtIZWzI q/8BogYFGGZoAAy31XpIDs9zxdbF/nm/k146BOsDa/wrR4lxx5KXMmUyn9U5N57UpJPS mJ1sMIVE+QeFqHgNNLaCTz7eQzM6YbQAYQlQKqn1shYsLONBkpdTOreNO56oaq1dyEm5 /3ICRnQw2RzAYPF/CHh8XdLOs4UBl0fIaBsNtTbGdNvhOtm2Zu3YQACx1Y6fyG/yWM/i VnqA== X-Forwarded-Encrypted: i=1; AJvYcCWaIwtYC5GZqpGW/PvsAmoXLARna9QbZ8uN5GXkbIl7gQ1rI7KfT8P+0bhbgVnk4up6xSnetfLQDxLoWIvMfFK1ppWJ2UlzfiJN75ag X-Gm-Message-State: AOJu0Yxm4sO2vgGZj6EI6Tmre+5pExmtMVf7lUQx1B4IS1wDQb8q9r/c ACS6sH1c/TXq/uS/KZa4hXIyytjVmUWED67KQIFxvUPloTyoCWVOnWPuKfd8j1ZMj7+wbBHYArz xgM43O3O7ws2Rl6/oRCsopu7+tnw8xHiwa+mv X-Received: by 2002:a05:6122:181c:b0:4d4:4ff8:c367 with SMTP id ay28-20020a056122181c00b004d44ff8c367mr2307752vkb.6.1711485748894; Tue, 26 Mar 2024 13:42:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <0851a207-7143-417e-be31-8bf2b3afb57d@molgen.mpg.de> <47e032a0-c9a0-4639-867b-cb3d67076eaf@suse.com> <20240326155247.GJZgLvT_AZi3XPPpBM@fat_crate.local> <80582244-8c1c-4eb4-8881-db68a1428817@suse.com> <20240326191211.GKZgMeC21uxi7H16o_@fat_crate.local> <20240326202548.GLZgMvTGpPfQcs2cQ_@fat_crate.local> In-Reply-To: <20240326202548.GLZgMvTGpPfQcs2cQ_@fat_crate.local> From: Marco Elver Date: Tue, 26 Mar 2024 21:41:50 +0100 Message-ID: Subject: Re: [PATCH] kbuild: Disable KCSAN for autogenerated *.mod.c intermediaries To: Borislav Petkov Cc: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, Nikolay Borisov , Josh Poimboeuf , Paul Menzel , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Dave Hansen , x86@kernel.org, LKML , kasan-dev@googlegroups.com, David Kaplan Content-Type: text/plain; charset="UTF-8" On Tue, 26 Mar 2024 at 21:26, Borislav Petkov wrote: > > On Tue, Mar 26, 2024 at 08:33:31PM +0100, Marco Elver wrote: > > I think just removing instrumentation from the mod.c files is very reasonable. > > Thanks! > > @Masahiro: pls send this to Linus now as the commit which adds the > warning is in 6.9 so we should make sure we release it with all issues > fixed. > > Thx. > > --- > From: "Borislav Petkov (AMD)" > Date: Tue, 26 Mar 2024 21:11:01 +0100 > > 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 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 > Signed-off-by: Borislav Petkov (AMD) > Link: https://lore.kernel.org/r/0851a207-7143-417e-be31-8bf2b3afb57d@molgen.mpg.de Reviewed-by: Marco Elver Thanks! > --- > scripts/Makefile.modfinal | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal > index 8568d256d6fb..79fcf2731686 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 > > > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette