drm: Use size_t type for len variable in drm_copy_field()
authorJavier Martinez Canillas <javierm@redhat.com>
Tue, 5 Jul 2022 10:02:13 +0000 (12:02 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:17:11 +0000 (13:17 +0200)
commit5b5ba7d6c2efa416cbc6d2a4a4f2a301aa53af12
tree7bb6eb61240b49df62186a8bb12bf3e7e9c13c6a
parentf5d6c938d51217d6f0f534f1ee606d9c5eb22fdc
drm: Use size_t type for len variable in drm_copy_field()

[ Upstream commit 94dc3471d1b2b58b3728558d0e3f264e9ce6ff59 ]

The strlen() function returns a size_t which is an unsigned int on 32-bit
arches and an unsigned long on 64-bit arches. But in the drm_copy_field()
function, the strlen() return value is assigned to an 'int len' variable.

Later, the len variable is passed as copy_from_user() third argument that
is an unsigned long parameter as well.

In theory, this can lead to an integer overflow via type conversion. Since
the assignment happens to a signed int lvalue instead of a size_t lvalue.

In practice though, that's unlikely since the values copied are set by DRM
drivers and not controlled by userspace. But using a size_t for len is the
correct thing to do anyways.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20220705100215.572498-2-javierm@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/drm_ioctl.c