All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiale Yao" <yaojiale02@163.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 4/6] drm/radeon: reject empty VRAM ranges
Date: Mon, 19 Oct 2026 08:50:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-176842@kernel.org> (raw)
In-Reply-To: <20261019084138.1821477-5-yaojiale02@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/radeon: NULL pointer dereference in radeon_ttm_set_active_vram_size()
--

commit 5b48ce714a8da9ec1142b39b688fe2ea60f7c240
Author: Jiale Yao <yaojiale02@163.com>

drm/radeon: reject empty VRAM ranges

This commit rejects VRAM sizes smaller than a page in radeon_ttm_init_vram()
before calling ttm_range_man_init() to avoid hitting a zero-range BUG check
in drm_mm_init().

> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index e7ab8162ac694..925593af1688b 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -69,6 +69,9 @@ struct radeon_device *radeon_get_rdev(struct ttm_device *bdev)
>  
>  static int radeon_ttm_init_vram(struct radeon_device *rdev)
>  {
> +	if (rdev->mc.real_vram_size < PAGE_SIZE)
> +		return -EINVAL;
> +
>  	return ttm_range_man_init(&rdev->mman.bdev, TTM_PL_VRAM,
>  				  false, rdev->mc.real_vram_size >> PAGE_SHIFT);
>  }

[Severity: High]
Can returning -EINVAL here lead to a NULL pointer dereference in
radeon_ttm_set_active_vram_size() during error teardown?

In drivers/gpu/drm/radeon/radeon_ttm.c, radeon_ttm_init() sets
rdev->mman.initialized = true before calling radeon_ttm_init_vram():

drivers/gpu/drm/radeon/radeon_ttm.c:radeon_ttm_init() {
	...
	rdev->mman.initialized = true;

	r = radeon_ttm_init_vram(rdev);
	if (r) {
		DRM_ERROR("Failed initializing VRAM heap.\n");
		return r;
	}
	...
}

When rdev->mc.real_vram_size < PAGE_SIZE, radeon_ttm_init_vram() now
returns -EINVAL before ttm_range_man_init() registers the TTM_PL_VRAM
manager, leaving rdev->mman.initialized set to true while the TTM_PL_VRAM
manager slot remains NULL.

As the error propagates up through radeon_bo_init() -> rdev->asic->init() ->
radeon_device_init() to radeon_driver_load_kms(), error cleanup calls
radeon_driver_unload_kms() -> radeon_device_fini() -> radeon_fini().

The ASIC .fini callbacks (such as r100_fini(), r600_fini(), and cik_fini())
stop the CP/DMA engines before calling radeon_bo_fini(), which invokes
radeon_ttm_set_active_vram_size() (for example via r100_cp_fini() ->
r100_cp_disable()):

drivers/gpu/drm/radeon/radeon_ttm.c:radeon_ttm_set_active_vram_size() {
	struct ttm_resource_manager *man;

	if (!rdev->mman.initialized)
		return;

	man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
	/* this just adjusts TTM size idea, which sets lpfn to the correct value */
	man->size = size >> PAGE_SHIFT;
}

Because rdev->mman.initialized is true, wouldn't this bypass the early
return and dereference a NULL man pointer (and also abort teardown before
radeon_bo_fini() and radeon_ttm_fini() can clean up the initialized
ttm_device)?

Should radeon_ttm_init() only set rdev->mman.initialized = true after
initialization succeeds (or clean up ttm_device_fini() on failure), or
should radeon_ttm_set_active_vram_size() also check if man is NULL?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261019084138.1821477-1-yaojiale02@163.com?part=4

  reply	other threads:[~2026-10-19  8:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  8:41 [PATCH 0/6] drm: reject empty TTM range manager sizes Jiale Yao
2026-10-19  8:41 ` [PATCH 1/6] drm/vram-helper: reject empty VRAM ranges Jiale Yao
2026-10-19  8:41 ` [PATCH 2/6] drm/nouveau: " Jiale Yao
2026-10-19  8:50   ` sashiko-bot
2026-10-19  8:41 ` [PATCH 3/6] drm/qxl: reject empty TTM memory ranges Jiale Yao
2026-10-19  8:50   ` sashiko-bot
2026-10-19  8:41 ` [PATCH 4/6] drm/radeon: reject empty VRAM ranges Jiale Yao
2026-10-19  8:50   ` sashiko-bot [this message]
2026-10-19  8:41 ` [PATCH 5/6] drm/ttm: reject empty range manager sizes Jiale Yao
2026-10-19  8:41 ` [PATCH 6/6] drm/vmwgfx: reject empty VRAM ranges Jiale Yao
2026-10-19  8:48 ` [PATCH 0/6] drm: reject empty TTM range manager sizes 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=sashiko-outbox-176842@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yaojiale02@163.com \
    /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.