Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp259581ybm; Thu, 28 May 2020 22:39:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+8B+WR9aTPrm/9cgdwS2yaEs+FMvdDKbQI2cdV3cRIPfChzzv3B4f7KcwgQCoJtIBJ4GH X-Received: by 2002:a50:fa8d:: with SMTP id w13mr6270092edr.280.1590730766614; Thu, 28 May 2020 22:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590730766; cv=none; d=google.com; s=arc-20160816; b=DoA1KUhYKJmEb+QVGBvIz4XP5kOlBxiYnGU4FG7HsllLwr1gdSXNAx5jMoKPyWEBHf 4u5ZChzyWQ+m6xTFubri1A8mQfhcGZ2Oh47P3xFmJNv6YAtWnRshHz256+1B30ni6Vqf 0gPJ/e/89eYO9/jgh8DZ0E6E+LSSapW4q7wYECFd6bLyY6uXxTygwFiZJ2alOw1Wf05O kk3B8aGHd4p50DtZ+AC77H/ZvnyDskv74F8dZElVbn6kP903FHF53QDZkUQVDUbYS394 1Amnq4linoW9pKy/30KdBfiVc+r7xgzJTtu4AcvmHQWSwKgJRLnvkSmkxBu7npa5Bf8b Tiow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=+RSbyrmn67gklznHON3cIB8cE6n0imfBhn2/0A4Pj/Q=; b=GcG3opJsy1HLs4Y0b5/zllJ0ac9ESPNQxSix2k6MZkMjSq+Q1ZM5EUY61CTvhUHTZT 3Nux8Ggjyu7WLdyePjur2VXC//V8kpXMiwoYbu/rEIAhyFzP1NDI9xBftAaHY/nrw+7I C16VyenRsxShoK8Ecog8b95R4FYF6Y6eJ3HRzUloARag51331v9mDGuot3HVJUlNGN+H vK6gM4MMCGh8hPmhZUBORuBfQaE3D73uw7YFkRn8bfuFY257P3hWcbKfQ1xN/aZyi/7s +2IZHyODOAy48cT9njIMwHbzHhtnwbeXtDKruLxURlm39LPsB/TLDleM2v3CL7JXxmRv u5HA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h1si4587784edq.86.2020.05.28.22.39.03; Thu, 28 May 2020 22:39:26 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725901AbgE2FfL convert rfc822-to-8bit (ORCPT + 99 others); Fri, 29 May 2020 01:35:11 -0400 Received: from mga02.intel.com ([134.134.136.20]:15353 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgE2FfK (ORCPT ); Fri, 29 May 2020 01:35:10 -0400 IronPort-SDR: Nr8GJnKLkkq7JkdDtxsHPUTabbtSHn5N8zNfabu2iS6Fnqwq46jL9Zi8mtlWbWzaJ9biDdTVph n32Rg9iHNCew== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 22:35:10 -0700 IronPort-SDR: x400dgFeBGYYcZf6at12iSswF0xD65yizzDfsHkKQorANkWQH8dBDMs/iN7EFBJpejnqYz2AVt zvwbRSCrA5YA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,447,1583222400"; d="scan'208";a="302723578" Received: from orsmsx110.amr.corp.intel.com ([10.22.240.8]) by fmsmga002.fm.intel.com with ESMTP; 28 May 2020 22:35:09 -0700 Received: from orsmsx112.amr.corp.intel.com ([169.254.3.61]) by ORSMSX110.amr.corp.intel.com ([169.254.10.119]) with mapi id 14.03.0439.000; Thu, 28 May 2020 22:35:09 -0700 From: "Kirsher, Jeffrey T" To: "Gustavo A. R. Silva" , "David S. Miller" , Jakub Kicinski , "Allan, Bruce W" CC: "intel-wired-lan@lists.osuosl.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Gustavo A. R. Silva" , Kees Cook Subject: RE: [PATCH net-next v3] ice: Replace one-element arrays with flexible-arrays Thread-Topic: [PATCH net-next v3] ice: Replace one-element arrays with flexible-arrays Thread-Index: AQHWNDACNpPEgN+IHEW5ZY2UVT3OQ6i+jFOg Date: Fri, 29 May 2020 05:35:09 +0000 Message-ID: <61CC2BC414934749BD9F5BF3D5D94044986DE746@ORSMSX112.amr.corp.intel.com> References: <20200527141119.GA30849@embeddedor> In-Reply-To: <20200527141119.GA30849@embeddedor> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.22.254.140] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Gustavo A. R. Silva > Sent: Wednesday, May 27, 2020 07:11 > To: Kirsher, Jeffrey T ; David S. Miller > ; Jakub Kicinski > Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux- > kernel@vger.kernel.org; Gustavo A. R. Silva ; > Kees Cook > Subject: [PATCH net-next v3] ice: Replace one-element arrays with flexible- > arrays > > The current codebase makes use of one-element arrays in the following > form: > > struct something { > int length; > u8 data[1]; > }; > > struct something *instance; > > instance = kmalloc(sizeof(*instance) + size, GFP_KERNEL); > instance->length = size; > memcpy(instance->data, source, size); > > but the preferred mechanism to declare variable-length types such as these > ones is a flexible array member[1][2], introduced in C99: > > struct foo { > int stuff; > struct boo array[]; > }; > > By making use of the mechanism above, we will get a compiler warning in case > the flexible array does not occur last in the structure, which will help us prevent > some kind of undefined behavior bugs from being inadvertently introduced[3] > to the codebase from now on. So, replace the one-element array with a > flexible-array member. > > Also, make use of the offsetof() helper in order to simplify some macros and > properly calculate the size of the structures that contain flexible-array members. > > This issue was found with the help of Coccinelle and, audited _manually_. > > [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html > [2] https://github.com/KSPP/linux/issues/21 > [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") > > Signed-off-by: Gustavo A. R. Silva [Kirsher, Jeffrey T] Thanks Gustavo, but we (or I should say Bruce Allan) already has a patch to resolve this, and is a bit more thorough. I will make sure you get CC'd on the patch, for your review. > --- > Changes in v3: > - We still can simply the code even more by using offsetof() just once. :) > > Changes in v2: > - Use offsetof(struct ice_aqc_sw_rules_elem, pdata) instead of > sizeof(struct ice_aqc_sw_rules_elem) - sizeof(((struct ice_aqc_sw_rules_elem > *)0)->pdata) > - Update changelog text. > > .../net/ethernet/intel/ice/ice_adminq_cmd.h | 6 ++--- > drivers/net/ethernet/intel/ice/ice_switch.c | 23 ++++++------------- > 2 files changed, 10 insertions(+), 19 deletions(-) >