Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4000809pxb; Mon, 1 Feb 2021 09:49:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/6sbodOeNeFTmoLrvnSKRQ3duW7zNVQcZIDr3V7ACH5+Y8wTSpQvwcWW1Ci1gEyd3JoF2 X-Received: by 2002:a17:906:b042:: with SMTP id bj2mr18677761ejb.261.1612201778118; Mon, 01 Feb 2021 09:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612201778; cv=none; d=google.com; s=arc-20160816; b=LDAEi4efznQJddtpU1ylgC/OugZwJ/j16vn6ZPKjDZqZzpjNOlGyLOTb0rhZxuNtlr TflijmFfE+smGnbX+xxgWiPLnmdcomHITUQXIy10PqWQIgbVXVb+sgXstmZ8/KfhGXkf NT3qz6f6cnFcEb1Q6w+F55MkbubsGnH2w0vhkbLuq6LAwXD+pJIQ4OIFI9R1uB1JMYrC 5Pl9Wo0WRUg9TGQEwUelq7iPPH2gc/6gpAYogZ3NXJd2PidwZ/jrCNp92BlCOzJxu9+w dNVw7nS0+tMxMlrqfdyirMlXSwZD9n4ptXfTNEQeDEPsoWOi6QFzsu3dZUBwrwEcKBXp Z9Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=Ilj8CfRyaURmt05fJjjTNF7CtOfukuLGhRip5WXm7Lk=; b=z/u+Maxo3b5f5gbzDQ5uzVl+D03AoMb6cr+UXzCiqUWTiP1XaTYF+iUt1VL80HY3RE EPysXGpiFlAtAK20O5fN/e+R0YMFXIu3Vns8johWo5G+K8d7UxKUKy539ebLqKVp2HOD eIa1ddicwYfdL5rE9Wb9lLZvr6hwLh8vqweiMnj8hkU967Mu2BGnGO4FwHCxO9KpbGpR t2UYLCyuIEatIrTlAC2ZZR5/26tfV43U+6xe6nGhOBUkJ7L7c2RMiPVNMhXMR5jqL4om eomfDBLcKG8lMbnRZATdDfypnGQ3pmc9DJSBu3urVnZlargGgjIbGOt42UwuPeS9kVpF R/XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RzHBn+zc; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t9si11164777eji.322.2021.02.01.09.49.13; Mon, 01 Feb 2021 09:49:38 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=RzHBn+zc; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232285AbhBARov (ORCPT + 99 others); Mon, 1 Feb 2021 12:44:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:50580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231287AbhBARoQ (ORCPT ); Mon, 1 Feb 2021 12:44:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD36664E92; Mon, 1 Feb 2021 17:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612201416; bh=6JuMhwiPxB5zwCevxjDcGxnSg7igAiVfttRPt3eGViM=; h=Date:From:To:Cc:Subject:From; b=RzHBn+zcnVxDBGt7mlXIwAfT7kISdYH5yde5MD1mHMHHzUnJCYwEinKiGKenm/oPj 4gNFA30b9y2ujEmDtW5YQx6+2qWOGHUW441BU0QAVYzE59NX54GdVwzJGpDMHW1+CS jzSdNGz1qB89qQ8YCoN4sYtkiTrZqMWtzTVeaI+cKyUCOpRQ/wvNPKhi/vUY3+uqyu Wt9gsJJSJyKk9R0q12r4GD+wtxWaxUOjNSTpdKKwLbjNQ5q8UTL349ir0A4M+4SJYA vHB7/t9hfcSja+Lb8/P5lm8/rlCqx9vIziZXWWMlOk+DJcOleoVH7uLw4CoKTLhNEk d3cD5RMLT/TXQ== Date: Mon, 1 Feb 2021 11:43:34 -0600 From: "Gustavo A. R. Silva" To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] hv: hyperv.h: Replace one-element array with flexible-array in struct icmsg_negotiate Message-ID: <20210201174334.GA171933@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use “flexible array members”[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2]. Refactor the code according to the use of a flexible-array member in struct icmsg_negotiate, instead of a one-element array. Also, this helps the ongoing efforts to enable -Warray-bounds and fix the following warnings: drivers/hv/channel_mgmt.c:315:23: warning: array subscript 1 is above array bounds of ‘struct ic_version[1]’ [-Warray-bounds] drivers/hv/channel_mgmt.c:316:23: warning: array subscript 1 is above array bounds of ‘struct ic_version[1]’ [-Warray-bounds] [1] https://en.wikipedia.org/wiki/Flexible_array_member [2] https://www.kernel.org/doc/html/v5.9/process/deprecated.html#zero-length-and-one-element-arrays Link: https://github.com/KSPP/linux/issues/79 Link: https://github.com/KSPP/linux/issues/109 Signed-off-by: Gustavo A. R. Silva --- include/linux/hyperv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index f0d48a368f13..7877746f1077 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1528,14 +1528,14 @@ struct icmsg_hdr { #define IC_VERSION_NEGOTIATION_MAX_VER_COUNT 100 #define ICMSG_HDR (sizeof(struct vmbuspipe_hdr) + sizeof(struct icmsg_hdr)) #define ICMSG_NEGOTIATE_PKT_SIZE(icframe_vercnt, icmsg_vercnt) \ - (ICMSG_HDR + offsetof(struct icmsg_negotiate, icversion_data) + \ + (ICMSG_HDR + sizeof(struct icmsg_negotiate) + \ (((icframe_vercnt) + (icmsg_vercnt)) * sizeof(struct ic_version))) struct icmsg_negotiate { u16 icframe_vercnt; u16 icmsg_vercnt; u32 reserved; - struct ic_version icversion_data[1]; /* any size array */ + struct ic_version icversion_data[]; /* any size array */ } __packed; struct shutdown_msg_data { -- 2.27.0