dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] drm: Annotate structs with __counted_by
@ 2023-09-22 17:32 Kees Cook
  2023-09-22 17:32 ` [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table " Kees Cook
                   ` (9 more replies)
  0 siblings, 10 replies; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Alex Deucher, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Dmitry Baryshkov,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

Hi,

This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

As found with Coccinelle[1], add __counted_by to structs that would
benefit from the annotation.

Since the element count member must be set before accessing the annotated
flexible array member, some patches also move the member's initialization
earlier. (These are noted in the individual patches.)

-Kees

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Kees Cook (9):
  drm/amd/pm: Annotate struct smu10_voltage_dependency_table with
    __counted_by
  drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
  drm/i915/selftests: Annotate struct perf_series with __counted_by
  drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
  drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
  drm/vc4: Annotate struct vc4_perfmon with __counted_by
  drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
  drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
  drm/v3d: Annotate struct v3d_perfmon with __counted_by

 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c        | 2 +-
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
 drivers/gpu/drm/i915/selftests/i915_request.c        | 2 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h    | 2 +-
 drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h        | 2 +-
 drivers/gpu/drm/v3d/v3d_drv.h                        | 2 +-
 drivers/gpu/drm/vc4/vc4_drv.h                        | 2 +-
 drivers/gpu/drm/virtio/virtgpu_drv.h                 | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c              | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-22 17:41   ` Alex Deucher
  2023-09-23  2:13   ` Gustavo A. R. Silva
  2023-09-22 17:32 ` [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance " Kees Cook
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Evan Quan <evan.quan@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Xiaojian Du <Xiaojian.Du@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Kevin Wang <kevin1.wang@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
index 808e0ecbe1f0..42adc2a3dcbc 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
@@ -192,7 +192,7 @@ struct smu10_clock_voltage_dependency_record {
 
 struct smu10_voltage_dependency_table {
 	uint32_t count;
-	struct smu10_clock_voltage_dependency_record entries[];
+	struct smu10_clock_voltage_dependency_record entries[] __counted_by(count);
 };
 
 struct smu10_clock_voltage_information {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
  2023-09-22 17:32 ` [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-22 17:42   ` Alex Deucher
  2023-09-23  2:14   ` Gustavo A. R. Silva
  2023-09-22 17:32 ` [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series " Kees Cook
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct ip_hw_instance.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Hawking Zhang <Hawking.Zhang@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index d1bc7b212520..be4c97a3d7bf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -662,7 +662,7 @@ struct ip_hw_instance {
 	u8  harvest;
 
 	int num_base_addresses;
-	u32 base_addr[];
+	u32 base_addr[] __counted_by(num_base_addresses);
 };
 
 struct ip_hw_id {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
  2023-09-22 17:32 ` [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table " Kees Cook
  2023-09-22 17:32 ` [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-23  2:14   ` Gustavo A. R. Silva
                     ` (2 more replies)
  2023-09-22 17:32 ` [PATCH 4/9] drm/msm/dpu: Annotate struct dpu_hw_intr " Kees Cook
                   ` (6 subsequent siblings)
  9 siblings, 3 replies; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct perf_series.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: John Harrison <john.c.harrison@Intel.com>
Cc: Andi Shyti <andi.shyti@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/i915/selftests/i915_request.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
index a9b79888c193..acae30a04a94 100644
--- a/drivers/gpu/drm/i915/selftests/i915_request.c
+++ b/drivers/gpu/drm/i915/selftests/i915_request.c
@@ -1924,7 +1924,7 @@ struct perf_stats {
 struct perf_series {
 	struct drm_i915_private *i915;
 	unsigned int nengines;
-	struct intel_context *ce[];
+	struct intel_context *ce[] __counted_by(nengines);
 };
 
 static int cmp_u32(const void *A, const void *B)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (2 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-23  2:15   ` Gustavo A. R. Silva
  2023-09-22 17:32 ` [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom " Kees Cook
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, Lang Yu, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, freedreno, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct dpu_hw_intr.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Rob Clark <robdclark@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Sean Paul <sean@poorly.run>
Cc: Marijn Suijten <marijn.suijten@somainline.org>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: linux-arm-msm@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: freedreno@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h
index dab761e54863..50cf9523d367 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h
@@ -61,7 +61,7 @@ struct dpu_hw_intr {
 		void (*cb)(void *arg, int irq_idx);
 		void *arg;
 		atomic_t count;
-	} irq_tbl[];
+	} irq_tbl[] __counted_by(total_irqs);
 };
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (3 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 4/9] drm/msm/dpu: Annotate struct dpu_hw_intr " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-22 19:00   ` Lyude Paul
  2023-09-23  2:15   ` Gustavo A. R. Silva
  2023-09-22 17:32 ` [PATCH 6/9] drm/vc4: Annotate struct vc4_perfmon " Kees Cook
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Karol Herbst, nouveau, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Emma Anholt,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, Tom Rix,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct nvkm_perfdom.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h b/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
index 6ae25d3e7f45..c011227f7052 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
@@ -82,7 +82,7 @@ struct nvkm_perfdom {
 	u8  mode;
 	u32 clk;
 	u16 signal_nr;
-	struct nvkm_perfsig signal[];
+	struct nvkm_perfsig signal[] __counted_by(signal_nr);
 };
 
 struct nvkm_funcdom {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (4 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-23  2:16   ` Gustavo A. R. Silva
  2023-09-22 17:32 ` [PATCH 7/9] drm/virtio: Annotate struct virtio_gpu_object_array " Kees Cook
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct vc4_perfmon.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Emma Anholt <emma@anholt.net>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/vc4/vc4_drv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index bf66499765fb..ab61e96e7e14 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -76,7 +76,7 @@ struct vc4_perfmon {
 	 * Note that counter values can't be reset, but you can fake a reset by
 	 * destroying the perfmon and creating a new one.
 	 */
-	u64 counters[];
+	u64 counters[] __counted_by(ncounters);
 };
 
 struct vc4_dev {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (5 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 6/9] drm/vc4: Annotate struct vc4_perfmon " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-23  2:36   ` Gustavo A. R. Silva
  2023-09-22 17:32 ` [PATCH 8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty " Kees Cook
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct virtio_gpu_object_array.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: David Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: virtualization@lists.linux-foundation.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
index 8513b671f871..96365a772f77 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -119,7 +119,7 @@ struct virtio_gpu_object_array {
 	struct ww_acquire_ctx ticket;
 	struct list_head next;
 	u32 nents, total;
-	struct drm_gem_object *objs[];
+	struct drm_gem_object *objs[] __counted_by(total);
 };
 
 struct virtio_gpu_vbuffer;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (6 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 7/9] drm/virtio: Annotate struct virtio_gpu_object_array " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-22 21:50   ` Zack Rusin
  2023-09-22 17:32 ` [PATCH 9/9] drm/v3d: Annotate struct v3d_perfmon " Kees Cook
  2023-09-29 19:33 ` [PATCH 0/9] drm: Annotate structs " Kees Cook
  9 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct vmw_surface_dirty.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Zack Rusin <zackr@vmware.com>
Cc: VMware Graphics Reviewers <linux-graphics-maintainer@vmware.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 5db403ee8261..2d1d857f99ae 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -77,7 +77,7 @@ struct vmw_surface_offset {
 struct vmw_surface_dirty {
 	struct vmw_surface_cache cache;
 	u32 num_subres;
-	SVGA3dBox boxes[];
+	SVGA3dBox boxes[] __counted_by(num_subres);
 };
 
 static void vmw_user_surface_free(struct vmw_resource *res);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH 9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (7 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty " Kees Cook
@ 2023-09-22 17:32 ` Kees Cook
  2023-09-28 15:16   ` Maira Canal
  2023-09-29 19:33 ` [PATCH 0/9] drm: Annotate structs " Kees Cook
  9 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-22 17:32 UTC (permalink / raw)
  To: David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Kees Cook, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Melissa Wen, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul,
	Tvrtko Ursulin, Xiaojian Du, Le Ma, freedreno, Bjorn Andersson,
	Pan, Xinhui, Nick Desaulniers, linux-kernel, Alex Deucher,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct v3d_perfmon.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc: Emma Anholt <emma@anholt.net>
Cc: Melissa Wen <mwen@igalia.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/v3d/v3d_drv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h
index 7f664a4b2a75..106454f28956 100644
--- a/drivers/gpu/drm/v3d/v3d_drv.h
+++ b/drivers/gpu/drm/v3d/v3d_drv.h
@@ -59,7 +59,7 @@ struct v3d_perfmon {
 	 * values can't be reset, but you can fake a reset by
 	 * destroying the perfmon and creating a new one.
 	 */
-	u64 values[];
+	u64 values[] __counted_by(ncounters);
 };
 
 struct v3d_dev {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-22 17:32 ` [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table " Kees Cook
@ 2023-09-22 17:41   ` Alex Deucher
  2023-09-25  6:30     ` Christian König
  2023-09-23  2:13   ` Gustavo A. R. Silva
  1 sibling, 1 reply; 40+ messages in thread
From: Alex Deucher @ 2023-09-22 17:41 UTC (permalink / raw)
  To: Kees Cook
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Evan Quan,
	Emma Anholt, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, Alex Deucher,
	Lijo Lazar, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor,
	Le Ma, Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	Christian König, John Harrison, linux-hardening

On Fri, Sep 22, 2023 at 1:32 PM Kees Cook <keescook@chromium.org> wrote:
>
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Evan Quan <evan.quan@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Xiaojian Du <Xiaojian.Du@amd.com>
> Cc: Huang Rui <ray.huang@amd.com>
> Cc: Kevin Wang <kevin1.wang@amd.com>
> Cc: amd-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> index 808e0ecbe1f0..42adc2a3dcbc 100644
> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> @@ -192,7 +192,7 @@ struct smu10_clock_voltage_dependency_record {
>
>  struct smu10_voltage_dependency_table {
>         uint32_t count;
> -       struct smu10_clock_voltage_dependency_record entries[];
> +       struct smu10_clock_voltage_dependency_record entries[] __counted_by(count);
>  };
>
>  struct smu10_clock_voltage_information {
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
  2023-09-22 17:32 ` [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance " Kees Cook
@ 2023-09-22 17:42   ` Alex Deucher
  2023-09-23  2:14   ` Gustavo A. R. Silva
  1 sibling, 0 replies; 40+ messages in thread
From: Alex Deucher @ 2023-09-22 17:42 UTC (permalink / raw)
  To: Kees Cook
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Evan Quan,
	Emma Anholt, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, Alex Deucher,
	Lijo Lazar, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor,
	Le Ma, Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	Christian König, John Harrison, linux-hardening

On Fri, Sep 22, 2023 at 1:33 PM Kees Cook <keescook@chromium.org> wrote:
>
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct ip_hw_instance.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Hawking Zhang <Hawking.Zhang@amd.com>
> Cc: amd-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index d1bc7b212520..be4c97a3d7bf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -662,7 +662,7 @@ struct ip_hw_instance {
>         u8  harvest;
>
>         int num_base_addresses;
> -       u32 base_addr[];
> +       u32 base_addr[] __counted_by(num_base_addresses);
>  };
>
>  struct ip_hw_id {
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
  2023-09-22 17:32 ` [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom " Kees Cook
@ 2023-09-22 19:00   ` Lyude Paul
  2023-09-23  2:15   ` Gustavo A. R. Silva
  1 sibling, 0 replies; 40+ messages in thread
From: Lyude Paul @ 2023-09-22 19:00 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Karol Herbst, nouveau, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Emma Anholt,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, Tom Rix,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

Reviewed-by: Lyude Paul <lyude@redhat.com>

Thanks!

On Fri, 2023-09-22 at 10:32 -0700, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct nvkm_perfdom.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: Karol Herbst <kherbst@redhat.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Cc: nouveau@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h b/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
> index 6ae25d3e7f45..c011227f7052 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
> +++ b/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
> @@ -82,7 +82,7 @@ struct nvkm_perfdom {
>  	u8  mode;
>  	u32 clk;
>  	u16 signal_nr;
> -	struct nvkm_perfsig signal[];
> +	struct nvkm_perfsig signal[] __counted_by(signal_nr);
>  };
>  
>  struct nvkm_funcdom {

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
  2023-09-22 17:32 ` [PATCH 8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty " Kees Cook
@ 2023-09-22 21:50   ` Zack Rusin
  0 siblings, 0 replies; 40+ messages in thread
From: Zack Rusin @ 2023-09-22 21:50 UTC (permalink / raw)
  To: keescook, airlied
  Cc: tejas.upadhyay, emma, trix, llvm, dri-devel, chris, Prike.Liang,
	ray.huang, linux-hardening, andrzej.hajda, marijn.suijten,
	matthew.brost, evan.quan, kherbst, neil.armstrong, amd-gfx,
	quic_khsieh, Linux-graphics-maintainer, bskeggs, andi.shyti,
	nouveau, airlied, alexander.deucher, lijo.lazar, tvrtko.ursulin,
	linux-arm-msm, intel-gfx, kevin1.wang, quic_abhinavk, mripard,
	nathan, le.ma, gurchetansingh, rodrigo.vivi, virtualization,
	sean, yifan1.zhang, kraxel, Xiaojian.Du, freedreno, andersson,
	Xinhui.Pan, ndesaulniers, linux-kernel, mwen, dmitry.baryshkov,
	Hawking.Zhang, Lang.Yu, christian.koenig, john.c.harrison,
	nirmoy.das

On Fri, 2023-09-22 at 10:32 -0700, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct vmw_surface_dirty.
> 
> [1]
> https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Zack Rusin <zackr@vmware.com>
> Cc: VMware Graphics Reviewers <linux-graphics-maintainer@vmware.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> index 5db403ee8261..2d1d857f99ae 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
> @@ -77,7 +77,7 @@ struct vmw_surface_offset {
>  struct vmw_surface_dirty {
>         struct vmw_surface_cache cache;
>         u32 num_subres;
> -       SVGA3dBox boxes[];
> +       SVGA3dBox boxes[] __counted_by(num_subres);
>  };
>  
>  static void vmw_user_surface_free(struct vmw_resource *res);

Thanks!

Reviewed-by: Zack Rusin <zackr@vmware.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-22 17:32 ` [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table " Kees Cook
  2023-09-22 17:41   ` Alex Deucher
@ 2023-09-23  2:13   ` Gustavo A. R. Silva
  1 sibling, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:13 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Evan Quan <evan.quan@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Xiaojian Du <Xiaojian.Du@amd.com>
> Cc: Huang Rui <ray.huang@amd.com>
> Cc: Kevin Wang <kevin1.wang@amd.com>
> Cc: amd-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo


> ---
>   drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> index 808e0ecbe1f0..42adc2a3dcbc 100644
> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> @@ -192,7 +192,7 @@ struct smu10_clock_voltage_dependency_record {
>   
>   struct smu10_voltage_dependency_table {
>   	uint32_t count;
> -	struct smu10_clock_voltage_dependency_record entries[];
> +	struct smu10_clock_voltage_dependency_record entries[] __counted_by(count);
>   };
>   
>   struct smu10_clock_voltage_information {

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
  2023-09-22 17:32 ` [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance " Kees Cook
  2023-09-22 17:42   ` Alex Deucher
@ 2023-09-23  2:14   ` Gustavo A. R. Silva
  1 sibling, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:14 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct ip_hw_instance.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Hawking Zhang <Hawking.Zhang@amd.com>
> Cc: amd-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index d1bc7b212520..be4c97a3d7bf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -662,7 +662,7 @@ struct ip_hw_instance {
>   	u8  harvest;
>   
>   	int num_base_addresses;
> -	u32 base_addr[];
> +	u32 base_addr[] __counted_by(num_base_addresses);
>   };
>   
>   struct ip_hw_id {

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
  2023-09-22 17:32 ` [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series " Kees Cook
@ 2023-09-23  2:14   ` Gustavo A. R. Silva
  2023-09-25 10:08   ` Andrzej Hajda
  2023-09-25 12:20   ` Andi Shyti
  2 siblings, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:14 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct perf_series.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: John Harrison <john.c.harrison@Intel.com>
> Cc: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: intel-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/gpu/drm/i915/selftests/i915_request.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
> index a9b79888c193..acae30a04a94 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_request.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_request.c
> @@ -1924,7 +1924,7 @@ struct perf_stats {
>   struct perf_series {
>   	struct drm_i915_private *i915;
>   	unsigned int nengines;
> -	struct intel_context *ce[];
> +	struct intel_context *ce[] __counted_by(nengines);
>   };
>   
>   static int cmp_u32(const void *A, const void *B)

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
  2023-09-22 17:32 ` [PATCH 4/9] drm/msm/dpu: Annotate struct dpu_hw_intr " Kees Cook
@ 2023-09-23  2:15   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:15 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, Lang Yu, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, freedreno,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct dpu_hw_intr.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Cc: Sean Paul <sean@poorly.run>
> Cc: Marijn Suijten <marijn.suijten@somainline.org>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Bjorn Andersson <andersson@kernel.org>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org
> Cc: freedreno@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h
> index dab761e54863..50cf9523d367 100644
> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h
> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_interrupts.h
> @@ -61,7 +61,7 @@ struct dpu_hw_intr {
>   		void (*cb)(void *arg, int irq_idx);
>   		void *arg;
>   		atomic_t count;
> -	} irq_tbl[];
> +	} irq_tbl[] __counted_by(total_irqs);
>   };
>   
>   /**

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
  2023-09-22 17:32 ` [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom " Kees Cook
  2023-09-22 19:00   ` Lyude Paul
@ 2023-09-23  2:15   ` Gustavo A. R. Silva
  1 sibling, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:15 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, nouveau, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, Tom Rix,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct nvkm_perfdom.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Ben Skeggs <bskeggs@redhat.com>
> Cc: Karol Herbst <kherbst@redhat.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Cc: nouveau@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h b/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
> index 6ae25d3e7f45..c011227f7052 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
> +++ b/drivers/gpu/drm/nouveau/nvkm/engine/pm/priv.h
> @@ -82,7 +82,7 @@ struct nvkm_perfdom {
>   	u8  mode;
>   	u32 clk;
>   	u16 signal_nr;
> -	struct nvkm_perfsig signal[];
> +	struct nvkm_perfsig signal[] __counted_by(signal_nr);
>   };
>   
>   struct nvkm_funcdom {

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
  2023-09-22 17:32 ` [PATCH 6/9] drm/vc4: Annotate struct vc4_perfmon " Kees Cook
@ 2023-09-23  2:16   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:16 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct vc4_perfmon.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Emma Anholt <emma@anholt.net>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/gpu/drm/vc4/vc4_drv.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> index bf66499765fb..ab61e96e7e14 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.h
> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> @@ -76,7 +76,7 @@ struct vc4_perfmon {
>   	 * Note that counter values can't be reset, but you can fake a reset by
>   	 * destroying the perfmon and creating a new one.
>   	 */
> -	u64 counters[];
> +	u64 counters[] __counted_by(ncounters);
>   };
>   
>   struct vc4_dev {

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
  2023-09-22 17:32 ` [PATCH 7/9] drm/virtio: Annotate struct virtio_gpu_object_array " Kees Cook
@ 2023-09-23  2:36   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 40+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-23  2:36 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 9/22/23 11:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct virtio_gpu_object_array.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: David Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Gurchetan Singh <gurchetansingh@chromium.org>
> Cc: Chia-I Wu <olvaffe@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Cc: virtualization@lists.linux-foundation.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-- 
Gustavo

> ---
>   drivers/gpu/drm/virtio/virtgpu_drv.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
> index 8513b671f871..96365a772f77 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_drv.h
> +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
> @@ -119,7 +119,7 @@ struct virtio_gpu_object_array {
>   	struct ww_acquire_ctx ticket;
>   	struct list_head next;
>   	u32 nents, total;
> -	struct drm_gem_object *objs[];
> +	struct drm_gem_object *objs[] __counted_by(total);
>   };
>   
>   struct virtio_gpu_vbuffer;

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-22 17:41   ` Alex Deucher
@ 2023-09-25  6:30     ` Christian König
  2023-09-25 14:07       ` Alex Deucher
  2023-09-25 17:52       ` Kees Cook
  0 siblings, 2 replies; 40+ messages in thread
From: Christian König @ 2023-09-25  6:30 UTC (permalink / raw)
  To: Alex Deucher, Kees Cook
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Evan Quan,
	Emma Anholt, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, Alex Deucher,
	Lijo Lazar, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor,
	Le Ma, Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	John Harrison, linux-hardening

Am 22.09.23 um 19:41 schrieb Alex Deucher:
> On Fri, Sep 22, 2023 at 1:32 PM Kees Cook <keescook@chromium.org> wrote:
>> 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 checking via CONFIG_UBSAN_BOUNDS
>> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
>> functions).
>>
>> As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
>>
>> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>>
>> Cc: Evan Quan <evan.quan@amd.com>
>> Cc: Alex Deucher <alexander.deucher@amd.com>
>> Cc: "Christian König" <christian.koenig@amd.com>
>> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
>> Cc: David Airlie <airlied@gmail.com>
>> Cc: Daniel Vetter <daniel@ffwll.ch>
>> Cc: Xiaojian Du <Xiaojian.Du@amd.com>
>> Cc: Huang Rui <ray.huang@amd.com>
>> Cc: Kevin Wang <kevin1.wang@amd.com>
>> Cc: amd-gfx@lists.freedesktop.org
>> Cc: dri-devel@lists.freedesktop.org
>> Signed-off-by: Kees Cook <keescook@chromium.org>
> Acked-by: Alex Deucher <alexander.deucher@amd.com>

Mhm, I'm not sure if this is a good idea. That is a structure filled in 
by the firmware, isn't it?

That would imply that we might need to byte swap count before it is 
checkable.

Regards,
Christian.

>
>> ---
>>   drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
>> index 808e0ecbe1f0..42adc2a3dcbc 100644
>> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
>> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
>> @@ -192,7 +192,7 @@ struct smu10_clock_voltage_dependency_record {
>>
>>   struct smu10_voltage_dependency_table {
>>          uint32_t count;
>> -       struct smu10_clock_voltage_dependency_record entries[];
>> +       struct smu10_clock_voltage_dependency_record entries[] __counted_by(count);
>>   };
>>
>>   struct smu10_clock_voltage_information {
>> --
>> 2.34.1
>>


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
  2023-09-22 17:32 ` [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series " Kees Cook
  2023-09-23  2:14   ` Gustavo A. R. Silva
@ 2023-09-25 10:08   ` Andrzej Hajda
  2023-09-25 17:50     ` Kees Cook
  2023-09-25 12:20   ` Andi Shyti
  2 siblings, 1 reply; 40+ messages in thread
From: Andrzej Hajda @ 2023-09-25 10:08 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Marijn Suijten, Matthew Brost, Karol Herbst, Neil Armstrong,
	amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang



On 22.09.2023 19:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct perf_series.
>
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: John Harrison <john.c.harrison@Intel.com>
> Cc: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: intel-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

I am surprised this is the only finding in i915, I would expected more. 
Anyway:

Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Regards
Andrzej

> ---
>   drivers/gpu/drm/i915/selftests/i915_request.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
> index a9b79888c193..acae30a04a94 100644
> --- a/drivers/gpu/drm/i915/selftests/i915_request.c
> +++ b/drivers/gpu/drm/i915/selftests/i915_request.c
> @@ -1924,7 +1924,7 @@ struct perf_stats {
>   struct perf_series {
>   	struct drm_i915_private *i915;
>   	unsigned int nengines;
> -	struct intel_context *ce[];
> +	struct intel_context *ce[] __counted_by(nengines);
>   };
>   
>   static int cmp_u32(const void *A, const void *B)


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
  2023-09-22 17:32 ` [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series " Kees Cook
  2023-09-23  2:14   ` Gustavo A. R. Silva
  2023-09-25 10:08   ` Andrzej Hajda
@ 2023-09-25 12:20   ` Andi Shyti
  2 siblings, 0 replies; 40+ messages in thread
From: Andi Shyti @ 2023-09-25 12:20 UTC (permalink / raw)
  To: Kees Cook
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

Hi Kees,

On Fri, Sep 22, 2023 at 10:32:08AM -0700, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct perf_series.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: John Harrison <john.c.harrison@Intel.com>
> Cc: Andi Shyti <andi.shyti@linux.intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: intel-gfx@lists.freedesktop.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> 

Thanks,
Andi

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-25  6:30     ` Christian König
@ 2023-09-25 14:07       ` Alex Deucher
  2023-09-25 14:14         ` Alex Deucher
  2023-09-25 17:52       ` Kees Cook
  1 sibling, 1 reply; 40+ messages in thread
From: Alex Deucher @ 2023-09-25 14:07 UTC (permalink / raw)
  To: Christian König
  Cc: Pan, Xinhui, Emma Anholt, Tom Rix, llvm, dri-devel, Chris Wilson,
	Prike Liang, Huang Rui, Gerd Hoffmann, Andrzej Hajda,
	Marijn Suijten, Matthew Brost, Evan Quan, Karol Herbst, amd-gfx,
	Kuogee Hsieh, VMware Graphics Reviewers, Ben Skeggs, Andi Shyti,
	nouveau, David Airlie, Alex Deucher, Lijo Lazar, Kees Cook,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor, Le Ma,
	Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	John Harrison, linux-hardening

On Mon, Sep 25, 2023 at 2:30 AM Christian König
<christian.koenig@amd.com> wrote:
>
> Am 22.09.23 um 19:41 schrieb Alex Deucher:
> > On Fri, Sep 22, 2023 at 1:32 PM Kees Cook <keescook@chromium.org> wrote:
> >> 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 checking via CONFIG_UBSAN_BOUNDS
> >> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> >> functions).
> >>
> >> As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
> >>
> >> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> >>
> >> Cc: Evan Quan <evan.quan@amd.com>
> >> Cc: Alex Deucher <alexander.deucher@amd.com>
> >> Cc: "Christian König" <christian.koenig@amd.com>
> >> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> >> Cc: David Airlie <airlied@gmail.com>
> >> Cc: Daniel Vetter <daniel@ffwll.ch>
> >> Cc: Xiaojian Du <Xiaojian.Du@amd.com>
> >> Cc: Huang Rui <ray.huang@amd.com>
> >> Cc: Kevin Wang <kevin1.wang@amd.com>
> >> Cc: amd-gfx@lists.freedesktop.org
> >> Cc: dri-devel@lists.freedesktop.org
> >> Signed-off-by: Kees Cook <keescook@chromium.org>
> > Acked-by: Alex Deucher <alexander.deucher@amd.com>
>
> Mhm, I'm not sure if this is a good idea. That is a structure filled in
> by the firmware, isn't it?
>
> That would imply that we might need to byte swap count before it is
> checkable.

True. Good point.  Same for the other amdgpu patch.

Alex

>
> Regards,
> Christian.
>
> >
> >> ---
> >>   drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> >> index 808e0ecbe1f0..42adc2a3dcbc 100644
> >> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> >> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> >> @@ -192,7 +192,7 @@ struct smu10_clock_voltage_dependency_record {
> >>
> >>   struct smu10_voltage_dependency_table {
> >>          uint32_t count;
> >> -       struct smu10_clock_voltage_dependency_record entries[];
> >> +       struct smu10_clock_voltage_dependency_record entries[] __counted_by(count);
> >>   };
> >>
> >>   struct smu10_clock_voltage_information {
> >> --
> >> 2.34.1
> >>
>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-25 14:07       ` Alex Deucher
@ 2023-09-25 14:14         ` Alex Deucher
  0 siblings, 0 replies; 40+ messages in thread
From: Alex Deucher @ 2023-09-25 14:14 UTC (permalink / raw)
  To: Christian König
  Cc: Pan, Xinhui, Emma Anholt, Tom Rix, llvm, dri-devel, Chris Wilson,
	Prike Liang, Huang Rui, Gerd Hoffmann, Andrzej Hajda,
	Marijn Suijten, Matthew Brost, Evan Quan, Karol Herbst, amd-gfx,
	Kuogee Hsieh, VMware Graphics Reviewers, Ben Skeggs, Andi Shyti,
	nouveau, David Airlie, Alex Deucher, Lijo Lazar, Kees Cook,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor, Le Ma,
	Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	John Harrison, linux-hardening

On Mon, Sep 25, 2023 at 10:07 AM Alex Deucher <alexdeucher@gmail.com> wrote:
>
> On Mon, Sep 25, 2023 at 2:30 AM Christian König
> <christian.koenig@amd.com> wrote:
> >
> > Am 22.09.23 um 19:41 schrieb Alex Deucher:
> > > On Fri, Sep 22, 2023 at 1:32 PM Kees Cook <keescook@chromium.org> wrote:
> > >> 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 checking via CONFIG_UBSAN_BOUNDS
> > >> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> > >> functions).
> > >>
> > >> As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
> > >>
> > >> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> > >>
> > >> Cc: Evan Quan <evan.quan@amd.com>
> > >> Cc: Alex Deucher <alexander.deucher@amd.com>
> > >> Cc: "Christian König" <christian.koenig@amd.com>
> > >> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> > >> Cc: David Airlie <airlied@gmail.com>
> > >> Cc: Daniel Vetter <daniel@ffwll.ch>
> > >> Cc: Xiaojian Du <Xiaojian.Du@amd.com>
> > >> Cc: Huang Rui <ray.huang@amd.com>
> > >> Cc: Kevin Wang <kevin1.wang@amd.com>
> > >> Cc: amd-gfx@lists.freedesktop.org
> > >> Cc: dri-devel@lists.freedesktop.org
> > >> Signed-off-by: Kees Cook <keescook@chromium.org>
> > > Acked-by: Alex Deucher <alexander.deucher@amd.com>
> >
> > Mhm, I'm not sure if this is a good idea. That is a structure filled in
> > by the firmware, isn't it?
> >
> > That would imply that we might need to byte swap count before it is
> > checkable.
>
> True. Good point.  Same for the other amdgpu patch.

Actually the other patch is fine.  That's just a local structure.

Alex

>
> Alex
>
> >
> > Regards,
> > Christian.
> >
> > >
> > >> ---
> > >>   drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h | 2 +-
> > >>   1 file changed, 1 insertion(+), 1 deletion(-)
> > >>
> > >> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> > >> index 808e0ecbe1f0..42adc2a3dcbc 100644
> > >> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> > >> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu10_hwmgr.h
> > >> @@ -192,7 +192,7 @@ struct smu10_clock_voltage_dependency_record {
> > >>
> > >>   struct smu10_voltage_dependency_table {
> > >>          uint32_t count;
> > >> -       struct smu10_clock_voltage_dependency_record entries[];
> > >> +       struct smu10_clock_voltage_dependency_record entries[] __counted_by(count);
> > >>   };
> > >>
> > >>   struct smu10_clock_voltage_information {
> > >> --
> > >> 2.34.1
> > >>
> >

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
  2023-09-25 10:08   ` Andrzej Hajda
@ 2023-09-25 17:50     ` Kees Cook
  0 siblings, 0 replies; 40+ messages in thread
From: Kees Cook @ 2023-09-25 17:50 UTC (permalink / raw)
  To: Andrzej Hajda
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Marijn Suijten, Matthew Brost, Karol Herbst, Neil Armstrong,
	amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Dmitry Baryshkov, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Alex Deucher, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

On Mon, Sep 25, 2023 at 12:08:36PM +0200, Andrzej Hajda wrote:
> 
> 
> On 22.09.2023 19:32, Kees Cook wrote:
> > 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 checking via CONFIG_UBSAN_BOUNDS
> > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> > functions).
> > 
> > As found with Coccinelle[1], add __counted_by for struct perf_series.
> > 
> > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> > 
> > Cc: Jani Nikula <jani.nikula@linux.intel.com>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> > Cc: David Airlie <airlied@gmail.com>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: John Harrison <john.c.harrison@Intel.com>
> > Cc: Andi Shyti <andi.shyti@linux.intel.com>
> > Cc: Matthew Brost <matthew.brost@intel.com>
> > Cc: intel-gfx@lists.freedesktop.org
> > Cc: dri-devel@lists.freedesktop.org
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> I am surprised this is the only finding in i915, I would expected more.

I'm sure there are more, but it's likely my Coccinelle pattern didn't
catch it. There are many many flexible arrays in drm. :)

$ grep -nRH '\[\];$' drivers/gpu/drm include/uapi/drm | grep -v :extern | wc -l
122

If anyone has some patterns I can add to the Coccinelle script, I can
take another pass at it.

> Anyway:
> 
> Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Thank you!

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-25  6:30     ` Christian König
  2023-09-25 14:07       ` Alex Deucher
@ 2023-09-25 17:52       ` Kees Cook
  2023-09-25 17:56         ` Alex Deucher
  1 sibling, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-25 17:52 UTC (permalink / raw)
  To: Christian König
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Evan Quan,
	Emma Anholt, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, Alex Deucher,
	Lijo Lazar, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor,
	Dmitry Baryshkov, Gurchetan Singh, Rodrigo Vivi, virtualization,
	Sean Paul, Neil Armstrong, Xiaojian Du, Le Ma, Lang Yu,
	Bjorn Andersson, Tejas Upadhyay, Nick Desaulniers, linux-kernel,
	Hawking Zhang, Melissa Wen, Nirmoy Das, freedreno, John Harrison,
	linux-hardening

On Mon, Sep 25, 2023 at 08:30:30AM +0200, Christian König wrote:
> Am 22.09.23 um 19:41 schrieb Alex Deucher:
> > On Fri, Sep 22, 2023 at 1:32 PM Kees Cook <keescook@chromium.org> wrote:
> > > 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 checking via CONFIG_UBSAN_BOUNDS
> > > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> > > functions).
> > > 
> > > As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
> > > 
> > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> > > 
> > > Cc: Evan Quan <evan.quan@amd.com>
> > > Cc: Alex Deucher <alexander.deucher@amd.com>
> > > Cc: "Christian König" <christian.koenig@amd.com>
> > > Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> > > Cc: David Airlie <airlied@gmail.com>
> > > Cc: Daniel Vetter <daniel@ffwll.ch>
> > > Cc: Xiaojian Du <Xiaojian.Du@amd.com>
> > > Cc: Huang Rui <ray.huang@amd.com>
> > > Cc: Kevin Wang <kevin1.wang@amd.com>
> > > Cc: amd-gfx@lists.freedesktop.org
> > > Cc: dri-devel@lists.freedesktop.org
> > > Signed-off-by: Kees Cook <keescook@chromium.org>
> > Acked-by: Alex Deucher <alexander.deucher@amd.com>
> 
> Mhm, I'm not sure if this is a good idea. That is a structure filled in by
> the firmware, isn't it?
> 
> That would imply that we might need to byte swap count before it is
> checkable.

The script found this instance because of this:

static int smu10_get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr,
                        struct smu10_voltage_dependency_table **pptable,
                        uint32_t num_entry, const DpmClock_t *pclk_dependency_table)
{
        uint32_t i;
        struct smu10_voltage_dependency_table *ptable;

        ptable = kzalloc(struct_size(ptable, entries, num_entry), GFP_KERNEL);
        if (NULL == ptable)
                return -ENOMEM;

        ptable->count = num_entry;

So the implication is that it's native byte order... but you tell me! I
certainly don't want this annotation if it's going to break stuff. :)

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
  2023-09-25 17:52       ` Kees Cook
@ 2023-09-25 17:56         ` Alex Deucher
  0 siblings, 0 replies; 40+ messages in thread
From: Alex Deucher @ 2023-09-25 17:56 UTC (permalink / raw)
  To: Kees Cook
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Evan Quan,
	Emma Anholt, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, Alex Deucher,
	Lijo Lazar, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor,
	Le Ma, Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	Christian König, John Harrison, linux-hardening

On Mon, Sep 25, 2023 at 1:52 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Mon, Sep 25, 2023 at 08:30:30AM +0200, Christian König wrote:
> > Am 22.09.23 um 19:41 schrieb Alex Deucher:
> > > On Fri, Sep 22, 2023 at 1:32 PM Kees Cook <keescook@chromium.org> wrote:
> > > > 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 checking via CONFIG_UBSAN_BOUNDS
> > > > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> > > > functions).
> > > >
> > > > As found with Coccinelle[1], add __counted_by for struct smu10_voltage_dependency_table.
> > > >
> > > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> > > >
> > > > Cc: Evan Quan <evan.quan@amd.com>
> > > > Cc: Alex Deucher <alexander.deucher@amd.com>
> > > > Cc: "Christian König" <christian.koenig@amd.com>
> > > > Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> > > > Cc: David Airlie <airlied@gmail.com>
> > > > Cc: Daniel Vetter <daniel@ffwll.ch>
> > > > Cc: Xiaojian Du <Xiaojian.Du@amd.com>
> > > > Cc: Huang Rui <ray.huang@amd.com>
> > > > Cc: Kevin Wang <kevin1.wang@amd.com>
> > > > Cc: amd-gfx@lists.freedesktop.org
> > > > Cc: dri-devel@lists.freedesktop.org
> > > > Signed-off-by: Kees Cook <keescook@chromium.org>
> > > Acked-by: Alex Deucher <alexander.deucher@amd.com>
> >
> > Mhm, I'm not sure if this is a good idea. That is a structure filled in by
> > the firmware, isn't it?
> >
> > That would imply that we might need to byte swap count before it is
> > checkable.
>
> The script found this instance because of this:
>
> static int smu10_get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr,
>                         struct smu10_voltage_dependency_table **pptable,
>                         uint32_t num_entry, const DpmClock_t *pclk_dependency_table)
> {
>         uint32_t i;
>         struct smu10_voltage_dependency_table *ptable;
>
>         ptable = kzalloc(struct_size(ptable, entries, num_entry), GFP_KERNEL);
>         if (NULL == ptable)
>                 return -ENOMEM;
>
>         ptable->count = num_entry;
>
> So the implication is that it's native byte order... but you tell me! I
> certainly don't want this annotation if it's going to break stuff. :)

In this case, the code is for an integrated GPU in an x86 CPU so the
firmware and driver endianness match.  You wouldn't find a stand alone
dGPU that uses this structure.  In this case it's ok.  False alarm.

Alex

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
  2023-09-22 17:32 ` [PATCH 9/9] drm/v3d: Annotate struct v3d_perfmon " Kees Cook
@ 2023-09-28 15:16   ` Maira Canal
  0 siblings, 0 replies; 40+ messages in thread
From: Maira Canal @ 2023-09-28 15:16 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Evan Quan,
	Emma Anholt, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, Alex Deucher,
	Lijo Lazar, Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Maxime Ripard, Tvrtko Ursulin, Nathan Chancellor,
	Le Ma, Gurchetan Singh, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, Dmitry Baryshkov, Nirmoy Das, freedreno,
	Christian König, John Harrison, linux-hardening

Hi Kees,

On 9/22/23 14:32, Kees Cook wrote:
> 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct v3d_perfmon.
> 
> [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
> 
> Cc: Emma Anholt <emma@anholt.net>
> Cc: Melissa Wen <mwen@igalia.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Maíra Canal <mcanal@igalia.com>

Best Regards,
- Maíra

> ---
>   drivers/gpu/drm/v3d/v3d_drv.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/v3d/v3d_drv.h b/drivers/gpu/drm/v3d/v3d_drv.h
> index 7f664a4b2a75..106454f28956 100644
> --- a/drivers/gpu/drm/v3d/v3d_drv.h
> +++ b/drivers/gpu/drm/v3d/v3d_drv.h
> @@ -59,7 +59,7 @@ struct v3d_perfmon {
>   	 * values can't be reset, but you can fake a reset by
>   	 * destroying the perfmon and creating a new one.
>   	 */
> -	u64 values[];
> +	u64 values[] __counted_by(ncounters);
>   };
>   
>   struct v3d_dev {

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
                   ` (8 preceding siblings ...)
  2023-09-22 17:32 ` [PATCH 9/9] drm/v3d: Annotate struct v3d_perfmon " Kees Cook
@ 2023-09-29 19:33 ` Kees Cook
  2023-10-02  9:20   ` Christian König
  9 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-09-29 19:33 UTC (permalink / raw)
  To: David Airlie, Kees Cook
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, Nathan Chancellor,
	VMware Graphics Reviewers, Ben Skeggs, Andi Shyti, nouveau,
	David Airlie, virtualization, linux-hardening, Lijo Lazar,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Melissa Wen, Alex Deucher, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Tvrtko Ursulin, Xiaojian Du,
	Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Dmitry Baryshkov, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
> 
> As found with Coccinelle[1], add __counted_by to structs that would
> benefit from the annotation.
> 
> [...]

Since this got Acks, I figure I should carry it in my tree. Let me know
if this should go via drm instead.

Applied to for-next/hardening, thanks!

[1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
      https://git.kernel.org/kees/c/a6046ac659d6
[2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
      https://git.kernel.org/kees/c/4df33089b46f
[3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
      https://git.kernel.org/kees/c/ffd3f823bdf6
[4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
      https://git.kernel.org/kees/c/2de35a989b76
[5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
      https://git.kernel.org/kees/c/188aeb08bfaa
[6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
      https://git.kernel.org/kees/c/59a54dc896c3
[7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
      https://git.kernel.org/kees/c/5cd476de33af
[8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
      https://git.kernel.org/kees/c/b426f2e5356a
[9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
      https://git.kernel.org/kees/c/dc662fa1b0e4

Take care,

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-09-29 19:33 ` [PATCH 0/9] drm: Annotate structs " Kees Cook
@ 2023-10-02  9:20   ` Christian König
  2023-10-02 15:06     ` Alex Deucher
  0 siblings, 1 reply; 40+ messages in thread
From: Christian König @ 2023-10-02  9:20 UTC (permalink / raw)
  To: Kees Cook, David Airlie
  Cc: Pan, Xinhui, Karol Herbst, Tom Rix, dri-devel, Chris Wilson,
	Prike Liang, Huang Rui, Gerd Hoffmann, Andrzej Hajda,
	Marijn Suijten, Matthew Brost, Evan Quan, Emma Anholt, amd-gfx,
	Kuogee Hsieh, Lijo Lazar, VMware Graphics Reviewers, Ben Skeggs,
	Andi Shyti, nouveau, David Airlie, Dmitry Baryshkov, llvm,
	Yifan Zhang, linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Tvrtko Ursulin, Nathan Chancellor, Le Ma, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, virtualization, Sean Paul,
	Neil Armstrong, Xiaojian Du, Lang Yu, Bjorn Andersson,
	Tejas Upadhyay, Nick Desaulniers, linux-kernel, Hawking Zhang,
	Melissa Wen, John Harrison, Alex Deucher, Nirmoy Das, freedreno,
	Christian König, linux-hardening

Am 29.09.23 um 21:33 schrieb Kees Cook:
> On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
>> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
>> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
>>
>> As found with Coccinelle[1], add __counted_by to structs that would
>> benefit from the annotation.
>>
>> [...]
> Since this got Acks, I figure I should carry it in my tree. Let me know
> if this should go via drm instead.
>
> Applied to for-next/hardening, thanks!
>
> [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
>        https://git.kernel.org/kees/c/a6046ac659d6

STOP! In a follow up discussion Alex and I figured out that this won't work.

The value in the structure is byte swapped based on some firmware 
endianness which not necessary matches the CPU endianness.

Please revert that one from going upstream if it's already on it's way.

And because of those reasons I strongly think that patches like this 
should go through the DRM tree :)

Regards,
Christian.

> [2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
>        https://git.kernel.org/kees/c/4df33089b46f
> [3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
>        https://git.kernel.org/kees/c/ffd3f823bdf6
> [4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
>        https://git.kernel.org/kees/c/2de35a989b76
> [5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
>        https://git.kernel.org/kees/c/188aeb08bfaa
> [6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
>        https://git.kernel.org/kees/c/59a54dc896c3
> [7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
>        https://git.kernel.org/kees/c/5cd476de33af
> [8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
>        https://git.kernel.org/kees/c/b426f2e5356a
> [9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
>        https://git.kernel.org/kees/c/dc662fa1b0e4
>
> Take care,
>


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02  9:20   ` Christian König
@ 2023-10-02 15:06     ` Alex Deucher
  2023-10-02 16:53       ` Kees Cook
  0 siblings, 1 reply; 40+ messages in thread
From: Alex Deucher @ 2023-10-02 15:06 UTC (permalink / raw)
  To: Christian König
  Cc: Tejas Upadhyay, Karol Herbst, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Emma Anholt,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Kees Cook,
	Tvrtko Ursulin, linux-arm-msm, intel-gfx, Kevin Wang,
	Abhinav Kumar, Nathan Chancellor, Le Ma, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang,
	Xiaojian Du, freedreno, Bjorn Andersson, Pan, Xinhui,
	Nick Desaulniers, linux-kernel, Melissa Wen, Dmitry Baryshkov,
	Nirmoy Das, Lang Yu, Christian König, John Harrison,
	Hawking Zhang

On Mon, Oct 2, 2023 at 5:20 AM Christian König
<ckoenig.leichtzumerken@gmail.com> wrote:
>
> Am 29.09.23 um 21:33 schrieb Kees Cook:
> > On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
> >> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
> >> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
> >>
> >> As found with Coccinelle[1], add __counted_by to structs that would
> >> benefit from the annotation.
> >>
> >> [...]
> > Since this got Acks, I figure I should carry it in my tree. Let me know
> > if this should go via drm instead.
> >
> > Applied to for-next/hardening, thanks!
> >
> > [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
> >        https://git.kernel.org/kees/c/a6046ac659d6
>
> STOP! In a follow up discussion Alex and I figured out that this won't work.
>
> The value in the structure is byte swapped based on some firmware
> endianness which not necessary matches the CPU endianness.

SMU10 is APU only so the endianess of the SMU firmware and the CPU
will always match.

Alex

>
> Please revert that one from going upstream if it's already on it's way.
>
> And because of those reasons I strongly think that patches like this
> should go through the DRM tree :)
>
> Regards,
> Christian.
>
> > [2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
> >        https://git.kernel.org/kees/c/4df33089b46f
> > [3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
> >        https://git.kernel.org/kees/c/ffd3f823bdf6
> > [4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
> >        https://git.kernel.org/kees/c/2de35a989b76
> > [5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
> >        https://git.kernel.org/kees/c/188aeb08bfaa
> > [6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
> >        https://git.kernel.org/kees/c/59a54dc896c3
> > [7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
> >        https://git.kernel.org/kees/c/5cd476de33af
> > [8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
> >        https://git.kernel.org/kees/c/b426f2e5356a
> > [9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
> >        https://git.kernel.org/kees/c/dc662fa1b0e4
> >
> > Take care,
> >
>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02 15:06     ` Alex Deucher
@ 2023-10-02 16:53       ` Kees Cook
  2023-10-02 18:01         ` Christian König
  0 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-10-02 16:53 UTC (permalink / raw)
  To: Alex Deucher
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, linux-arm-msm, llvm,
	dri-devel, Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	Christian König, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Le Ma, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang, Xiaojian Du,
	freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Melissa Wen, Dmitry Baryshkov, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
> On Mon, Oct 2, 2023 at 5:20 AM Christian König
> <ckoenig.leichtzumerken@gmail.com> wrote:
> >
> > Am 29.09.23 um 21:33 schrieb Kees Cook:
> > > On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
> > >> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
> > >> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
> > >>
> > >> As found with Coccinelle[1], add __counted_by to structs that would
> > >> benefit from the annotation.
> > >>
> > >> [...]
> > > Since this got Acks, I figure I should carry it in my tree. Let me know
> > > if this should go via drm instead.
> > >
> > > Applied to for-next/hardening, thanks!
> > >
> > > [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
> > >        https://git.kernel.org/kees/c/a6046ac659d6
> >
> > STOP! In a follow up discussion Alex and I figured out that this won't work.

I'm so confused; from the discussion I saw that Alex said both instances
were false positives?

> >
> > The value in the structure is byte swapped based on some firmware
> > endianness which not necessary matches the CPU endianness.
> 
> SMU10 is APU only so the endianess of the SMU firmware and the CPU
> will always match.

Which I think is what is being said here?

> > Please revert that one from going upstream if it's already on it's way.
> >
> > And because of those reasons I strongly think that patches like this
> > should go through the DRM tree :)

Sure, that's fine -- please let me know. It was others Acked/etc. Who
should carry these patches?

Thanks!

-Kees


> >
> > Regards,
> > Christian.
> >
> > > [2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
> > >        https://git.kernel.org/kees/c/4df33089b46f
> > > [3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
> > >        https://git.kernel.org/kees/c/ffd3f823bdf6
> > > [4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
> > >        https://git.kernel.org/kees/c/2de35a989b76
> > > [5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
> > >        https://git.kernel.org/kees/c/188aeb08bfaa
> > > [6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
> > >        https://git.kernel.org/kees/c/59a54dc896c3
> > > [7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
> > >        https://git.kernel.org/kees/c/5cd476de33af
> > > [8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
> > >        https://git.kernel.org/kees/c/b426f2e5356a
> > > [9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
> > >        https://git.kernel.org/kees/c/dc662fa1b0e4
> > >
> > > Take care,
> > >
> >

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02 16:53       ` Kees Cook
@ 2023-10-02 18:01         ` Christian König
  2023-10-02 18:08           ` Kees Cook
  0 siblings, 1 reply; 40+ messages in thread
From: Christian König @ 2023-10-02 18:01 UTC (permalink / raw)
  To: Kees Cook, Alex Deucher
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Le Ma, Gurchetan Singh, Maxime Ripard,
	Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang, Xiaojian Du,
	freedreno, Bjorn Andersson, Pan, Xinhui, Nick Desaulniers,
	linux-kernel, Melissa Wen, Dmitry Baryshkov, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

Am 02.10.23 um 18:53 schrieb Kees Cook:
> On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
>> On Mon, Oct 2, 2023 at 5:20 AM Christian König
>> <ckoenig.leichtzumerken@gmail.com> wrote:
>>> Am 29.09.23 um 21:33 schrieb Kees Cook:
>>>> On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
>>>>> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
>>>>> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
>>>>>
>>>>> As found with Coccinelle[1], add __counted_by to structs that would
>>>>> benefit from the annotation.
>>>>>
>>>>> [...]
>>>> Since this got Acks, I figure I should carry it in my tree. Let me know
>>>> if this should go via drm instead.
>>>>
>>>> Applied to for-next/hardening, thanks!
>>>>
>>>> [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
>>>>         https://git.kernel.org/kees/c/a6046ac659d6
>>> STOP! In a follow up discussion Alex and I figured out that this won't work.
> I'm so confused; from the discussion I saw that Alex said both instances
> were false positives?
>
>>> The value in the structure is byte swapped based on some firmware
>>> endianness which not necessary matches the CPU endianness.
>> SMU10 is APU only so the endianess of the SMU firmware and the CPU
>> will always match.
> Which I think is what is being said here?
>
>>> Please revert that one from going upstream if it's already on it's way.
>>>
>>> And because of those reasons I strongly think that patches like this
>>> should go through the DRM tree :)
> Sure, that's fine -- please let me know. It was others Acked/etc. Who
> should carry these patches?

Probably best if the relevant maintainer pick them up individually.

Some of those structures are filled in by firmware/hardware and only the 
maintainers can judge if that value actually matches what the compiler 
needs.

We have cases where individual bits are used as flags or when the size 
is byte swapped etc...

Even Alex and I didn't immediately say how and where that field is 
actually used and had to dig that up. That's where the confusion came from.

Regards,
Christian.

>
> Thanks!
>
> -Kees
>
>
>>> Regards,
>>> Christian.
>>>
>>>> [2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance with __counted_by
>>>>         https://git.kernel.org/kees/c/4df33089b46f
>>>> [3/9] drm/i915/selftests: Annotate struct perf_series with __counted_by
>>>>         https://git.kernel.org/kees/c/ffd3f823bdf6
>>>> [4/9] drm/msm/dpu: Annotate struct dpu_hw_intr with __counted_by
>>>>         https://git.kernel.org/kees/c/2de35a989b76
>>>> [5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom with __counted_by
>>>>         https://git.kernel.org/kees/c/188aeb08bfaa
>>>> [6/9] drm/vc4: Annotate struct vc4_perfmon with __counted_by
>>>>         https://git.kernel.org/kees/c/59a54dc896c3
>>>> [7/9] drm/virtio: Annotate struct virtio_gpu_object_array with __counted_by
>>>>         https://git.kernel.org/kees/c/5cd476de33af
>>>> [8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty with __counted_by
>>>>         https://git.kernel.org/kees/c/b426f2e5356a
>>>> [9/9] drm/v3d: Annotate struct v3d_perfmon with __counted_by
>>>>         https://git.kernel.org/kees/c/dc662fa1b0e4
>>>>
>>>> Take care,
>>>>


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02 18:01         ` Christian König
@ 2023-10-02 18:08           ` Kees Cook
  2023-10-02 18:11             ` Christian König
  0 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-10-02 18:08 UTC (permalink / raw)
  To: Christian König
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang,
	Xiaojian Du, Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui,
	Nick Desaulniers, linux-kernel, Melissa Wen, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

On Mon, Oct 02, 2023 at 08:01:57PM +0200, Christian König wrote:
> Am 02.10.23 um 18:53 schrieb Kees Cook:
> > On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
> > > On Mon, Oct 2, 2023 at 5:20 AM Christian König
> > > <ckoenig.leichtzumerken@gmail.com> wrote:
> > > > Am 29.09.23 um 21:33 schrieb Kees Cook:
> > > > > On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
> > > > > > This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
> > > > > > indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
> > > > > > 
> > > > > > As found with Coccinelle[1], add __counted_by to structs that would
> > > > > > benefit from the annotation.
> > > > > > 
> > > > > > [...]
> > > > > Since this got Acks, I figure I should carry it in my tree. Let me know
> > > > > if this should go via drm instead.
> > > > > 
> > > > > Applied to for-next/hardening, thanks!
> > > > > 
> > > > > [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
> > > > >         https://git.kernel.org/kees/c/a6046ac659d6
> > > > STOP! In a follow up discussion Alex and I figured out that this won't work.
> > I'm so confused; from the discussion I saw that Alex said both instances
> > were false positives?
> > 
> > > > The value in the structure is byte swapped based on some firmware
> > > > endianness which not necessary matches the CPU endianness.
> > > SMU10 is APU only so the endianess of the SMU firmware and the CPU
> > > will always match.
> > Which I think is what is being said here?
> > 
> > > > Please revert that one from going upstream if it's already on it's way.
> > > > 
> > > > And because of those reasons I strongly think that patches like this
> > > > should go through the DRM tree :)
> > Sure, that's fine -- please let me know. It was others Acked/etc. Who
> > should carry these patches?
> 
> Probably best if the relevant maintainer pick them up individually.
> 
> Some of those structures are filled in by firmware/hardware and only the
> maintainers can judge if that value actually matches what the compiler
> needs.
> 
> We have cases where individual bits are used as flags or when the size is
> byte swapped etc...
> 
> Even Alex and I didn't immediately say how and where that field is actually
> used and had to dig that up. That's where the confusion came from.

Okay, I've dropped them all from my tree. Several had Acks/Reviews, so
hopefully those can get picked up for the DRM tree?

Thanks!

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02 18:08           ` Kees Cook
@ 2023-10-02 18:11             ` Christian König
  2023-10-02 18:22               ` Kees Cook
  0 siblings, 1 reply; 40+ messages in thread
From: Christian König @ 2023-10-02 18:11 UTC (permalink / raw)
  To: Kees Cook, Christian König
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang,
	Xiaojian Du, Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui,
	Nick Desaulniers, linux-kernel, Melissa Wen, Nirmoy Das, Lang Yu,
	John Harrison, Hawking Zhang

Am 02.10.23 um 20:08 schrieb Kees Cook:
> On Mon, Oct 02, 2023 at 08:01:57PM +0200, Christian König wrote:
>> Am 02.10.23 um 18:53 schrieb Kees Cook:
>>> On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
>>>> On Mon, Oct 2, 2023 at 5:20 AM Christian König
>>>> <ckoenig.leichtzumerken@gmail.com> wrote:
>>>>> Am 29.09.23 um 21:33 schrieb Kees Cook:
>>>>>> On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
>>>>>>> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
>>>>>>> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
>>>>>>>
>>>>>>> As found with Coccinelle[1], add __counted_by to structs that would
>>>>>>> benefit from the annotation.
>>>>>>>
>>>>>>> [...]
>>>>>> Since this got Acks, I figure I should carry it in my tree. Let me know
>>>>>> if this should go via drm instead.
>>>>>>
>>>>>> Applied to for-next/hardening, thanks!
>>>>>>
>>>>>> [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
>>>>>>          https://git.kernel.org/kees/c/a6046ac659d6
>>>>> STOP! In a follow up discussion Alex and I figured out that this won't work.
>>> I'm so confused; from the discussion I saw that Alex said both instances
>>> were false positives?
>>>
>>>>> The value in the structure is byte swapped based on some firmware
>>>>> endianness which not necessary matches the CPU endianness.
>>>> SMU10 is APU only so the endianess of the SMU firmware and the CPU
>>>> will always match.
>>> Which I think is what is being said here?
>>>
>>>>> Please revert that one from going upstream if it's already on it's way.
>>>>>
>>>>> And because of those reasons I strongly think that patches like this
>>>>> should go through the DRM tree :)
>>> Sure, that's fine -- please let me know. It was others Acked/etc. Who
>>> should carry these patches?
>> Probably best if the relevant maintainer pick them up individually.
>>
>> Some of those structures are filled in by firmware/hardware and only the
>> maintainers can judge if that value actually matches what the compiler
>> needs.
>>
>> We have cases where individual bits are used as flags or when the size is
>> byte swapped etc...
>>
>> Even Alex and I didn't immediately say how and where that field is actually
>> used and had to dig that up. That's where the confusion came from.
> Okay, I've dropped them all from my tree. Several had Acks/Reviews, so
> hopefully those can get picked up for the DRM tree?

I will pick those up to go through drm-misc-next.

Going to ping maintainers once more when I'm not sure if stuff is 
correct or not.

Christian.

>
> Thanks!
>
> -Kees
>


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02 18:11             ` Christian König
@ 2023-10-02 18:22               ` Kees Cook
  2023-10-05  9:42                 ` Christian König
  0 siblings, 1 reply; 40+ messages in thread
From: Kees Cook @ 2023-10-02 18:22 UTC (permalink / raw)
  To: Christian König
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, linux-arm-msm, llvm,
	dri-devel, Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	Christian König, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang,
	Xiaojian Du, Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui,
	Nick Desaulniers, linux-kernel, Melissa Wen, Nirmoy Das, Lang Yu,
	John Harrison, Hawking Zhang

On Mon, Oct 02, 2023 at 08:11:41PM +0200, Christian König wrote:
> Am 02.10.23 um 20:08 schrieb Kees Cook:
> > On Mon, Oct 02, 2023 at 08:01:57PM +0200, Christian König wrote:
> > > Am 02.10.23 um 18:53 schrieb Kees Cook:
> > > > On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
> > > > > On Mon, Oct 2, 2023 at 5:20 AM Christian König
> > > > > <ckoenig.leichtzumerken@gmail.com> wrote:
> > > > > > Am 29.09.23 um 21:33 schrieb Kees Cook:
> > > > > > > On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
> > > > > > > > This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
> > > > > > > > indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
> > > > > > > > 
> > > > > > > > As found with Coccinelle[1], add __counted_by to structs that would
> > > > > > > > benefit from the annotation.
> > > > > > > > 
> > > > > > > > [...]
> > > > > > > Since this got Acks, I figure I should carry it in my tree. Let me know
> > > > > > > if this should go via drm instead.
> > > > > > > 
> > > > > > > Applied to for-next/hardening, thanks!
> > > > > > > 
> > > > > > > [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
> > > > > > >          https://git.kernel.org/kees/c/a6046ac659d6
> > > > > > STOP! In a follow up discussion Alex and I figured out that this won't work.
> > > > I'm so confused; from the discussion I saw that Alex said both instances
> > > > were false positives?
> > > > 
> > > > > > The value in the structure is byte swapped based on some firmware
> > > > > > endianness which not necessary matches the CPU endianness.
> > > > > SMU10 is APU only so the endianess of the SMU firmware and the CPU
> > > > > will always match.
> > > > Which I think is what is being said here?
> > > > 
> > > > > > Please revert that one from going upstream if it's already on it's way.
> > > > > > 
> > > > > > And because of those reasons I strongly think that patches like this
> > > > > > should go through the DRM tree :)
> > > > Sure, that's fine -- please let me know. It was others Acked/etc. Who
> > > > should carry these patches?
> > > Probably best if the relevant maintainer pick them up individually.
> > > 
> > > Some of those structures are filled in by firmware/hardware and only the
> > > maintainers can judge if that value actually matches what the compiler
> > > needs.
> > > 
> > > We have cases where individual bits are used as flags or when the size is
> > > byte swapped etc...
> > > 
> > > Even Alex and I didn't immediately say how and where that field is actually
> > > used and had to dig that up. That's where the confusion came from.
> > Okay, I've dropped them all from my tree. Several had Acks/Reviews, so
> > hopefully those can get picked up for the DRM tree?
> 
> I will pick those up to go through drm-misc-next.
> 
> Going to ping maintainers once more when I'm not sure if stuff is correct or
> not.

Sounds great; thanks!

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-02 18:22               ` Kees Cook
@ 2023-10-05  9:42                 ` Christian König
  2023-10-05 16:16                   ` Kees Cook
  0 siblings, 1 reply; 40+ messages in thread
From: Christian König @ 2023-10-05  9:42 UTC (permalink / raw)
  To: Kees Cook, Christian König
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang,
	Xiaojian Du, Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui,
	Nick Desaulniers, linux-kernel, Melissa Wen, Nirmoy Das, Lang Yu,
	John Harrison, Hawking Zhang

Am 02.10.23 um 20:22 schrieb Kees Cook:
> On Mon, Oct 02, 2023 at 08:11:41PM +0200, Christian König wrote:
>> Am 02.10.23 um 20:08 schrieb Kees Cook:
>>> On Mon, Oct 02, 2023 at 08:01:57PM +0200, Christian König wrote:
>>>> Am 02.10.23 um 18:53 schrieb Kees Cook:
>>>>> On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
>>>>>> On Mon, Oct 2, 2023 at 5:20 AM Christian König
>>>>>> <ckoenig.leichtzumerken@gmail.com> wrote:
>>>>>>> Am 29.09.23 um 21:33 schrieb Kees Cook:
>>>>>>>> On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
>>>>>>>>> This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
>>>>>>>>> indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
>>>>>>>>>
>>>>>>>>> As found with Coccinelle[1], add __counted_by to structs that would
>>>>>>>>> benefit from the annotation.
>>>>>>>>>
>>>>>>>>> [...]
>>>>>>>> Since this got Acks, I figure I should carry it in my tree. Let me know
>>>>>>>> if this should go via drm instead.
>>>>>>>>
>>>>>>>> Applied to for-next/hardening, thanks!
>>>>>>>>
>>>>>>>> [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
>>>>>>>>           https://git.kernel.org/kees/c/a6046ac659d6
>>>>>>> STOP! In a follow up discussion Alex and I figured out that this won't work.
>>>>> I'm so confused; from the discussion I saw that Alex said both instances
>>>>> were false positives?
>>>>>
>>>>>>> The value in the structure is byte swapped based on some firmware
>>>>>>> endianness which not necessary matches the CPU endianness.
>>>>>> SMU10 is APU only so the endianess of the SMU firmware and the CPU
>>>>>> will always match.
>>>>> Which I think is what is being said here?
>>>>>
>>>>>>> Please revert that one from going upstream if it's already on it's way.
>>>>>>>
>>>>>>> And because of those reasons I strongly think that patches like this
>>>>>>> should go through the DRM tree :)
>>>>> Sure, that's fine -- please let me know. It was others Acked/etc. Who
>>>>> should carry these patches?
>>>> Probably best if the relevant maintainer pick them up individually.
>>>>
>>>> Some of those structures are filled in by firmware/hardware and only the
>>>> maintainers can judge if that value actually matches what the compiler
>>>> needs.
>>>>
>>>> We have cases where individual bits are used as flags or when the size is
>>>> byte swapped etc...
>>>>
>>>> Even Alex and I didn't immediately say how and where that field is actually
>>>> used and had to dig that up. That's where the confusion came from.
>>> Okay, I've dropped them all from my tree. Several had Acks/Reviews, so
>>> hopefully those can get picked up for the DRM tree?
>> I will pick those up to go through drm-misc-next.
>>
>> Going to ping maintainers once more when I'm not sure if stuff is correct or
>> not.
> Sounds great; thanks!

I wasn't 100% sure for the VC4 patch, but pushed the whole set to 
drm-misc-next anyway.

This also means that the patches are now auto merged into the drm-tip 
integration branch and should any build or unit test go boom we should 
notice immediately and can revert it pretty easily.

Thanks,
Christian.

>
> -Kees
>


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH 0/9] drm: Annotate structs with __counted_by
  2023-10-05  9:42                 ` Christian König
@ 2023-10-05 16:16                   ` Kees Cook
  0 siblings, 0 replies; 40+ messages in thread
From: Kees Cook @ 2023-10-05 16:16 UTC (permalink / raw)
  To: Christian König
  Cc: Tejas Upadhyay, Emma Anholt, Tom Rix, llvm, dri-devel,
	Chris Wilson, Prike Liang, Huang Rui, Gerd Hoffmann,
	Andrzej Hajda, Marijn Suijten, Matthew Brost, Karol Herbst,
	Neil Armstrong, amd-gfx, Kuogee Hsieh, VMware Graphics Reviewers,
	Ben Skeggs, Andi Shyti, nouveau, David Airlie, virtualization,
	linux-hardening, Alex Deucher, Lijo Lazar, Tvrtko Ursulin,
	linux-arm-msm, intel-gfx, Kevin Wang, Abhinav Kumar,
	Nathan Chancellor, Dmitry Baryshkov, Gurchetan Singh,
	Maxime Ripard, Rodrigo Vivi, Evan Quan, Sean Paul, Yifan Zhang,
	Xiaojian Du, Le Ma, freedreno, Bjorn Andersson, Pan, Xinhui,
	Nick Desaulniers, linux-kernel, Melissa Wen, Nirmoy Das, Lang Yu,
	Christian König, John Harrison, Hawking Zhang

On Thu, Oct 05, 2023 at 11:42:38AM +0200, Christian König wrote:
> Am 02.10.23 um 20:22 schrieb Kees Cook:
> > On Mon, Oct 02, 2023 at 08:11:41PM +0200, Christian König wrote:
> > > Am 02.10.23 um 20:08 schrieb Kees Cook:
> > > > On Mon, Oct 02, 2023 at 08:01:57PM +0200, Christian König wrote:
> > > > > Am 02.10.23 um 18:53 schrieb Kees Cook:
> > > > > > On Mon, Oct 02, 2023 at 11:06:19AM -0400, Alex Deucher wrote:
> > > > > > > On Mon, Oct 2, 2023 at 5:20 AM Christian König
> > > > > > > <ckoenig.leichtzumerken@gmail.com> wrote:
> > > > > > > > Am 29.09.23 um 21:33 schrieb Kees Cook:
> > > > > > > > > On Fri, 22 Sep 2023 10:32:05 -0700, Kees Cook wrote:
> > > > > > > > > > This is a batch of patches touching drm for preparing 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 checking via CONFIG_UBSAN_BOUNDS (for array
> > > > > > > > > > indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
> > > > > > > > > > 
> > > > > > > > > > As found with Coccinelle[1], add __counted_by to structs that would
> > > > > > > > > > benefit from the annotation.
> > > > > > > > > > 
> > > > > > > > > > [...]
> > > > > > > > > Since this got Acks, I figure I should carry it in my tree. Let me know
> > > > > > > > > if this should go via drm instead.
> > > > > > > > > 
> > > > > > > > > Applied to for-next/hardening, thanks!
> > > > > > > > > 
> > > > > > > > > [1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table with __counted_by
> > > > > > > > >           https://git.kernel.org/kees/c/a6046ac659d6
> > > > > > > > STOP! In a follow up discussion Alex and I figured out that this won't work.
> > > > > > I'm so confused; from the discussion I saw that Alex said both instances
> > > > > > were false positives?
> > > > > > 
> > > > > > > > The value in the structure is byte swapped based on some firmware
> > > > > > > > endianness which not necessary matches the CPU endianness.
> > > > > > > SMU10 is APU only so the endianess of the SMU firmware and the CPU
> > > > > > > will always match.
> > > > > > Which I think is what is being said here?
> > > > > > 
> > > > > > > > Please revert that one from going upstream if it's already on it's way.
> > > > > > > > 
> > > > > > > > And because of those reasons I strongly think that patches like this
> > > > > > > > should go through the DRM tree :)
> > > > > > Sure, that's fine -- please let me know. It was others Acked/etc. Who
> > > > > > should carry these patches?
> > > > > Probably best if the relevant maintainer pick them up individually.
> > > > > 
> > > > > Some of those structures are filled in by firmware/hardware and only the
> > > > > maintainers can judge if that value actually matches what the compiler
> > > > > needs.
> > > > > 
> > > > > We have cases where individual bits are used as flags or when the size is
> > > > > byte swapped etc...
> > > > > 
> > > > > Even Alex and I didn't immediately say how and where that field is actually
> > > > > used and had to dig that up. That's where the confusion came from.
> > > > Okay, I've dropped them all from my tree. Several had Acks/Reviews, so
> > > > hopefully those can get picked up for the DRM tree?
> > > I will pick those up to go through drm-misc-next.
> > > 
> > > Going to ping maintainers once more when I'm not sure if stuff is correct or
> > > not.
> > Sounds great; thanks!
> 
> I wasn't 100% sure for the VC4 patch, but pushed the whole set to
> drm-misc-next anyway.
> 
> This also means that the patches are now auto merged into the drm-tip
> integration branch and should any build or unit test go boom we should
> notice immediately and can revert it pretty easily.

Thanks very much; I'll keep an eye out for any reports.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2023-10-05 16:16 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 17:32 [PATCH 0/9] drm: Annotate structs with __counted_by Kees Cook
2023-09-22 17:32 ` [PATCH 1/9] drm/amd/pm: Annotate struct smu10_voltage_dependency_table " Kees Cook
2023-09-22 17:41   ` Alex Deucher
2023-09-25  6:30     ` Christian König
2023-09-25 14:07       ` Alex Deucher
2023-09-25 14:14         ` Alex Deucher
2023-09-25 17:52       ` Kees Cook
2023-09-25 17:56         ` Alex Deucher
2023-09-23  2:13   ` Gustavo A. R. Silva
2023-09-22 17:32 ` [PATCH 2/9] drm/amdgpu/discovery: Annotate struct ip_hw_instance " Kees Cook
2023-09-22 17:42   ` Alex Deucher
2023-09-23  2:14   ` Gustavo A. R. Silva
2023-09-22 17:32 ` [PATCH 3/9] drm/i915/selftests: Annotate struct perf_series " Kees Cook
2023-09-23  2:14   ` Gustavo A. R. Silva
2023-09-25 10:08   ` Andrzej Hajda
2023-09-25 17:50     ` Kees Cook
2023-09-25 12:20   ` Andi Shyti
2023-09-22 17:32 ` [PATCH 4/9] drm/msm/dpu: Annotate struct dpu_hw_intr " Kees Cook
2023-09-23  2:15   ` Gustavo A. R. Silva
2023-09-22 17:32 ` [PATCH 5/9] drm/nouveau/pm: Annotate struct nvkm_perfdom " Kees Cook
2023-09-22 19:00   ` Lyude Paul
2023-09-23  2:15   ` Gustavo A. R. Silva
2023-09-22 17:32 ` [PATCH 6/9] drm/vc4: Annotate struct vc4_perfmon " Kees Cook
2023-09-23  2:16   ` Gustavo A. R. Silva
2023-09-22 17:32 ` [PATCH 7/9] drm/virtio: Annotate struct virtio_gpu_object_array " Kees Cook
2023-09-23  2:36   ` Gustavo A. R. Silva
2023-09-22 17:32 ` [PATCH 8/9] drm/vmwgfx: Annotate struct vmw_surface_dirty " Kees Cook
2023-09-22 21:50   ` Zack Rusin
2023-09-22 17:32 ` [PATCH 9/9] drm/v3d: Annotate struct v3d_perfmon " Kees Cook
2023-09-28 15:16   ` Maira Canal
2023-09-29 19:33 ` [PATCH 0/9] drm: Annotate structs " Kees Cook
2023-10-02  9:20   ` Christian König
2023-10-02 15:06     ` Alex Deucher
2023-10-02 16:53       ` Kees Cook
2023-10-02 18:01         ` Christian König
2023-10-02 18:08           ` Kees Cook
2023-10-02 18:11             ` Christian König
2023-10-02 18:22               ` Kees Cook
2023-10-05  9:42                 ` Christian König
2023-10-05 16:16                   ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).