From: "Christian König" <christian.koenig@amd.com>
To: Werner Kasselman <werner@verivus.ai>,
Alex Deucher <alexander.deucher@amd.com>
Cc: David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Thomas Zimmermann <tzimmermann@suse.de>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2] drm/amdgpu: fix integer overflow in amdgpu_gem_align_pitch()
Date: Tue, 14 Apr 2026 11:26:47 +0200 [thread overview]
Message-ID: <8892f093-a98b-481e-b01e-4e640d2edc54@amd.com> (raw)
In-Reply-To: <20260414050840.244705-1-werner@verivus.com>
On 4/14/26 07:08, Werner Kasselman wrote:
> amdgpu_gem_align_pitch() is passed u32 width and cpp from dumb buffer
> creation but uses signed int internally. The round-up add and the
> aligned * cpp multiplication can overflow, returning zero or a negative
> pitch. A zero pitch propagates to a zero-sized GEM object allocation
> that reaches userspace via DRM_IOCTL_MODE_CREATE_DUMB.
>
> Switch the helper to unsigned int and use check_add_overflow() /
> check_mul_overflow() so wraparound returns zero. Reject a zero pitch
> or size in amdgpu_mode_dumb_create() rather than allocating a zero-
> byte BO.
>
> Fixes: 8e911ab770f7 ("drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()")
> Cc: stable@vger.kernel.org
The patch looks valid to me, but I think we can drop this CC: stable.
Since dump buffers are a kernel only interface the fix has no practical relevance and is only of cosmetic nature.
Regards,
Christian.
> Signed-off-by: Werner Kasselman <werner@verivus.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index a6107109a2b8..0d9309f792a4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -27,6 +27,7 @@
> */
> #include <linux/ktime.h>
> #include <linux/module.h>
> +#include <linux/overflow.h>
> #include <linux/pagemap.h>
> #include <linux/pci.h>
> #include <linux/dma-buf.h>
> @@ -1223,13 +1224,14 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
> return ret;
> }
>
> -static int amdgpu_gem_align_pitch(struct amdgpu_device *adev,
> - int width,
> - int cpp,
> - bool tiled)
> +static unsigned int amdgpu_gem_align_pitch(struct amdgpu_device *adev,
> + unsigned int width,
> + unsigned int cpp,
> + bool tiled)
> {
> - int aligned = width;
> - int pitch_mask = 0;
> + unsigned int aligned = width;
> + unsigned int pitch_mask = 0;
> + unsigned int pitch;
>
> switch (cpp) {
> case 1:
> @@ -1244,9 +1246,12 @@ static int amdgpu_gem_align_pitch(struct amdgpu_device *adev,
> break;
> }
>
> - aligned += pitch_mask;
> + if (check_add_overflow(aligned, pitch_mask, &aligned))
> + return 0;
> aligned &= ~pitch_mask;
> - return aligned * cpp;
> + if (check_mul_overflow(aligned, cpp, &pitch))
> + return 0;
> + return pitch;
> }
>
> int amdgpu_mode_dumb_create(struct drm_file *file_priv,
> @@ -1273,8 +1278,12 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,
>
> args->pitch = amdgpu_gem_align_pitch(adev, args->width,
> DIV_ROUND_UP(args->bpp, 8), 0);
> + if (!args->pitch)
> + return -EINVAL;
> args->size = (u64)args->pitch * args->height;
> args->size = ALIGN(args->size, PAGE_SIZE);
> + if (!args->size)
> + return -EINVAL;
> domain = amdgpu_bo_get_preferred_domain(adev,
> amdgpu_display_supported_domains(adev, flags));
> r = amdgpu_gem_object_create(adev, args->size, 0, domain, flags,
next prev parent reply other threads:[~2026-04-14 9:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 22:50 [PATCH 0/2] drm/amdgpu,radeon: fix integer overflow in pitch alignment Werner Kasselman
2026-04-06 22:50 ` [PATCH 1/2] drm/amdgpu: fix integer overflow in amdgpu_gem_align_pitch() Werner Kasselman
2026-04-13 18:13 ` Alex Deucher
2026-04-14 5:08 ` [PATCH v2] " Werner Kasselman
2026-04-14 9:26 ` Christian König [this message]
2026-04-06 22:50 ` [PATCH 2/2] drm/radeon: fix integer overflow in radeon_align_pitch() Werner Kasselman
2026-04-14 13:11 ` Alex Deucher
2026-04-14 21:14 ` [PATCH v2] " Werner Kasselman
2026-04-15 12:59 ` Alex Deucher
2026-04-15 22:13 ` [PATCH v3] " Werner Kasselman
2026-04-17 13:34 ` Alex Deucher
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=8892f093-a98b-481e-b01e-4e640d2edc54@amd.com \
--to=christian.koenig@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=stable@vger.kernel.org \
--cc=tzimmermann@suse.de \
--cc=werner@verivus.ai \
/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