From: Hari Mishal <harimishal1@gmail.com>
To: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Hari Mishal" <harimishal1@gmail.com>
Subject: [PATCH] drm/amdkfd: reject alloc_memory_of_gpu with wrapping va_addr/mmap_offset
Date: Thu, 30 Jul 2026 17:35:55 +0200 [thread overview]
Message-ID: <20260730153555.15176-1-harimishal1@gmail.com> (raw)
kfd_ioctl_alloc_memory_of_gpu() computes the SVM overlap-check range as
[va_addr, va_addr + size - 1] (and likewise for mmap_offset) and passes
it to interval_tree_iter_first() with no check that the addition can
overflow u64. With va_addr near U64_MAX, the end wraps below start,
interval_tree_iter_first() sees an inverted range and returns NULL, and
the overlap check is silently skipped. /dev/kfd is unprivileged, and
va_addr/size/mmap_offset are plain fields in the ioctl argument struct
supplied directly by the calling process, so this is reachable by any
local user with a single crafted ioctl call.
Reject the ioctl when either va_addr+size or mmap_offset+size overflows,
using check_add_overflow().
Signed-off-by: Hari Mishal <harimishal1@gmail.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 309510e23315..12954d65503c 100644
--- 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,
long err;
uint64_t offset = args->mmap_offset;
uint32_t flags = args->flags;
+ u64 end;
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;
+
if (p->context_id != KFD_CONTEXT_ID_PRIMARY && (flags & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR)) {
pr_debug("USERPTR is not supported on non-primary kfd_process\n");
--
2.43.0
next reply other threads:[~2026-07-30 15:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 15:35 Hari Mishal [this message]
2026-07-30 15:46 ` [PATCH] drm/amdkfd: reject alloc_memory_of_gpu with wrapping va_addr/mmap_offset sashiko-bot
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=20260730153555.15176-1-harimishal1@gmail.com \
--to=harimishal1@gmail.com \
--cc=Felix.Kuehling@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.