Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp27624rdb; Thu, 16 Nov 2023 10:57:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPvBuuV3pzKe8cCoW9uPU+xPrAyzD+qVGWCSj1vM5VeHTsGFNpJQ60gaapAqjQOmeghbJt X-Received: by 2002:a05:6a20:748d:b0:187:f706:7cca with SMTP id p13-20020a056a20748d00b00187f7067ccamr922257pzd.16.1700161038399; Thu, 16 Nov 2023 10:57:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700161038; cv=none; d=google.com; s=arc-20160816; b=WWrm9ylU+zUJzWF6e4Ehh/DZ/IWSuMhCiIhoCQT1V0AVZON746r0XYld9+CEfFBX4b v1PAiNJ3nxOivi3avsBHhKCgYsHqVcQyMgiem/72Yl6MOTW5VWJODf0TzHHnqI5DgZjv ChdCXSUv5NKxOauI3ynpousxZTXTxgcOxPBpMPA9FgA4AY/oplwYZFg+pmxPgdedQP6C y4ljx8KJiVAjduWkuGvIEUlweZnLhlMSWJEmoB0veCCkPDJXkhNqO3jBlXkFqD9arlgj IlMvocqRAwtFuJviXENN+aDepObJ44vBPUrFWtPYq2zk+DvFl5QKEL51HCpSlKXrOZRf 04OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=OCPJFEqpeLxujmn8gJLKB3zbLNlfUGdZvBYYuSiWDJ8=; fh=grvoduVzbCjvQHNuY8TNqZyALqbAi7v/eKkAflEVkYI=; b=WW2zHrVB6bjXlbrkU4cG9iiwyH/2Wt2lUKKGJQT2cM/Aju0/Jn+TjND5Qx9Um5Yfsl 9VK7NlMi8d8zNBiKdLj+J3tXnQXwtxMZF/hAQeZyUbtXVVbf5Oz3LRSX5PVIOUMBpe4a T2I96aoEYzTsSity1gPdUvcRxhVVOKGRiMsJUddzvQHNPXsPwCm9AHtBQOIcerAH0Ak1 VVWo910eSus2eqWwB7vst1JsycxWqPDMQWHDYbpCyOLPe+oBqk6+279YsOXREMIsMBMe NDRGfmLJEwMciXjLep1qFCp5aILPUi9WFyr7q2/N4zQAt0KveR2tmeWIfDZ/PpxBtXcd Pfag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q2KeOstZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c26-20020a630d1a000000b005acb92781fbsi60064pgl.415.2023.11.16.10.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:57:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q2KeOstZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 08F3280D5843; Thu, 16 Nov 2023 10:56:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbjKPSzG (ORCPT + 99 others); Thu, 16 Nov 2023 13:55:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjKPSzG (ORCPT ); Thu, 16 Nov 2023 13:55:06 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A7FC1A8 for ; Thu, 16 Nov 2023 10:55:03 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BBB8C433C8; Thu, 16 Nov 2023 18:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700160902; bh=JwQgKXdyVFHDeYy2JqIrcrbfOB3OycZsBTQgBU7qjPM=; h=Date:From:To:Cc:Subject:From; b=Q2KeOstZqpSdN4JhKTSNmJecY3BmKrmxV0TKxlDYtF5gv7UBoA9ki8l+3oU7WT0Hx SGmSc3VfEncIDsy7g1gUdu/dUurdmxWoNKqVqXpNG0JIQn/9CRKtLj4EZby3gR0ebM W29DzH+9f5rXc4ky/j82PuHjBZxanaXp2OXpLgfdOeYwEyc8H6InT7BIuTjYwI2twZ K2Q59QirBuKsjjD1uHuCUq6Vt0CT0Ut1+Mc3R70pFEkwWmeLddoRJdAqfYUx+Un6j7 onTVWGPMm6W16RlorLGNo7T/80qIpz+vuwThsSHkscF6lBwIA6x+UPnUOlCQ+Gw8al 9yTiFS6TTIGSg== Date: Thu, 16 Nov 2023 12:54:59 -0600 From: "Gustavo A. R. Silva" To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 16 Nov 2023 10:56:41 -0800 (PST) Fake flexible arrays (zero-length and one-element arrays) are deprecated, and should be replaced by flexible-array members. So, replace zero-length array with a flexible-array member in `struct privcmd_kernel_ioreq`. Also annotate array `ports` with `__counted_by()` to prepare for the coming implementation by GCC and Clang of the `__counted_by` attribute. Flexible array members annotated with `__counted_by` can have their accesses bounds-checked at run-time via `CONFIG_UBSAN_BOUNDS` (for array indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family functions). This fixes multiple -Warray-bounds warnings: drivers/xen/privcmd.c:1239:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] drivers/xen/privcmd.c:1240:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] drivers/xen/privcmd.c:1241:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] drivers/xen/privcmd.c:1245:33: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] drivers/xen/privcmd.c:1258:67: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=] This results in no differences in binary output. Signed-off-by: Gustavo A. R. Silva --- drivers/xen/privcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 1ce7f3c7a950..0eb337a8ec0f 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -1115,7 +1115,7 @@ struct privcmd_kernel_ioreq { spinlock_t lock; /* Protects ioeventfds list */ struct list_head ioeventfds; struct list_head list; - struct ioreq_port ports[0]; + struct ioreq_port ports[] __counted_by(vcpus); }; static irqreturn_t ioeventfd_interrupt(int irq, void *dev_id) -- 2.34.1