Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp97642pxb; Wed, 18 Aug 2021 17:03:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLo0GHMJR6HwE60cLlcr7RDCzCU4Y+UYlRJ9+Hsw8fYBOETjrF64vY6H4eAfQ9MYqdPhqh X-Received: by 2002:a6b:c80f:: with SMTP id y15mr9190137iof.80.1629331420239; Wed, 18 Aug 2021 17:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629331420; cv=none; d=google.com; s=arc-20160816; b=HyQ5+mj1ysGKdMpxlOJdFRpkKhQfztskdScsbYYk8eFVcbGcS4OJGnxuPautTCY4rT 7poSVHhiEqiMQHYnrJS/zq1jHy8aZym1sxCi0IvyyYrGCwZbYslrGaMXWiPGyM3vV3BJ R0RdLrQaguCdG/GbzK53x/lBvPz9jxsPfjVp0mj/AQGmU4vRSqJ+N/b8SsEp5I0NYkmb z81fZp9Xi+/2eYxfbXtTIGhDi6COLmfb/xAKfSWiGwukhZeoenZro02SxpfpWRd9UL6A y9EdGJ190jGolNYY47cI1NOofHycYQ94hVu7ppprcw9IJUFCjx4P+arrNSXErY6CsqqJ 0ESQ== 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=No/CqcYi/ja+9aQOR285LDlQZpZG4tmFE2Pn19n6my4=; b=KE2OB5kawoVGMKwQthvy1gqv3m7nobAYrhPtGJ8PRkrqfNByaprSFf0vmAsZdZovGd h1aeu816d7Bt87PvxW6cf+zrX0r851xhelpJH3IuqiiScV56MgigUdsjOW8wkBXqWpoM DDPUSqKx6pf9t0RvqPOMZWuF5YGKtc6xDT3Gv4/+KvrN0Qgw0Kjq+pb5SvWu8WTUS6Ic /LDKMxIdESFzJJFMn7S4X9bu7Z2NxmO9NDJyDneODDbbIbuafW14c9GWafNHxvBYajBz TaL+vcxx4xOwam5oDY0FW/Sej8e+/psgQ8iWF1TIaoOBUkBFkAS84TVK9G7xxc0ZFSqL Ua4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GCsLDCnT; 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 h9si1631498ils.85.2021.08.18.17.03.27; Wed, 18 Aug 2021 17:03:40 -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=GCsLDCnT; 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 S235392AbhHSACs (ORCPT + 99 others); Wed, 18 Aug 2021 20:02:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234965AbhHSACr (ORCPT ); Wed, 18 Aug 2021 20:02:47 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 916C8C061764 for ; Wed, 18 Aug 2021 17:02:12 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id i21so3811549pfd.8 for ; Wed, 18 Aug 2021 17:02:12 -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=No/CqcYi/ja+9aQOR285LDlQZpZG4tmFE2Pn19n6my4=; b=GCsLDCnT1IGo2ICI8aIFEl7kCwiCIR1K3yHJzTlpK+e6S2iHvTa9PDNboC80JdoO84 7qA4G0tlNAdBMtSHQBeyX6n/AuWMsudOz5uq/iTGlMH10Q9h4POgQqR/tjXC7Id59AgS W54I+QF851939R6t+NKPj0fi0SIIiz3PspBiE= 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=No/CqcYi/ja+9aQOR285LDlQZpZG4tmFE2Pn19n6my4=; b=S2uBUeUev9D67OLJymxZyZ+FMDsLEzjwVcsceI9yNoJk1CVxBkiJR4sOs7NcmPj2IF ytBJqqEBF62ruyNbzbZC37rMZku38jLKXCri8zEAVdS0v6kVZ5zECXHX7Z8/vCMd/Q2G +z6ZU8CGYBrkOqf0CHfpWO0mIFFCbzZbIXKyYahqper3zdQTrFW4u+bLHB0aS56T+1YP qo/9d3JihKp4ax/qemBHGzCcrZXudrDHteRNJHuQHxpBz8k7ZoiSIytDqHyTKHb0jCOe /Ll6WZJSoy4zyx13teL2KAQxwwJGJg/OdRKJ9duv44O0jzNEfCeRhGv0OoakOEkmgPe1 eHQA== X-Gm-Message-State: AOAM530+nyy97PaHLwnvvUWQy0xwEsQx9wXdh/6P4rjnULAOEJDqs5yE FWKtqHcHwV8YaR9FUx/XAhfBhg== X-Received: by 2002:a62:ea0f:0:b029:319:8eef:5ff1 with SMTP id t15-20020a62ea0f0000b02903198eef5ff1mr11907946pfh.74.1629331332031; Wed, 18 Aug 2021 17:02:12 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w9sm872502pja.16.2021.08.18.17.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 17:02:11 -0700 (PDT) Date: Wed, 18 Aug 2021 17:02:10 -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: <202108181659.3DE5E5451@keescook> References: <20210818034010.800652-1-keescook@chromium.org> <202108172320.1540EC10C@keescook> <202108180159.5C1CEE70F@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 06:33:39PM +0900, Vincent MAILHOL wrote: > On Wed. 18 Aug 2021 at 18:03, Kees Cook wrote: > > 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. :) > > The __flex_array itself is a nasty hack :D Indeed. ;) > but the rest is clean. Thanks! > Is this compliant to the C standard? Well, I guess that as long > as both GCC and LLVM supports it, it is safe to add it to the > kernel. The kernel already uses a bunch of compiler extensions, none of which were legal under the C standard to begin with. :) So, really, this is about normalizing what we're already doing and finding a single hack that helps the code base for readability and robustness. > I like the final result. I will do a bit more testing and give my > acknowledgement if everything goes well. Great; thank you! -- Kees Cook