From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91134C04A95 for ; Sun, 25 Sep 2022 15:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbiIYPmU (ORCPT ); Sun, 25 Sep 2022 11:42:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbiIYPmQ (ORCPT ); Sun, 25 Sep 2022 11:42:16 -0400 X-Greylist: delayed 571 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 25 Sep 2022 08:42:14 PDT Received: from mail-m118207.qiye.163.com (mail-m118207.qiye.163.com [115.236.118.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D036C1C136 for ; Sun, 25 Sep 2022 08:42:14 -0700 (PDT) Received: from lyc-workstation.. (unknown [221.212.176.62]) by mail-m118207.qiye.163.com (HMail) with ESMTPA id 21789900D0A; Sun, 25 Sep 2022 23:32:40 +0800 (CST) From: YingChi Long To: tglx@linutronix.de Cc: me@inclyc.cn, ndesaulniers@google.com, Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , "Chang S. Bae" , linux-kernel@vger.kernel.org Subject: [PATCH] x86/fpu: use __alignof__ to avoid UB in TYPE_ALIGN Date: Sun, 25 Sep 2022 23:31:50 +0800 Message-Id: <20220925153151.2467884-1-me@inclyc.cn> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFPN1dZLVlBSVdZDwkaFQgSH1lBWUJPT0JWT0JOTR8YSx1LGUtOVQIWExYaEhckFA4PWV dZGBILWUFZSUlKVUlKSVVKTE1VTUlZV1kWGg8SFR0UWUFZS1VLVUtVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OVE6Dio5HTlIIzcVNzw*OUxL MjMwFBxVSlVKTU1PSkpCQk1KSU1OVTMWGhIXVRYeOxIVGBcCGFUYFUVZV1kSC1lBWUlJSlVJSklV SkxNVU1JWVdZCAFZQUlJQ083Bg++ X-HM-Tid: 0a837547743f2d29kusn21789900d0a Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org WG14 N2350 made very clear that it is an UB having type definitions with in "offsetof". This patch change the implementation of macro "TYPE_ALIGN" to builtin "__alignof__" to avoid undefined behavior. I've grepped all source files to find any type definitions within "offsetof". offsetof\(struct .*\{ .*, This implementation of macro "TYPE_ALIGN" seemes to be the only case of type definitions within offsetof in the kernel codebase. Signed-off-by: YingChi Long Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm --- arch/x86/kernel/fpu/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/fpu/init.c b/arch/x86/kernel/fpu/init.c index 621f4b6cac4a..41425ba0b6b1 100644 --- a/arch/x86/kernel/fpu/init.c +++ b/arch/x86/kernel/fpu/init.c @@ -134,7 +134,7 @@ static void __init fpu__init_system_generic(void) } /* Get alignment of the TYPE. */ -#define TYPE_ALIGN(TYPE) offsetof(struct { char x; TYPE test; }, test) +#define TYPE_ALIGN(TYPE) __alignof__(TYPE) /* * Enforce that 'MEMBER' is the last field of 'TYPE'. -- 2.35.1