public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type
@ 2025-04-26  6:14 Kees Cook
  2025-04-28  8:18 ` Louis Chauvet
  2025-05-06  8:23 ` Louis Chauvet
  0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2025-04-26  6:14 UTC (permalink / raw)
  To: Louis Chauvet
  Cc: Kees Cook, Haneen Mohammed, Simona Vetter, Melissa Wen,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	dri-devel, linux-kernel, linux-hardening

In preparation for making the kmalloc family of allocators type aware,
we need to make sure that the returned type from the allocation matches
the type of the variable being assigned. (Before, the allocator would
always return "void *", which can be implicitly cast to any pointer type.)

The assigned type is "struct vkms_plane_state **", but the returned type
will be "struct drm_plane **". These are the same size (pointer size), but
the types don't match. Adjust the allocation type to match the assignment.

Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Louis Chauvet <louis.chauvet@bootlin.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: Melissa Wen <melissa.srw@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: <dri-devel@lists.freedesktop.org>
---
 drivers/gpu/drm/vkms/vkms_crtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 12034ec12029..8c9898b9055d 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -194,7 +194,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
 		i++;
 	}
 
-	vkms_state->active_planes = kcalloc(i, sizeof(plane), GFP_KERNEL);
+	vkms_state->active_planes = kcalloc(i, sizeof(*vkms_state->active_planes), GFP_KERNEL);
 	if (!vkms_state->active_planes)
 		return -ENOMEM;
 	vkms_state->num_active_planes = i;
-- 
2.34.1


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

* Re: [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type
  2025-04-26  6:14 [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type Kees Cook
@ 2025-04-28  8:18 ` Louis Chauvet
  2025-04-30 19:06   ` Kees Cook
  2025-05-06  8:23 ` Louis Chauvet
  1 sibling, 1 reply; 4+ messages in thread
From: Louis Chauvet @ 2025-04-28  8:18 UTC (permalink / raw)
  To: Kees Cook
  Cc: Haneen Mohammed, Simona Vetter, Melissa Wen, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, dri-devel,
	linux-kernel, linux-hardening



Le 26/04/2025 à 08:14, Kees Cook a écrit :
> In preparation for making the kmalloc family of allocators type aware,
> we need to make sure that the returned type from the allocation matches
> the type of the variable being assigned. (Before, the allocator would
> always return "void *", which can be implicitly cast to any pointer type.)
> 
> The assigned type is "struct vkms_plane_state **", but the returned type
> will be "struct drm_plane **". These are the same size (pointer size), but
> the types don't match. Adjust the allocation type to match the assignment.

I think this is an issue, can you add the proper Fixup tag in this commit?

With this:

Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>

> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Louis Chauvet <louis.chauvet@bootlin.com>
> Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
> Cc: Simona Vetter <simona@ffwll.ch>
> Cc: Melissa Wen <melissa.srw@gmail.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: David Airlie <airlied@gmail.com>
> Cc: <dri-devel@lists.freedesktop.org>
> ---
>   drivers/gpu/drm/vkms/vkms_crtc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
> index 12034ec12029..8c9898b9055d 100644
> --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> @@ -194,7 +194,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
>   		i++;
>   	}
>   
> -	vkms_state->active_planes = kcalloc(i, sizeof(plane), GFP_KERNEL);
> +	vkms_state->active_planes = kcalloc(i, sizeof(*vkms_state->active_planes), GFP_KERNEL);
>   	if (!vkms_state->active_planes)
>   		return -ENOMEM;
>   	vkms_state->num_active_planes = i;

-- 
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


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

* Re: [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type
  2025-04-28  8:18 ` Louis Chauvet
@ 2025-04-30 19:06   ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2025-04-30 19:06 UTC (permalink / raw)
  To: Louis Chauvet
  Cc: Haneen Mohammed, Simona Vetter, Melissa Wen, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, dri-devel,
	linux-kernel, linux-hardening

On Mon, Apr 28, 2025 at 10:18:34AM +0200, Louis Chauvet wrote:
> 
> 
> Le 26/04/2025 à 08:14, Kees Cook a écrit :
> > In preparation for making the kmalloc family of allocators type aware,
> > we need to make sure that the returned type from the allocation matches
> > the type of the variable being assigned. (Before, the allocator would
> > always return "void *", which can be implicitly cast to any pointer type.)
> > 
> > The assigned type is "struct vkms_plane_state **", but the returned type
> > will be "struct drm_plane **". These are the same size (pointer size), but
> > the types don't match. Adjust the allocation type to match the assignment.
> 
> I think this is an issue, can you add the proper Fixup tag in this commit?

I think trailers updating tools like b4 will pick this up:

Fixes: 8b1865873651 ("drm/vkms: totally reworked crc data tracking")

Would you rather I send a v2 with the Fixes added?

> 
> With this:
> 
> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>

Thanks!

-Kees

-- 
Kees Cook

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

* Re: [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type
  2025-04-26  6:14 [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type Kees Cook
  2025-04-28  8:18 ` Louis Chauvet
@ 2025-05-06  8:23 ` Louis Chauvet
  1 sibling, 0 replies; 4+ messages in thread
From: Louis Chauvet @ 2025-05-06  8:23 UTC (permalink / raw)
  To: Louis Chauvet, Kees Cook
  Cc: Haneen Mohammed, Simona Vetter, Melissa Wen, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, dri-devel,
	linux-kernel, linux-hardening


On Fri, 25 Apr 2025 23:14:32 -0700, Kees Cook wrote:
> In preparation for making the kmalloc family of allocators type aware,
> we need to make sure that the returned type from the allocation matches
> the type of the variable being assigned. (Before, the allocator would
> always return "void *", which can be implicitly cast to any pointer type.)
> 
> The assigned type is "struct vkms_plane_state **", but the returned type
> will be "struct drm_plane **". These are the same size (pointer size), but
> the types don't match. Adjust the allocation type to match the assignment.
> 
> [...]

Applied, thanks!

[1/1] drm/vkms: Adjust vkms_state->active_planes allocation type
      commit: 258aebf100540d36aba910f545d4d5ddf4ecaf0b

Best regards,
-- 
Louis Chauvet <contact@louischauvet.fr>


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

end of thread, other threads:[~2025-05-06  8:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-26  6:14 [PATCH] drm/vkms: Adjust vkms_state->active_planes allocation type Kees Cook
2025-04-28  8:18 ` Louis Chauvet
2025-04-30 19:06   ` Kees Cook
2025-05-06  8:23 ` Louis Chauvet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox