[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aBQqOCQZrHBBbPbL@lstrano-desk.jf.intel.com>
Date: Thu, 1 May 2025 19:13:12 -0700
From: Matthew Brost <matthew.brost@...el.com>
To: Kees Cook <kees@...nel.org>
CC: Thomas Hellström <thomas.hellstrom@...ux.intel.com>,
Christian Koenig <christian.koenig@....com>, Somalapuram Amaranath
<Amaranath.Somalapuram@....com>, Huang Rui <ray.huang@....com>, Matthew Auld
<matthew.auld@...el.com>, Maarten Lankhorst
<maarten.lankhorst@...ux.intel.com>, Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, <dri-devel@...ts.freedesktop.org>,
<linux-kernel@...r.kernel.org>, <linux-hardening@...r.kernel.org>
Subject: Re: [PATCH v2] drm/ttm: Silence randstruct warning about casting
struct file
On Thu, May 01, 2025 at 05:24:38PM -0700, Kees Cook wrote:
> Casting through a "void *" isn't sufficient to convince the randstruct
> GCC plugin that the result is intentional. Instead operate through an
> explicit union to silence the warning:
>
> drivers/gpu/drm/ttm/ttm_backup.c: In function 'ttm_file_to_backup':
> drivers/gpu/drm/ttm/ttm_backup.c:21:16: note: randstruct: casting between randomized structure pointer types (ssa): 'struct ttm_backup' and 'struct file'
> 21 | return (void *)file;
> | ^~~~~~~~~~~~
>
> Suggested-by: Matthew Brost <matthew.brost@...el.com>
I forgot the policy if suggest-by but will add:
Reviewed-by: Matthew Brost <matthew.brost@...el.com>
Thomas was out today I suspect he will look at this tomorrow when he is
back too.
Matt
> Fixes: e7b5d23e5d47 ("drm/ttm: Provide a shmem backup implementation")
> Signed-off-by: Kees Cook <kees@...nel.org>
> ---
> v2: use struct and container_of (matthew)
> v1: https://lore.kernel.org/all/20250501195859.work.107-kees@kernel.org/
> Cc: Thomas Hellström <thomas.hellstrom@...ux.intel.com>
> Cc: Christian Koenig <christian.koenig@....com>
> Cc: Somalapuram Amaranath <Amaranath.Somalapuram@....com>
> Cc: Matthew Brost <matthew.brost@...el.com>
> Cc: Huang Rui <ray.huang@....com>
> Cc: Matthew Auld <matthew.auld@...el.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>
> Cc: Maxime Ripard <mripard@...nel.org>
> Cc: Thomas Zimmermann <tzimmermann@...e.de>
> Cc: David Airlie <airlied@...il.com>
> Cc: Simona Vetter <simona@...ll.ch>
> Cc: <dri-devel@...ts.freedesktop.org>
> ---
> drivers/gpu/drm/ttm/ttm_backup.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_backup.c b/drivers/gpu/drm/ttm/ttm_backup.c
> index 93c007f18855..60cff6c60db4 100644
> --- a/drivers/gpu/drm/ttm/ttm_backup.c
> +++ b/drivers/gpu/drm/ttm/ttm_backup.c
> @@ -9,16 +9,21 @@
>
> /*
> * Casting from randomized struct file * to struct ttm_backup * is fine since
> - * struct ttm_backup is never defined nor dereferenced.
> + * struct ttm_backup is never defined nor dereferenced. Use a single-member
> + * struct to avoid cast warnings.
> */
> +struct ttm_backup {
> + struct file file;
> +};
> +
> static struct file *ttm_backup_to_file(struct ttm_backup *backup)
> {
> - return (void *)backup;
> + return &backup->file;
> }
>
> static struct ttm_backup *ttm_file_to_backup(struct file *file)
> {
> - return (void *)file;
> + return container_of(file, struct ttm_backup, file);
> }
>
> /*
> --
> 2.34.1
>
Powered by blists - more mailing lists