Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp279116pxb; Wed, 18 Aug 2021 02:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc1aFgSKZPMhTwrAnAtFOIPp5hmi5vexDoQ9SVSWStM+Ur76Q0kO5QG6JCdsjQV07WYKwh X-Received: by 2002:a17:906:5909:: with SMTP id h9mr8563572ejq.329.1629277529062; Wed, 18 Aug 2021 02:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629277529; cv=none; d=google.com; s=arc-20160816; b=hcLkMIc6lYsCYdlkA38w/x2qBeoHPLa9Tby3WI+bAUpLC0l6hYuY/8VubrTZO70GC+ GxXE+qKxVIIrggmQJVBh80W3wzwEuFxN4P5DOcpt0bqj7BS7bD+LJR7oPHEujOIJKoOD jPOoopz6WVkXbGXkUyWxOgWNeXKpbG4dwpsXrKtefbkHj9pBo9Ns6tiB1200lECDDxqi J8xPq+GxZVF4rSdvlFGhFLpRAHj0CAjGeIEViYiBP97V5dnpRpeODqVUMgvAXpQk82J5 c5jgfAKVvedOMwPzUcNhBM+BuGlvvrWW1VZG9o5TWtRZZPl1HSelGSGbOavFjJbako5g L+Yw== 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=Wi6GiW3siAeArZqvWLcz46sruMCMOkQL9Tx1MHP2F9M=; b=WQADjE9zbAzBFcojEfajgKI/hJlSMV82zZod6oIWXeuzPai73GsCsjAQEpl8jz+MFG mOIuiJB0R7Y5KplxhvXjrACs7ckBiALdDsSHEsXOf+Z7EZpNa0szoZn5751WJgAgi7jj o9YH8eop+cH1OC3KpSmkb+draGE5lK8itiDEnRD1MMfAxYf0R9jEa3PXfLseYtWfTgMT r4eU/Msq9n6ZO917tucwbQDFzTb781RTDGJqeaZyzaHwgv9AtrG6526rgjome0vks+mi N+z4zu7E2awrpyVPe+bQGQS5HKVl2UVszXBB0sReYgD4Sbb/uM/JVfITve6Bx4Enw6wR iTxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=O6b9QEJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 h6si4889552ejk.727.2021.08.18.02.05.06; Wed, 18 Aug 2021 02:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=O6b9QEJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S231258AbhHRJD4 (ORCPT + 99 others); Wed, 18 Aug 2021 05:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbhHRJDx (ORCPT ); Wed, 18 Aug 2021 05:03:53 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE75C061764 for ; Wed, 18 Aug 2021 02:03:18 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id w6so1369851plg.9 for ; Wed, 18 Aug 2021 02:03:18 -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=Wi6GiW3siAeArZqvWLcz46sruMCMOkQL9Tx1MHP2F9M=; b=O6b9QEJX2A+BMP2t/Jopnb3uLzfw7MkxdgYGDPd8kXg7lj6i5rW4b1KQUD7duBp0NW ARZb6rSvwK8yUjjDtTmZ/No5b/N6TJNMpFMfjHQcB66xfWC5jxVfZdmVgg/rw4tb9D9m KTQ5SvRW25g7NfqelO4dYcMxQcfvJG7CIhrVQ= 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=Wi6GiW3siAeArZqvWLcz46sruMCMOkQL9Tx1MHP2F9M=; b=cyycmAbUyP+MEhea6Q0qbMU1HkQu4kFkZr05PJMO75XyP5FwEaxoaGmB4/QbS5Yj4/ kQ2IQdr6BYm/8yGLMpLODAfyUr2UI0hja/01HEwIu891oVVh21ONeVC9bW7iMZtZ8Jlz 2usvP9AtGK5Kpx7CckQiWVQ7CRi0H4DKE20xq+dukLWcvCTN2clVFwXDoGvUpRM2qryY 1s6A/x/w+dv8cB8QzVa73/JchrSsnOFnU1/+3FJcASSUpOsABoPBclzycG9InxzaGnJi CUKyxN5RfhbK4IDM4YP1VYILDggKdEMuHC8yzSLRMUk+fOdEqGA56kpOMOSBA5GIs/PT 4JCQ== X-Gm-Message-State: AOAM530IErtFd6qR0SIEBaoJteHLOP/45YX8h/j1SiWxKp8KoUUyaTrF Vy4C5peRufnpGlAxWd1DCJk6yg== X-Received: by 2002:a17:903:22cd:b0:12d:8876:eea7 with SMTP id y13-20020a17090322cd00b0012d8876eea7mr6462580plg.75.1629277398247; Wed, 18 Aug 2021 02:03:18 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y13sm5730422pfq.147.2021.08.18.02.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 02:03:17 -0700 (PDT) Date: Wed, 18 Aug 2021 02:03:16 -0700 From: Kees Cook To: Vincent MAILHOL Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski , Arunachalam Santhanam , linux-can , netdev , open list , linux-hardening@vger.kernel.org Subject: Re: [PATCH] can: etas_es58x: Replace 0-element raw_msg array Message-ID: <202108180159.5C1CEE70F@keescook> References: <20210818034010.800652-1-keescook@chromium.org> <202108172320.1540EC10C@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 18, 2021 at 04:55:20PM +0900, Vincent MAILHOL wrote: > At the end, the only goal of raw_msg[] is to have a tag pointing > to the beginning of the union. It would be virtually identical to > something like: > | u8 raw_msg[]; > | union { > | /* ... */ > | } __packed ; > > I had a look at your work and especially at your struct_group() macro. > Do you think it would make sense to introduce a union_group()? > > Result would look like: > > | union_group_attr(urb_msg, __packed, /* raw_msg renamed to urb_msg */ > | struct es58x_fd_tx_conf_msg tx_conf_msg; > | u8 tx_can_msg_buf[ES58X_FD_TX_BULK_MAX * ES58X_FD_CANFD_TX_LEN]; > | u8 rx_can_msg_buf[ES58X_FD_RX_BULK_MAX * ES58X_FD_CANFD_RX_LEN]; > | struct es58x_fd_echo_msg echo_msg[ES58X_FD_ECHO_BULK_MAX]; > | struct es58x_fd_rx_event_msg rx_event_msg; > | struct es58x_fd_tx_ack_msg tx_ack_msg; > | __le64 timestamp; > | __le32 rx_cmd_ret_le32; > | ); > > And I can then use urb_msg in place of the old raw_msg (might > need a bit of rework here and there but I can take care of it). > > This is the most pretty way I can think of to remove this zero length array. > Keeping the raw_msg[] but with another size seems odd to me. > > Or maybe I would be the only one using this feature in the full > tree? In that case, maybe it would make sense to keep the > union_group_attr() macro local to the etas_es58x driver? I actually ended up with something close to this idea, but more generalized for other cases in the kernel. There was a sane way to include a "real" flexible array in a union (or alone in a struct), so I've proposed this flex_array() helper: https://lore.kernel.org/lkml/20210818081118.1667663-2-keescook@chromium.org/ and then it's just a drop-in replacement for all the places that need this fixed, including etas_es58x: https://lore.kernel.org/lkml/20210818081118.1667663-3-keescook@chromium.org/#Z30drivers:net:can:usb:etas_es58x:es581_4.h Hopefully this will work out; I think it's as clean as we can get for now. :) -- Kees Cook