Rust for Linux List
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: "Matthew Brost" <matthew.brost@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Boris Brezillon" <boris.brezillon@collabora.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] drm/gpuvm: skip setting kernel_alloc_node range on overflow
Date: Sun, 11 Oct 2026 13:46:47 +0200	[thread overview]
Message-ID: <DM1ZG8WZJOE7.C6W4AHB6H2CX@kernel.org> (raw)
In-Reply-To: <20261011-gpuvm-reserve-overflow-v1-1-9c0cb23d7409@google.com>

On Sun Oct 11, 2026 at 9:22 AM CEST, Alice Ryhl wrote:
> When the reserved VA range overflows in drm_gpuvm_init(), insertion of
> kernel_alloc_node is skipped, leaving its vm pointer NULL. However,
> va.range is still set to a non-zero value, which causes drm_gpuvm_fini()
> to dereference the NULL vm pointer when removing the node. Thus, only
> initialize kernel_alloc_node's address and range when the overflow check
> succeeds.
>
> Note that this fixes unsoundness in the Rust GpuVm::new() abstraction:
> passing a backwards reserve_range (start > end) when overflow checks are
> disabled causes `end - start` to wrap around, triggering the overflow in
> drm_gpuvm_init() and dereferencing NULL when the GpuVm is dropped.
>
> Fixes: e6303f323b1a ("drm: manager to keep track of GPUs VA mappings")
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Good catch! Please also add Cc: stable.

> @@ -1127,12 +1127,12 @@ drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name,
>  
>  	memset(&gpuvm->kernel_alloc_node, 0, sizeof(struct drm_gpuva));
>  	if (reserve_range) {
> -		gpuvm->kernel_alloc_node.va.addr = reserve_offset;
> -		gpuvm->kernel_alloc_node.va.range = reserve_range;
> -
>  		if (likely(!drm_gpuvm_warn_check_overflow(gpuvm, reserve_offset,
> -							  reserve_range)))
> +							  reserve_range))) {
> +			gpuvm->kernel_alloc_node.va.addr = reserve_offset;
> +			gpuvm->kernel_alloc_node.va.range = reserve_range;
>  			__drm_gpuva_insert(gpuvm, &gpuvm->kernel_alloc_node);
> +		}
>  	}

Please collapse this to a single if statement.

Thanks,
Danilo

      reply	other threads:[~2026-10-11 11:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11  7:22 [PATCH] drm/gpuvm: skip setting kernel_alloc_node range on overflow Alice Ryhl
2026-10-11 11:46 ` Danilo Krummrich [this message]

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=DM1ZG8WZJOE7.C6W4AHB6H2CX@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=boris.brezillon@collabora.com \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.brost@intel.com \
    --cc=mripard@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tmgross@umich.edu \
    --cc=tzimmermann@suse.de \
    --cc=work@onurozkan.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