dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hari Mishal" <harimishal1@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdkfd: reject alloc_memory_of_gpu with wrapping va_addr/mmap_offset
Date: Thu, 30 Jul 2026 15:46:43 +0000	[thread overview]
Message-ID: <20260730154644.226891F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730153555.15176-1-harimishal1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch adds an unconditional overflow check on `args->mmap_offset`, which is strictly an OUT parameter for most allocation types. This will cause perfectly valid ioctl calls to randomly fail with `-EINVAL` if userspace leaves the output field uninitialized.
--

--- Patch [1]: [PATCH] drm/amdkfd: reject alloc_memory_of_gpu with wrapping va_addr/mmap_offset ---
commit 90e63e5cacd60faaf13c89e037955751ad085487
Author: Hari Mishal <harimishal1@gmail.com>

drm/amdkfd: reject alloc_memory_of_gpu with wrapping va_addr/mmap_offset

This commit adds check_add_overflow() checks to kfd_ioctl_alloc_memory_of_gpu()
to prevent integer wrap-arounds when calculating the end address of va_addr
and mmap_offset.

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1089,10 +1089,15 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
[ ... ]
>  	if (args->size == 0)
>  		return -EINVAL;
>  
> +	if (check_add_overflow(args->va_addr, args->size, &end) ||
> +	    check_add_overflow(args->mmap_offset, args->size, &end))
> +		return -EINVAL;
> +

[Severity: High]
Will this check cause valid allocation requests to fail if the user space
application leaves args->mmap_offset uninitialized?

According to the uAPI in kfd_ioctl.h, mmap_offset is an OUT parameter
for non-USERPTR allocations:

struct kfd_ioctl_alloc_memory_of_gpu_args {
	...
	__u64 mmap_offset;	/* to KFD (userptr), from KFD (mmap offset) */
	...
};

Since this check is unconditional, if userspace calls this ioctl without the
KFD_IOC_ALLOC_MEM_FLAGS_USERPTR flag and leaves the mmap_offset field
uninitialized on the stack, random garbage in that field could trigger this
overflow check and spuriously return -EINVAL.

Should the args->mmap_offset overflow check be restricted to only run when
(args->flags & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) is true?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730153555.15176-1-harimishal1@gmail.com?part=1

  reply	other threads:[~2026-07-30 15:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 15:35 [PATCH] drm/amdkfd: reject alloc_memory_of_gpu with wrapping va_addr/mmap_offset Hari Mishal
2026-07-30 15:46 ` sashiko-bot [this message]
2026-08-04 13:44   ` 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=20260730154644.226891F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=harimishal1@gmail.com \
    --cc=sashiko-reviews@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