All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gabriel Gama" <operatingsystemsdepression@gmail.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH 6/6] drm/gma500: Add software-only KUnit coverage for SGX page tables
Date: Mon, 09 Nov 2026 06:07:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-204484@kernel.org> (raw)
In-Reply-To: <20261109055451.17458-7-operatingsystemsdepression@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/gma500: NULL deref and double free in psb_mmu_test_exit()
  on init error
--

commit 0ae7cbd175ba45e2df744da8590157d933a675ae
Author: Gabriel Gama <operatingsystemsdepression@gmail.com>

drm/gma500: Add software-only KUnit coverage for SGX page tables

This commit adds a built-in KUnit test suite for GMA500 SGX page-table
operations using a software page directory without hardware access.

> diff --git a/drivers/gpu/drm/gma500/mmu_test.c b/drivers/gpu/drm/gma500/mmu_test.c
> new file mode 100644
> index 0000000000000..0581c7d9ac4ac
> --- /dev/null
> +++ b/drivers/gpu/drm/gma500/mmu_test.c
> @@ -0,0 +1,222 @@
[ ... ]
> +static int psb_mmu_test_init(struct kunit *test)
> +{
> +	struct psb_mmu_test_context *ctx;
> +	int i;
> +
> +	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> +	if (!ctx)
> +		return -ENOMEM;
> +	test->priv = ctx;
> +	spin_lock_init(&ctx->driver.lock);
> +	init_rwsem(&ctx->driver.sem);
> +	ctx->pd = psb_mmu_alloc_pd(&ctx->driver, 1, 0);
> +	if (!ctx->pd)
> +		return -ENOMEM;
> +	for (i = 0; i < ARRAY_SIZE(ctx->pages); i++) {
> +		ctx->pages[i] = alloc_page(GFP_DMA32);
> +		if (!ctx->pages[i]) {
> +			while (i--)
> +				__free_page(ctx->pages[i]);
> +			psb_mmu_free_pagedir(ctx->pd);
> +			return -ENOMEM;
> +		}
> +	}
> +	return 0;
> +}
> +
> +static void psb_mmu_test_exit(struct kunit *test)
> +{
> +	struct psb_mmu_test_context *ctx = test->priv;
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(ctx->pages); i++)
> +		__free_page(ctx->pages[i]);
> +	psb_mmu_free_pagedir(ctx->pd);
> +}

[Severity: Medium]
Can psb_mmu_test_exit() cause a NULL pointer dereference or double free
when psb_mmu_test_init() fails?

KUnit runs suite->exit(test) via kunit_run_case_cleanup() even when
suite->init(test) returns a non-zero error.  If kunit_kzalloc() or
psb_mmu_alloc_pd() fails, psb_mmu_test_exit() dereferences a NULL ctx or
ctx->pd; if alloc_page() fails, psb_mmu_test_init() frees ctx->pages[] and
ctx->pd without clearing the pointers, and psb_mmu_test_exit() frees them
again while passing NULL for the unallocated pages.

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

  reply	other threads:[~2026-11-09  6:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09  5:54 [RFC PATCH 0/6] drm/gma500: prepare GEM and MMU for 3D rendering and hybrid 2D Gabriel Gama
2026-11-09  5:54 ` [RFC PATCH 1/6] drm/gma500: use the common dumb-buffer size helper Gabriel Gama
2026-11-09  5:54 ` [RFC PATCH 2/6] drm/gma500: do not underflow an unpinned GEM object Gabriel Gama
2026-11-09  5:54 ` [RFC PATCH 3/6] drm/gma500: Fix SGX page-table cache-flush mapping lifetime Gabriel Gama
2026-11-09  6:00   ` sashiko-bot
2026-11-09  5:54 ` [RFC PATCH 4/6] drm/gma500: Make SGX MMU insertion checked and transactional Gabriel Gama
2026-11-09  5:54 ` [RFC PATCH 5/6] drm/gma500: Propagate SGX MMU setup and GEM pin failures Gabriel Gama
2026-11-09  6:06   ` sashiko-bot
2026-11-09  5:54 ` [RFC PATCH 6/6] drm/gma500: Add software-only KUnit coverage for SGX page tables Gabriel Gama
2026-11-09  6:07   ` sashiko-bot [this message]
2026-11-09  6:26     ` Operating System's Depression

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-204484@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=operatingsystemsdepression@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 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.