Commit 2923d0e7 authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Jialin Zhang
Browse files

drm: Use size_t type for len variable in drm_copy_field()

stable inclusion
from stable-v5.10.150
commit e7d701800365d2dd3ef2252497dcaed9a2d2fada
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6D0XA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e7d701800365d2dd3ef2252497dcaed9a2d2fada



--------------------------------

[ Upstream commit 94dc3471 ]

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: default avatarJavier Martinez Canillas <javierm@redhat.com>
Tested-by: default avatarPeter Robinson <pbrobinson@gmail.com>
Reviewed-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20220705100215.572498-2-javierm@redhat.com


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parent 2b54ca49
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment