From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Bw1+HklB" Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3FA41AD for ; Thu, 16 Nov 2023 10:28:38 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1cc30bf9e22so8578025ad.1 for ; Thu, 16 Nov 2023 10:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700159318; x=1700764118; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7reBGJiccGvFEPh84DNhsMy+d8d0VEfZ803Vs8wYx6A=; b=Bw1+HklBx24qQvlrxlGvf87SNTxgtB2H7RSTrdsZR2AFH/KEUZU6rNkusOea1sCbaZ 6s+REsEmrGSJdW+777sPyeSg/94oYl4/QHj/FAyXh8+M8PfDWi6pDCAEIkfxgQFMh9np TfsUBXnvkRI3p21iy2fFS/mz0lThRZHYoOrjM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700159318; x=1700764118; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7reBGJiccGvFEPh84DNhsMy+d8d0VEfZ803Vs8wYx6A=; b=I6vErTgJY6ZK3bx8MjACEKDIdAAWeGjV3/32YX6ir+jRQQvDFkRT9qpW0k/s6qUe1/ yY4PwqdSd+Hg3cf4Qkzfbf9gOCBGHw5LjK92G7zDig9bcIdPyZmykmwDcZJ5Iu4ozQbv SpVaio9JEiNFSwWGEkcQ9i1uIzyO3kpK36UeMuZ5E2AFrDfiJ4TiCCUSXKyIX9Hz3ZBR eYsstvG/57oYdRwfnMlsY0/V2KftSf13oOK2frOMgzrVirzFcsaaYhKKHu/psTEfJsCc 9bVNKT6Wt/MReNyNfLHZoV40z48bA+6kGoLb92fwrYYdbPDO7fsvSaviEBLVNmKAugsq qtew== X-Gm-Message-State: AOJu0YzSJDfxOKf3wQbysgrffAnDNO/BgYVuxC5B6tGE/nXy1AhXQEIQ aO2wjjKuYB/rxl92cqvoMK2q/Q== X-Google-Smtp-Source: AGHT+IGAIJ1flNjVNFt30991BeOzVwdm7nFOpSj7aipBLifSRgBzIDb+/MN7TcTVw7PDSnp4FgwR1Q== X-Received: by 2002:a17:903:485:b0:1cc:38e6:f097 with SMTP id jj5-20020a170903048500b001cc38e6f097mr3076987plb.7.1700159318125; Thu, 16 Nov 2023 10:28:38 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id t18-20020a1709028c9200b001bdeedd8579sm9514614plo.252.2023.11.16.10.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:28:37 -0800 (PST) Date: Thu, 16 Nov 2023 10:28:37 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Cc: Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] nouveau/gsp: replace zero-length array with flex-array member and use __counted_by Message-ID: <202311161028.E780FBB146@keescook> References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Nov 16, 2023 at 12:11:43PM -0600, Gustavo A. R. Silva wrote: > 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 > PACKED_REGISTRY_TABLE`. > > Also annotate array `entries` 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/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1069:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1070:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1071:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1072:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > > While there, also make use of the struct_size() helper, and address > checkpatch.pl warning: > WARNING: please, no spaces at the start of a line > > This results in no differences in binary output. > > Signed-off-by: Gustavo A. R. Silva Looks nice to me. Reviewed-by: Kees Cook -- Kees Cook From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30E0DC197A0 for ; Thu, 16 Nov 2023 18:28:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4151410E657; Thu, 16 Nov 2023 18:28:41 +0000 (UTC) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9318810E663 for ; Thu, 16 Nov 2023 18:28:38 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1cc53d0030fso8735415ad.0 for ; Thu, 16 Nov 2023 10:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700159318; x=1700764118; darn=lists.freedesktop.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7reBGJiccGvFEPh84DNhsMy+d8d0VEfZ803Vs8wYx6A=; b=C++qO4tx/HxtIn9XdRiJzvnjuROcf/PVIZNJKvyDMFXrtn+cqIjufFgu2TOVnhVdNq Gix/z6NRxnHt6jlap/rqbob9I66145RXiU9T3n7Tj1yWoqzZ2svaAqlGT/l0z2wq2V1M 8U++XFsqywh6B7t2merVbNNUe6KcTxi1QVkGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700159318; x=1700764118; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7reBGJiccGvFEPh84DNhsMy+d8d0VEfZ803Vs8wYx6A=; b=Hb5gp5QELQtU5CXxoQNuGJlycFQk6Cq89BUDHe/nWP5v4dha2MLkirH5CPQTLyel2x /ytRlZcUF3LHZMgnHqSJLOgxkVn3aoz7wcRnvP0Hh6MUS+fo2JIo8WlHPDTahB9thK5g YNKA517vS23fXkDI0ZuJ/2AeU+Hm7OBcqCRBpSCNLurHy7GFT2z8O3VSyot1JE4BaVoe FyBzncUO8yAdMZadhCTR4c9HUopiIXhGPeYij8sChRewKNzjf8+YQ8w9m0+GT4N6APEW lxBZxhuqc1lWItjg4z7OtWwgw/r6nrK0prxSiKDnaVmI1YRULdIohHg3cdPAplExKD4j 0YZQ== X-Gm-Message-State: AOJu0YxG1f86DU0Yy/IIZk3cXvcpBqP7PtO/w80dT9nrJhWacqpTvphM stfmKjTumQbMawJW5OSYZjc7QQ== X-Google-Smtp-Source: AGHT+IGAIJ1flNjVNFt30991BeOzVwdm7nFOpSj7aipBLifSRgBzIDb+/MN7TcTVw7PDSnp4FgwR1Q== X-Received: by 2002:a17:903:485:b0:1cc:38e6:f097 with SMTP id jj5-20020a170903048500b001cc38e6f097mr3076987plb.7.1700159318125; Thu, 16 Nov 2023 10:28:38 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id t18-20020a1709028c9200b001bdeedd8579sm9514614plo.252.2023.11.16.10.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:28:37 -0800 (PST) Date: Thu, 16 Nov 2023 10:28:37 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Message-ID: <202311161028.E780FBB146@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Nouveau] [PATCH][next] nouveau/gsp: replace zero-length array with flex-array member and use __counted_by X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-hardening@vger.kernel.org, Daniel Vetter Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On Thu, Nov 16, 2023 at 12:11:43PM -0600, Gustavo A. R. Silva wrote: > 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 > PACKED_REGISTRY_TABLE`. > > Also annotate array `entries` 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/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1069:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1070:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1071:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1072:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > > While there, also make use of the struct_size() helper, and address > checkpatch.pl warning: > WARNING: please, no spaces at the start of a line > > This results in no differences in binary output. > > Signed-off-by: Gustavo A. R. Silva Looks nice to me. Reviewed-by: Kees Cook -- Kees Cook From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3D46C197A0 for ; Thu, 16 Nov 2023 18:28:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F124D10E658; Thu, 16 Nov 2023 18:28:39 +0000 (UTC) Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by gabe.freedesktop.org (Postfix) with ESMTPS id A5F2010E665 for ; Thu, 16 Nov 2023 18:28:38 +0000 (UTC) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1cc131e52f1so17448375ad.0 for ; Thu, 16 Nov 2023 10:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700159318; x=1700764118; darn=lists.freedesktop.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7reBGJiccGvFEPh84DNhsMy+d8d0VEfZ803Vs8wYx6A=; b=C++qO4tx/HxtIn9XdRiJzvnjuROcf/PVIZNJKvyDMFXrtn+cqIjufFgu2TOVnhVdNq Gix/z6NRxnHt6jlap/rqbob9I66145RXiU9T3n7Tj1yWoqzZ2svaAqlGT/l0z2wq2V1M 8U++XFsqywh6B7t2merVbNNUe6KcTxi1QVkGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700159318; x=1700764118; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7reBGJiccGvFEPh84DNhsMy+d8d0VEfZ803Vs8wYx6A=; b=Mt8BX2HMvkUqCfUlMMGz69ayVGE7iO6kgwH/Ifm7o5F3BoVQE03EKCIOU8WQYcrL/J YWYMHmN+x7mB7mcd9eL6nceq0dVvr7VMJJ91ue3FnMWwx2iR8ASlGPm0KP18Du2tP3X2 U6frtQKOvhSpEUL7nUloK+nRYhXEtNFmmB4g5+pAHGh+QFhoc5uPKUsm/LCgpGh1euU0 smvqkUpMn4kVgBWlwx2muqanTYouga7DK5hIkR/ZEItUaPA/Xq6BUKu3acqUi/7kQH2U AjTdK8iHCwFavasOiS530eElCsH55OJAXXcUnl2Jl8qGf6kxFZTjqXNgNP7yMpS/t3YP Pugw== X-Gm-Message-State: AOJu0YyM5iVH5uak9PYSLIsEj9clgbJpAn4gQA+sW4yFeqTVNzOhvyN1 bTFe/+0Td1VIQ9GyZjjUU0Uvzg== X-Google-Smtp-Source: AGHT+IGAIJ1flNjVNFt30991BeOzVwdm7nFOpSj7aipBLifSRgBzIDb+/MN7TcTVw7PDSnp4FgwR1Q== X-Received: by 2002:a17:903:485:b0:1cc:38e6:f097 with SMTP id jj5-20020a170903048500b001cc38e6f097mr3076987plb.7.1700159318125; Thu, 16 Nov 2023 10:28:38 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id t18-20020a1709028c9200b001bdeedd8579sm9514614plo.252.2023.11.16.10.28.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 10:28:37 -0800 (PST) Date: Thu, 16 Nov 2023 10:28:37 -0800 From: Kees Cook To: "Gustavo A. R. Silva" Subject: Re: [PATCH][next] nouveau/gsp: replace zero-length array with flex-array member and use __counted_by Message-ID: <202311161028.E780FBB146@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Karol Herbst , nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Danilo Krummrich , linux-hardening@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Thu, Nov 16, 2023 at 12:11:43PM -0600, Gustavo A. R. Silva wrote: > 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 > PACKED_REGISTRY_TABLE`. > > Also annotate array `entries` 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/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1069:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1070:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1071:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c:1072:29: warning: array subscript 0 is outside array bounds of 'PACKED_REGISTRY_ENTRY[0]' [-Warray-bounds=] > > While there, also make use of the struct_size() helper, and address > checkpatch.pl warning: > WARNING: please, no spaces at the start of a line > > This results in no differences in binary output. > > Signed-off-by: Gustavo A. R. Silva Looks nice to me. Reviewed-by: Kees Cook -- Kees Cook