Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5602154pxv; Wed, 28 Jul 2021 14:59:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzXBFhGiARrAU6mVoyoHGpvaL07USf/SK5yJ4NkCc+MVJgYHhXGyMFq0iQXt0X9UHyDI/W X-Received: by 2002:a92:dcc2:: with SMTP id b2mr1342911ilr.84.1627509573350; Wed, 28 Jul 2021 14:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627509573; cv=none; d=google.com; s=arc-20160816; b=tousT0723qjQ3bhYc6BiCuwpZduwkbFq3MrMk/tZBeaBgM+PWQvawkX2U+zYxmYqB9 M9oSiV+AYZTsKCHHXOg5Gb2JMEhCEkdu5qo0cfuQphq3Zci3oOfH7IcuqZQytRvgzYtO qvMQchHRBBEedFUm/gFVfcQctG48CuHAFzECbIIDl0pVyZbFfRraNfJF5Kxto5MU6MYK bQXJtBFh1kn7H15wdpkAWmVuAF5yRF9GC7CNfuRE4tY1rIF2rZrvvzT0MF56a9B0sTB4 1zfATaTv/b3Xr9WcFY+DhDqLztbHj8SJ5/lCEvOVZ7bsidoNWtSXZgbjrkNdF5XsAi8o fTJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ry2so8wkWIDOCG/sQogiwuE+9Zyl4IrepEHbauTvq4U=; b=NXm23lOmS7dR4eXXEnkyPxaM/z7kYm0jN2eBuhvnX9BM3BiLJ4WUYzq11Q83xyDyct fFxag43icpblR+gvbXRXhaVNUHa5n8XGJkc9FblfN2h2OLu/0FiJVp54rFci9LB8zdYz 2z6FYKQOEgcGU3kR5rSqRVYbGdEk3GTKS5sZT3CoWaDBjbKM2Xy9w/9RhfIaYH0Isq8e FMO6LUJ4agOoZEeckjejzGllpwjHW+AIV/P+Ho6GCUi5YNuGOk8/UFJTBS8WhKzvwY3k GlplVXoqp2Khz7aDJHWoseMnl5FvsWlz4i1mgv5UFb807cGS9BOB6M5f0U+6bgr8+YGl LoHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IGRqrDLs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si1111096ior.73.2021.07.28.14.59.21; Wed, 28 Jul 2021 14:59:33 -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=@chromium.org header.s=google header.b=IGRqrDLs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbhG1V7S (ORCPT + 99 others); Wed, 28 Jul 2021 17:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231668AbhG1V7S (ORCPT ); Wed, 28 Jul 2021 17:59:18 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BFC2C061765 for ; Wed, 28 Jul 2021 14:59:16 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id b6so7233588pji.4 for ; Wed, 28 Jul 2021 14:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ry2so8wkWIDOCG/sQogiwuE+9Zyl4IrepEHbauTvq4U=; b=IGRqrDLsPrMGIokLAHHitBXrTGx8ldPYhQZ0vhlO7BwqLTxHuG39KqoD+0xySdQDeZ wOes72WlsRRJac/rz2gEpxXYvtLZ6bSaZfmQarX0qm7P2LxswesUfd9AKF5i4JhugBhi nx2jk3HjG5WlS1z72s2XLwsxgebFqKKL6xJwA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ry2so8wkWIDOCG/sQogiwuE+9Zyl4IrepEHbauTvq4U=; b=ccOduSh7sEFDUGl3BLY7b4KdFfF/tYuTFo5o4RjmC8M7NA6IzGNFT6KQeoALGlmdAl IlK8+ASv3v1AXlfGR4IqRxv+nXm2CqWEPKKhHsmrT9Pl62S1TSEg38C1+GwkkfZTEpks u06XlWtvPbkWGdV0E1bzAy1ZmDK8aMep2nfRtnsNKGqPwLn1l2k+vtbQoRxbgCTD5oR/ VW3gf5MWTqynvYqbo70Fnskl0H/kVgO94vBLrqNZUFDMZ+36usZnksnwrX2RSRkKp1+o rprGNqBFI8VR8EsAjZboxwiF2ySwdesL4fChqTIxw9O1NXMTq4AMnqddWcKAFjuukQbX prng== X-Gm-Message-State: AOAM532G5N86nHKyJ6GUprbYajWR2m73SjNchhzkJ08+/UVuqZGC6GAK U8KEqQhpk96yIDzIJ+cBmJE6mg== X-Received: by 2002:a65:498a:: with SMTP id r10mr928037pgs.7.1627509555798; Wed, 28 Jul 2021 14:59:15 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 30sm1011862pgq.31.2021.07.28.14.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 14:59:15 -0700 (PDT) Date: Wed, 28 Jul 2021 14:59:14 -0700 From: Kees Cook To: Rasmus Villemoes Cc: linux-hardening@vger.kernel.org, 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 Subject: Re: [PATCH 04/64] stddef: Introduce struct_group() helper macro Message-ID: <202107281456.1A3A5C18@keescook> References: <20210727205855.411487-1-keescook@chromium.org> <20210727205855.411487-5-keescook@chromium.org> <41183a98-bdb9-4ad6-7eab-5a7292a6df84@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41183a98-bdb9-4ad6-7eab-5a7292a6df84@rasmusvillemoes.dk> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, Jul 28, 2021 at 12:54:18PM +0200, Rasmus Villemoes wrote: > 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. Oops, yes, thanks. This is why I shouldn't write code that doesn't first go through a compiler. ;) > 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. Ah! Perfect, thank you. I totally forgot I could do it that way. > > > > > 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 :( My instinct is to make these kinds of helpers "always available" (like sizeof_field(), etc), but I have no strong opinion on where it should live. If the consensus is to move it, I certainly can! :) -Kees -- Kees Cook