Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp158713pxb; Tue, 17 Aug 2021 22:18:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpj8pFgADQVydx7JzuJHZ1B8fb0MWQfWgCMxMRkuh5oYn036tQhenaKU6OYB2FxwsdTI7+ X-Received: by 2002:aa7:da09:: with SMTP id r9mr7995240eds.161.1629263912169; Tue, 17 Aug 2021 22:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629263912; cv=none; d=google.com; s=arc-20160816; b=ICT/H5C3wFh+rTLAytEnI4Ql+FzUbU/y1XCX59slnJBkoYF8DFoAUYKCQqJitK9hbU spZGPeX9NTGuqn7IJ4/WdhwHIeqOvmr3Uq3rZzzGFj24uHGEmNe30FDzUsQgpahv8X+e C/zhu1iAyIahSioVZa3js7j5Yy8fii8zL/2FSSpSjorWTVDh3X+0/bDfyTDmEBUEH8v7 V5q3WVV7dyaJLxfHX6i6fXMo4dV23Eo4TI046oiifSW3lbuHQbYulxWfNmXku2v0hjUT y5a/1YeTP1t0xwjWs8G2AEkGUmtLUiABy4qmFQsZCVVqaPOOKCbuA360rffGmarweAkN 2GXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=dThlhLLrplnuLh2UP7jmiTXGduhqKRmat16fPmXeSs4=; b=0QKZhtP3ajoILerRlDjk/txAg+YxSvSNIWJdelYY/k5NnvlF5G4qi7+AWWPboaueHN CLbDXb1WwQEw+qwJhKQxOx2V32J6FdrsM8uGhy6OlH5d6apPX/vyb/c125HkbxpVNG7E 5SDfKcaFgSNsYS6Q45o3YOuqSDB0P06sagAND+Qe/mR5Xlu0v8Iw7dpu/cuBWgC+74sO 97WdabEAPUmNJlzR7j5efP587AjH3CGO4vwhzgprTGPNi5V4dknM1rxZTu1B/GrdtgLv XikiqrPsHwM6va+pHSOYODxqhZ/qsHhPpEsoxaTHYRccrmUnlSUtXLAmtaHGia7Yh5un PJpw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq37si5055206ejc.56.2021.08.17.22.18.08; Tue, 17 Aug 2021 22:18:32 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237672AbhHRFOi (ORCPT + 99 others); Wed, 18 Aug 2021 01:14:38 -0400 Received: from mail-lf1-f53.google.com ([209.85.167.53]:45724 "EHLO mail-lf1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232380AbhHRFOi (ORCPT ); Wed, 18 Aug 2021 01:14:38 -0400 Received: by mail-lf1-f53.google.com with SMTP id g13so1930651lfj.12; Tue, 17 Aug 2021 22:14:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dThlhLLrplnuLh2UP7jmiTXGduhqKRmat16fPmXeSs4=; b=mJMGN8v2uzWYrKsMoCbN/zimJ+q+km9nqHHf00Nw/i0zZ9aChKgb+MqX/n3hsizlCh 2if2pDhs/Aq5iNpxMyp2tIG2oX3bmtdYw27M+OMEGy/A9vt5RCFHxj7REJJxhDptpXID YSHQmMz4BPpeMRx5rx8EYb/NHJ1aaA00IEulfbYkLdcUnLnm2YV10xWLPfg23k19P97Q etwKG5LPsOR43rkYgjRucyuekdBoj/VNTURRNrP1NemTnxhr/kGMVD26x8vE0T5g65Us 6XnGeoVxZgZ/6PFG+9aWhYPsBTZiOPIQw0foMuSKnHFftzqAkg7v6PlgJtJ8QI7V+5UA ckbQ== X-Gm-Message-State: AOAM532rc/NUUIEtYO8OZUYN8Jq3hY2xJFPs+CGN2FJHTV99apgNUz/Y WqFn0+fz24D7+shASMKCUPw0Sy3eg4hw8HJmHL8= X-Received: by 2002:ac2:5d27:: with SMTP id i7mr5022735lfb.488.1629263642539; Tue, 17 Aug 2021 22:14:02 -0700 (PDT) MIME-Version: 1.0 References: <20210818034010.800652-1-keescook@chromium.org> In-Reply-To: <20210818034010.800652-1-keescook@chromium.org> From: Vincent MAILHOL Date: Wed, 18 Aug 2021 14:13:51 +0900 Message-ID: Subject: Re: [PATCH] can: etas_es58x: Replace 0-element raw_msg array To: Kees Cook Cc: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Jakub Kicinski , Arunachalam Santhanam , linux-can , netdev , open list , linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed. 18 Aug 2021 at 12:40, Kees Cook wrote: > While raw_msg isn't a fixed size, it does have a maximum size. Adjust the > struct to represent this and avoid the following warning when building > with -Wzero-length-bounds: > > drivers/net/can/usb/etas_es58x/es58x_fd.c: In function 'es58x_fd_tx_can_msg': > drivers/net/can/usb/etas_es58x/es58x_fd.c:360:35: warning: array subscript 65535 is outside the bounds of an interior zero-length array 'u8[0]' {aka 'unsigned char[]'} [-Wzero-length-bounds] > 360 | tx_can_msg = (typeof(tx_can_msg))&es58x_fd_urb_cmd->raw_msg[msg_len]; > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:22, > from drivers/net/can/usb/etas_es58x/es58x_fd.c:17: > drivers/net/can/usb/etas_es58x/es58x_fd.h:231:6: note: while referencing 'raw_msg' > 231 | u8 raw_msg[0]; > | ^~~~~~~ > > Cc: Wolfgang Grandegger > Cc: Marc Kleine-Budde > Cc: "David S. Miller" > Cc: Jakub Kicinski > Cc: Arunachalam Santhanam > Cc: Vincent Mailhol > Cc: linux-can@vger.kernel.org > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- > drivers/net/can/usb/etas_es58x/es581_4.h | 2 +- > drivers/net/can/usb/etas_es58x/es58x_fd.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/can/usb/etas_es58x/es581_4.h b/drivers/net/can/usb/etas_es58x/es581_4.h > index 4bc60a6df697..af38c4938859 100644 > --- a/drivers/net/can/usb/etas_es58x/es581_4.h > +++ b/drivers/net/can/usb/etas_es58x/es581_4.h > @@ -192,7 +192,7 @@ struct es581_4_urb_cmd { > struct es581_4_rx_cmd_ret rx_cmd_ret; > __le64 timestamp; > u8 rx_cmd_ret_u8; > - u8 raw_msg[0]; > + u8 raw_msg[USHRT_MAX]; > } __packed; > > __le16 reserved_for_crc16_do_not_use; > diff --git a/drivers/net/can/usb/etas_es58x/es58x_fd.h b/drivers/net/can/usb/etas_es58x/es58x_fd.h > index ee18a87e40c0..e0319b8358ef 100644 > --- a/drivers/net/can/usb/etas_es58x/es58x_fd.h > +++ b/drivers/net/can/usb/etas_es58x/es58x_fd.h > @@ -228,7 +228,7 @@ struct es58x_fd_urb_cmd { > struct es58x_fd_tx_ack_msg tx_ack_msg; > __le64 timestamp; > __le32 rx_cmd_ret_le32; > - u8 raw_msg[0]; > + u8 raw_msg[USHRT_MAX]; > } __packed; > > __le16 reserved_for_crc16_do_not_use; > -- > 2.30.2 raw_msg is part of a union so its maximum size is implicitly the biggest size of the other member of that union: | struct es58x_fd_urb_cmd { | __le16 SOF; | u8 cmd_type; | u8 cmd_id; | u8 channel_idx; | __le16 msg_len; | | union { | 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; | u8 raw_msg[0]; | } __packed; | | __le16 reserved_for_crc16_do_not_use; | } __packed; ram_msg can then be used to manipulate the other fields at the byte level. I am sorry but I fail to understand why this is an issue. Also, the proposed fix drastically increases the size of the structure. Yours sincerely, Vincent