Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "João Peixoto" <jpeixoto@osyx.tech>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/3] virt: bao: add IPC shared-memory driver
Date: Sun, 27 Sep 2026 12:00:16 +0000	[thread overview]
Message-ID: <20260927120016.B841D1F00893@smtp.kernel.org> (raw)
In-Reply-To: <d5b8553918e16173aaf4767e32daeb47b656a253.1790357735.git.jpeixoto@osyx.tech>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] virt: bao: UAF on module initialization failure
--

commit 2f861bb98100794551d8aebc0473ce9f71733cac
Author: João Peixoto <jpeixoto@osyx.tech>

virt: bao: add IPC shared-memory driver

This commit introduces a new IPC shared-memory driver for the Bao hypervisor.
It allows guests to communicate through read and write regions configured via
the bao_ipcshmem.channels module parameter, exposing each channel as a misc
character device to userspace.

> diff --git a/drivers/virt/bao/ipcshmem/ipcshmem.c b/drivers/virt/bao/ipcshmem/ipcshmem.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/virt/bao/ipcshmem/ipcshmem.c
> @@ -0,0 +1,358 @@
[ ... ]
> +static int __init bao_ipcshmem_init(void)
> +{
> +	char *buf, *p, *desc;
> +	int ret = 0;
> +
> +	if (!channels || !*channels)
> +		return 0;
> +
> +	buf = kstrdup(channels, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	p = buf;
> +	while ((desc = strsep(&p, ";")) != NULL) {
> +		if (!*desc)
> +			continue;
> +		ret = bao_ipcshmem_parse_one(desc);
> +		if (ret) {
> +			pr_err("bad 'channels' descriptor\n");
> +			bao_ipcshmem_remove_all();

[Severity: High]
Can this error path lead to a use-after-free if userspace has already opened a
character device?

When multiple channels are specified in the module parameter,
bao_ipcshmem_init() parses them in a loop. For each successfully parsed
channel, bao_ipcshmem_add() immediately exposes the device to userspace via
misc_register():

bao_ipcshmem_init()
  bao_ipcshmem_parse_one()
    bao_ipcshmem_add()
      misc_register(&bao->miscdev);

If a subsequent channel fails to parse, bao_ipcshmem_init() takes this error
path and calls bao_ipcshmem_remove_all(). This unregisters and frees all
previously registered channels.

If a user-space process (such as udev) opens the first exposed character
device before the initialization failure occurs, the file descriptor remains
active. However, the initialization failure causes the kernel to unload the
module and free its memory. Subsequent system calls on the active file
descriptor would attempt to access the unmapped file_operations structure and
the freed struct bao_ipcshmem data, crashing the system.

Would it be safer to defer calling misc_register() until all channels have
been successfully parsed and added to the list?

> +			break;
> +		}
> +	}
> +
> +	kfree(buf);
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790357735.git.jpeixoto@osyx.tech?part=1

  reply	other threads:[~2026-09-27 12:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27 11:49 [PATCH v4 0/3] virt: bao: add Bao hypervisor IPC and I/O dispatcher drivers João Peixoto
2026-09-27 11:49 ` [PATCH v4 1/3] virt: bao: add IPC shared-memory driver João Peixoto
2026-09-27 12:00   ` sashiko-bot [this message]
2026-09-27 11:49 ` [PATCH v4 2/3] virt: bao: add I/O dispatcher driver João Peixoto
2026-09-27 12:02   ` sashiko-bot
2026-09-27 11:49 ` [PATCH v4 3/3] MAINTAINERS: add Bao hypervisor entry João Peixoto

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=20260927120016.B841D1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jpeixoto@osyx.tech \
    --cc=robh@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox