Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5126693pxv; Wed, 28 Jul 2021 03:55:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy0RW+LuOT58fzpSMiexNgYWc81VtZro0TwQJA2PS3ocMGLDpEHqhgsBDrskT4uxPrfniu X-Received: by 2002:a02:90d0:: with SMTP id c16mr25671791jag.106.1627469712376; Wed, 28 Jul 2021 03:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627469712; cv=none; d=google.com; s=arc-20160816; b=yXMOU4dGgJ0R2Zy4sOE5S+cf8qSyURCdJiI/Z6jx6jibtfbl3d7kdxOSoaQGTrztlh YNnQNP40z7vnaz7chwGZhAEdgPnupc8yU1gt1eQO6T0jM12OR0gZe6YLh4Pk/lZHHeoY jyxo/0wwFZJ/Wikl+7GTptnguism1sXLlsslUl6u92lpXkOj4qrCCSNNCCliDBoRM9tl yDZzmh/4RMOMcG9B9PbddsL1XniA/WAtgjs/A9kZIzqo5Reswf5O4+xDztccAYpfEsYW SJ8KkQ5CLt1rKWkdhe3xgB1QZT2bheBqlk/z/MmZydFhefd0EITIWeyg/ricpXMo1Ilu 523A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=y7BSRF2BV2wKYMpkMU6AInonSJrtXWVBGV0wA+UfcSQ=; b=W86P1HlWqUKBf8YnmpFeuizKJKuYePlfaTGNBIF6Vhp7FGE7DOUh7BpYEJdJV8t7R4 MAB3NtpTXgnyLd7DaePHnoagrDty5gOhbF+5wl/B0UXwtDerSKPTnPPJhiQVN1VcqzqD QvwrjgfyDe43jDpr27+PQ1eb7elMlpinSawU0x3YOTdZMGcpg38zUr6yH1btc4ttZe/5 FJicCX2KuHChX9b2E33sEDaaqxMIfAwMpw0NlH2LsHN2fUmVvkraAbzRG1OYO+mXpxuo Fk8H6TcKnXddEiJCrrKBhHz9nf+hgo6+pgCP1VigBpeKTEePlEvyoGTbSY5JfNwNM8uS 7Gww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=HvxZxKOR; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si1622088iog.96.2021.07.28.03.54.46; Wed, 28 Jul 2021 03:55:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=HvxZxKOR; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235930AbhG1KyY (ORCPT + 99 others); Wed, 28 Jul 2021 06:54:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232147AbhG1KyX (ORCPT ); Wed, 28 Jul 2021 06:54:23 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB851C061764 for ; Wed, 28 Jul 2021 03:54:21 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id e5so2542379ljp.6 for ; Wed, 28 Jul 2021 03:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=y7BSRF2BV2wKYMpkMU6AInonSJrtXWVBGV0wA+UfcSQ=; b=HvxZxKORsgd1u77vvKkzSHVmzDZnFgdXGSifvV+HmSIPnClkA6lYo7Qz7nvYlLjejZ PK9B0U1dzVIDM4JKLg5sSHucPcc5bP4ZeDpjmSTAFJSiF4x48AfpDxMdOGxhIAJqc77U oc7qawDYmcTBtp40SM72ZiIXxtcm1lp5rspVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=y7BSRF2BV2wKYMpkMU6AInonSJrtXWVBGV0wA+UfcSQ=; b=Xg/zMccUpTWtpIqxesMnUPPHGHAZqj39rKkPklWIXQrCzQCBde88mZlYIce9N779iK nDhBLQ6tFueVBitXTqb1/H+lpti4K8EXMYGzngsFxU25pX3/ARmkDRyqn2PX76CuzKRq NIE7rVWwHJlaSZgY3UWqNhK1evbj1XQBB737OUhxFOCWLgJ1JsE8TgipvcxpNb2owCK6 XSReNAjJdPlS9FLqnREVrv8Q2TS4hAUOfrIJVDJacq8bcxYGZ8xFXWBn7gUkk38nzYtY gVBmKDG1CE/zTZrAVbMePRSVfhiG7xo+6lDelUs96STRN0sYveU5bP+vYkW5Mnv78qZk e8qw== X-Gm-Message-State: AOAM530iX3+zeIethPmAyaNesLIWjiuynI9q8cbgMVLl3OebwqDrGPLz 0y2s+gIy2HzUcbppoBn+NTJu6g== X-Received: by 2002:a05:651c:1144:: with SMTP id h4mr18097576ljo.396.1627469659652; Wed, 28 Jul 2021 03:54:19 -0700 (PDT) Received: from [172.16.11.1] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id o1sm555702lfk.298.2021.07.28.03.54.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Jul 2021 03:54:19 -0700 (PDT) Subject: Re: [PATCH 04/64] stddef: Introduce struct_group() helper macro To: Kees Cook , linux-hardening@vger.kernel.org Cc: Keith Packard , "Gustavo A. R. Silva" , Greg Kroah-Hartman , Andrew Morton , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-staging@lists.linux.dev, linux-block@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-5-keescook@chromium.org> From: Rasmus Villemoes Message-ID: <41183a98-bdb9-4ad6-7eab-5a7292a6df84@rasmusvillemoes.dk> Date: Wed, 28 Jul 2021 12:54:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210727205855.411487-5-keescook@chromium.org> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On 27/07/2021 22.57, Kees Cook wrote: > In order to have a regular programmatic way to describe a struct > region that can be used for references and sizing, can be examined for > bounds checking, avoids forcing the use of intermediate identifiers, > and avoids polluting the global namespace, introduce the struct_group() > macro. This macro wraps the member declarations to create an anonymous > union of an anonymous struct (no intermediate name) and a named struct > (for references and sizing): > > struct foo { > int one; > struct_group(thing, > int two, > int three, > ); > int four; > }; That example won't compile, the commas after two and three should be semicolons. And your implementation relies on MEMBERS not containing any comma tokens, but as int a, b, c, d; is a valid way to declare multiple members, consider making MEMBERS variadic #define struct_group(NAME, MEMBERS...) to have it slurp up every subsequent argument and make that work. > > Co-developed-by: Keith Packard > Signed-off-by: Keith Packard > Signed-off-by: Kees Cook > --- > include/linux/stddef.h | 34 ++++++++++++++++++++++++++++++++++ Bikeshedding a bit, but do we need to add 34 lines that need to be preprocessed to virtually each and every translation unit [as opposed to adding a struct_group.h header]? Oh well, you need it for struct skbuff.h, so it would be pulled in by a lot regardless :( Rasmus