From: Alexey Simakov <bigalex934@gmail.com>
To: David Airlie <airlied@redhat.com>
Cc: Alexey Simakov <bigalex934@gmail.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Gurchetan Singh <gurchetansingh@chromium.org>,
Chia-I Wu <olvaffe@gmail.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Simona Vetter <simona@ffwll.ch>, Lingfeng Yang <lfy@google.com>,
dri-devel@lists.freedesktop.org, virtualization@lists.linux.dev,
linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org
Subject: [PATCH] drm/virtio: fix undefined behavior in capset shift calculation
Date: Mon, 8 Dec 2025 19:02:29 +0300 [thread overview]
Message-ID: <20251208160228.13145-1-bigalex934@gmail.com> (raw)
According to MAX_CAPSET_ID, possible values of vgdev->capsets[i].id
range from 0 to 63. Since the intermediate calculation uses type int,
shifting by values larger than the bit width of int is undefined
behavior as per the C language standard.
Explicitly cast the left-shift operand to ULL to prevent undefined
behavior during the calculation.
Found by Linux Verification Center (linuxtesting.org) with Svace.
Fixes: 1925d6a7e0f4 ("drm/virtio: implement context init: track valid capabilities in a mask")
Signed-off-by: Alexey Simakov <bigalex934@gmail.com>
---
drivers/gpu/drm/virtio/virtgpu_kms.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
index 1c15cbf326b7..2e0ec7590ac2 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -104,7 +104,7 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
return;
}
- vgdev->capset_id_mask |= 1 << vgdev->capsets[i].id;
+ vgdev->capset_id_mask |= 1ULL << vgdev->capsets[i].id;
DRM_INFO("cap set %d: id %d, max-version %d, max-size %d\n",
i, vgdev->capsets[i].id,
vgdev->capsets[i].max_version,
--
2.34.1
next reply other threads:[~2025-12-08 16:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 16:02 Alexey Simakov [this message]
2025-12-11 4:58 ` Dmitry Osipenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251208160228.13145-1-bigalex934@gmail.com \
--to=bigalex934@gmail.com \
--cc=airlied@redhat.com \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gurchetansingh@chromium.org \
--cc=kraxel@redhat.com \
--cc=lfy@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=olvaffe@gmail.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®