Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp538354lqt; Mon, 18 Mar 2024 16:00:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJLhtEDKTXBPy5CxAb5OhWAV6H8Tkmp+tJHfjP6sRNcvfSSU1XmXovPf7lz09nVhNyD/cq+JF2siqkZQrqbbubAyW966IWi8LB1OG6SQ== X-Google-Smtp-Source: AGHT+IFec7gU3zM5OpiZuLBHjbOsdnRueq8WnIJc/hwwGrEs6QtgYOazNdq9Gh1lVdv89dI8TTg0 X-Received: by 2002:a05:6a00:1701:b0:6e5:78bf:d40d with SMTP id h1-20020a056a00170100b006e578bfd40dmr14056680pfc.18.1710802848071; Mon, 18 Mar 2024 16:00:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710802848; cv=pass; d=google.com; s=arc-20160816; b=CMXgjQZOruYU4c20UX/NDq89Cqo/dwgnd7yg828rlTa8Ryft9KwliBJpKPEm8CQaOe gwEld2lIDEyb18dWnjRbXMTDyeEx1EWeI1PsuEcGZ3/wFyxpqG4izYOwor3Q/RRd/b7N jaMG293L7VfQGOsLHkzRxyuIn44TW8fQJbPaa4RcoIcDS+YyUvtNRwkbqpQNg3eJrpu2 PtNoqF66mqRxvgE3Xyn81Wh2aMH1hcNB7vK2uHEpQBBE1iXUnJuvuRWcf4sIMPd7wZ5h BGLiH8czes5KODCIiS3ABGjeiQFKT4qoU/TL/vnCueWtZIVWlPh40MJNAiKBTZ7jMHF9 VA5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=ni2nNgSRA9AkVut62VBtzRvEGkcb61rXE1IEyyfOCLA=; fh=fPKzxhEe2Xcz1gOtE9Brql6Z43OtAhkPPLEvrVGQfSg=; b=tfSS/mGVH4W/6CPZ7GfKkrW6C87mwtrpb8xRYVn+qm94UwYXq3GLe4lPzsivfV2R8U 4LjVETwV6xCWwZNfv4JVvq/VPeHwgCG3zeKo9lvPC9nGoRfP7hbV3k83TdO8VuF9uhBJ O43SCVoWLXePy/z9hAUUn3HfPsyOuNve+8WjJ6roJZDuq2efJ7b5Leh/osmKfwI7QW7K uG/o0km0pXA9+9qH2ilKl/hIhTwdQNiWkq1rz4MytKp/zTQ5cy2JWfAJi23kLBvFL6Bb sUB+o5GZGaiARdTgQdudkHR2l68paBCp1Gs2L34x65fQLDcaoQYQw1lFsSaRB4ZvMX/o KtkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FnvTf2qb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-106784-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106784-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y1-20020aa793c1000000b006e64519650esi9889128pff.205.2024.03.18.16.00.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 16:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106784-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FnvTf2qb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-106784-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106784-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 BDAAF282C4C for ; Mon, 18 Mar 2024 23:00:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13DEB5B5CE; Mon, 18 Mar 2024 23:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FnvTf2qb" 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 3D0735B5B2; Mon, 18 Mar 2024 23:00:36 +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=1710802836; cv=none; b=g6VEpKEAFGWCpAzVPtNr2t1+UpF3ws1z3tnGMYmREmye2bGog7B1D2WXgtSUTKOEc5oTrwcqx815wGFL6mf3fC/idVWR8X9uBwWoG0slmvY/ai/GONIzsQBnkfiXAoeGOCx4dQctJKrfaI3kAS+ZbMrspWNTeKFv71foPPdNwXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710802836; c=relaxed/simple; bh=2aJSw72TDhJJtJGSi3sZZ5tt6V0h7mkTLli9U+Gg7Xw=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=UsBo/Ab/BzkZu4oBFsj4iMAxUDa6L5QcEc6qjigya+RwqtTdZD5Sxo2XMgja7fYNN8bkeisxxFvaZ3yYCcKYjVDGMPNBF65k6omARgNtcyohGhcA+Znbm7mSosbMA/fKVHYYpSiakL3jF6ZZnF2KewgW3qNPxZ83AWHgf6UMrpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FnvTf2qb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3001C433B2; Mon, 18 Mar 2024 23:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710802836; bh=2aJSw72TDhJJtJGSi3sZZ5tt6V0h7mkTLli9U+Gg7Xw=; h=Date:From:To:Cc:Subject:From; b=FnvTf2qbmOzydEu8kJi0fDnXWES0yeHfdDlw1N0PDEUrcA1Nqt4ix6hw7W+N++ahX ZkkJcjzvM90XpxwcE8dKfSlKreG0c46NTd5n4oTvl3jvps310/VEQNFpsRlLq5MffY /5iN0SvaDXu1j9dZ4yfRx8N6VAswzwyaRrx7b5iaxYd9jfls1xBNv/O2z6Hd/0KA8v 1Ctz/9cvdl5GsMyLdvQ/A2yr2eT++XNH0lDVq6Z7WdmfguRFE4W60qJHIhykfWp3qv HoJrYVHnUUujRRqZb4C7xDNs1IGUSEZqHgmcqoWYYODpaUb6kVPQ0S61y3BpJ/6DnX cOBznMF0W+cMw== Date: Mon, 18 Mar 2024 17:00:33 -0600 From: "Gustavo A. R. Silva" To: Kees Cook Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] stddef: Introduce struct_group_tagged_attr() helper macro Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline We need a new `struct_group()` helper that allows for both having the struct be tagged, and specifying struct attributes like `__packed` or `__align(x)`. This new helper will initially be used to address -Wflex-array-member-not-at-end warnings, where a tagged struct is used to separate the flexible-array member from the rest of the members in the flexible structure [1]. There are some scenarios in which those members need to be packed, as well. So, `struct_group_tagged_attr()` is introduced for this. Link: https://lore.kernel.org/linux-hardening/ZeIgeZ5Sb0IZTOyt@neat/ [1] Signed-off-by: Gustavo A. R. Silva --- include/linux/stddef.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/stddef.h b/include/linux/stddef.h index 929d67710cc5..919df9453257 100644 --- a/include/linux/stddef.h +++ b/include/linux/stddef.h @@ -80,6 +80,26 @@ enum { #define struct_group_tagged(TAG, NAME, MEMBERS...) \ __struct_group(TAG, NAME, /* no attrs */, MEMBERS) +/** + * struct_group_tagged_attr() - Create a struct_group with a reusable + * tag and trailing attributes. + * + * @TAG: The tag name for the named sub-struct + * @NAME: The identifier name of the mirrored sub-struct + * @ATTRS: Any struct attributes to apply + * @MEMBERS: The member declarations for the mirrored structs + * + * Used to create an anonymous union of two structs with identical + * layout and size: one anonymous and one named. The former can be + * used normally without sub-struct naming, and the latter can be + * used to reason about the start, end, and size of the group of + * struct members. Includes struct tag argument for the named copy, + * so the specified layout can be reused later. Also includes + * structure attributes argument. + */ +#define struct_group_tagged_attr(TAG, NAME, ATTRS, MEMBERS...) \ + __struct_group(TAG, NAME, ATTRS, MEMBERS) + /** * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union * -- 2.34.1