From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: "Fedor Pchelkin" <pchelkin@ispras.ru>,
"Christian König" <christian.koenig@amd.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Denis Arefev <arefev@swemel.ru>,
Alex Deucher <alexander.deucher@amd.com>,
Simona Vetter <simona@ffwll.ch>,
lvc-project@linuxtesting.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
David Airlie <airlied@gmail.com>
Subject: Re: [lvc-project] [PATCH] drm/amdgpu: check a user-provided number of BOs in list
Date: Mon, 14 Apr 2025 11:35:24 +0200 [thread overview]
Message-ID: <44f0bf71-c689-46de-bfdc-e4a24b9fb921@gmail.com> (raw)
In-Reply-To: <fgd6hrllcwj2guhr4mwzfblhausluczprlbjqhsqiqeshoq2g2@jgi4rgufn6wx>
Am 13.04.25 um 13:31 schrieb Fedor Pchelkin:
> On Thu, 10. Apr 11:07, Christian König wrote:
>> Am 09.04.25 um 19:27 schrieb Linus Torvalds:
>>> The VM layer allows larger allocations. But the "this is a simple
>>> allocation, choose kmalloc or vmalloc automatically based on size"
>>> helper says "you are being simple, I'm going to check your arguments
>>> are actually sane".
>>>
>>> So the drm code can easily have a function that validates the input
>>> for your specific cases, and then you (a) don't need the helper
>>> function that does the overflow protection and (b) don't want it.
>>>
>>> But it should actually validate arguments for real sanity at that
>>> point. Not just open-code kvmalloc() without the sanity check.
>> Yeah, exactly that has been proposed by driver maintainers before and we just rejected it on the subsystem maintainers level.
>>
>> For this particular use case here I will propose some hopefully high enough hard coded limit, but I can't guarantee that this will work for all use cases.
> FWIW, the current code anyway has this limit being some sort of 4Gb, not
> more.
>
> The resulting calculation of `bytes` wraps at 32 bits albeit itself being
> of type *unsigned long*.
Yeah that is a *much* more serious bug. Thanks for pointing that out.
This should probably be using size_t here and applying the limit to the bo_number before the calculation.
And a bo_info_size which doesn't match the expected size should be rejected and not worked around like it currently is.
Thanks,
Christian.
>
> /* copy the handle array from userspace to a kernel buffer */
> r = -EFAULT;
> if (likely(info_size == in->bo_info_size)) {
> unsigned long bytes = in->bo_number *
> in->bo_info_size;
>
> if (copy_from_user(info, uptr, bytes))
> goto error_free;
>
next prev parent reply other threads:[~2025-04-14 9:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 9:17 [PATCH] drm/amdgpu: check a user-provided number of BOs in list Denis Arefev
2025-04-08 9:26 ` Christian König
2025-04-08 9:39 ` [lvc-project] " Fedor Pchelkin
2025-04-08 11:37 ` Christian König
2025-04-08 11:54 ` Fedor Pchelkin
[not found] ` <edc08eb4-63dd-402c-82df-af6898d499a9@amd.com>
2025-04-08 16:07 ` Fedor Pchelkin
2025-04-09 2:39 ` Linus Torvalds
2025-04-09 7:29 ` Christian König
2025-04-09 17:27 ` Linus Torvalds
2025-04-10 9:07 ` Christian König
2025-04-13 11:31 ` Fedor Pchelkin
2025-04-14 9:35 ` Christian König [this message]
2025-04-14 9:27 ` Christian König
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=44f0bf71-c689-46de-bfdc-e4a24b9fb921@gmail.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=arefev@swemel.ru \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=pchelkin@ispras.ru \
--cc=simona@ffwll.ch \
--cc=torvalds@linux-foundation.org \
/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