* [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl()
@ 2026-07-08 1:28 Yi Xie
2026-07-08 1:42 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yi Xie @ 2026-07-08 1:28 UTC (permalink / raw)
To: kys, haiyangz, wei.liu; +Cc: linux-hyperv, linux-kernel, Yi Xie
put_unused_fd() if anon_inode_getfile() fails.
Signed-off-by: Yi Xie <xieyi@kylinos.cn>
---
drivers/hv/mshv_vtl_main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c
index 0d3d4161974f..897a41b08d02 100644
--- a/drivers/hv/mshv_vtl_main.c
+++ b/drivers/hv/mshv_vtl_main.c
@@ -129,6 +129,7 @@ mshv_ioctl_create_vtl(void __user *user_arg, struct device *module_dev)
file = anon_inode_getfile("mshv_vtl", &mshv_vtl_fops,
vtl, O_RDWR);
if (IS_ERR(file)) {
+ put_unused_fd(fd);
kfree(vtl);
return PTR_ERR(file);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl()
2026-07-08 1:28 [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl() Yi Xie
@ 2026-07-08 1:42 ` sashiko-bot
2026-07-08 13:05 ` Hamza Mahfooz
2026-07-09 16:05 ` Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-07-08 1:42 UTC (permalink / raw)
To: Yi Xie; +Cc: linux-hyperv
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The `mshv_vtl_fault` mmap fault handler fails to bounds-check the user-controlled `cpu` index against `nr_cpu_ids`.
--
--- Patch [1]: [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl() ---
commit 2e3734b84c858c82d0ec893b4137e370673f6928
Author: Yi Xie <xieyi@kylinos.cn>
mshv: fix fd leak in mshv_ioctl_create_vtl()
This commit addresses a file descriptor leak in mshv_ioctl_create_vtl().
It ensures put_unused_fd() is called when anon_inode_getfile() fails,
freeing the allocated file descriptor before returning an error.
> diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c
> index 0d3d4161974f8..897a41b08d026 100644
> --- a/drivers/hv/mshv_vtl_main.c
> +++ b/drivers/hv/mshv_vtl_main.c
> @@ -129,6 +129,7 @@ mshv_ioctl_create_vtl(void __user *user_arg, struct device *module_dev)
> file = anon_inode_getfile("mshv_vtl", &mshv_vtl_fops,
> vtl, O_RDWR);
> if (IS_ERR(file)) {
> + put_unused_fd(fd);
> kfree(vtl);
> return PTR_ERR(file);
> }
[Severity: Critical]
This is a pre-existing issue, but while reviewing this file I noticed an
insufficient bounds check in the mmap fault handler.
Does this missing validation allow an out-of-bounds pointer arithmetic
regression?
drivers/hv/mshv_vtl_main.c:mshv_vtl_fault() {
struct page *page;
int cpu = vmf->pgoff & MSHV_PG_OFF_CPU_MASK;
int real_off = vmf->pgoff >> MSHV_REAL_OFF_SHIFT;
if (!cpu_online(cpu))
return VM_FAULT_SIGBUS;
A VMA with a large offset can cause vmf->pgoff to yield an arbitrary
cpu index. The only validation is cpu_online(cpu), which uses an
unbounds-checked test_bit() against cpu_online_mask.
If the out-of-bounds read hits a set bit, the check passes. Execution then
proceeds to mshv_vtl_cpu_run(cpu), calling per_cpu_ptr() which reads from
the __per_cpu_offset array out-of-bounds.
The resulting garbage pointer is passed to virt_to_page(), and get_page()
incorrectly increments a reference count, potentially mapping arbitrary
physical memory into userspace.
Should this code check the cpu index against nr_cpu_ids before passing it
to cpu_online()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708012852.36824-1-xieyi@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl()
2026-07-08 1:28 [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl() Yi Xie
2026-07-08 1:42 ` sashiko-bot
@ 2026-07-08 13:05 ` Hamza Mahfooz
2026-07-09 16:05 ` Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: Hamza Mahfooz @ 2026-07-08 13:05 UTC (permalink / raw)
To: Yi Xie; +Cc: kys, haiyangz, wei.liu, linux-hyperv, linux-kernel
On Wed, Jul 08, 2026 at 09:28:52AM +0800, Yi Xie wrote:
> put_unused_fd() if anon_inode_getfile() fails.
>
> Signed-off-by: Yi Xie <xieyi@kylinos.cn>
Reviewed-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
> ---
> drivers/hv/mshv_vtl_main.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c
> index 0d3d4161974f..897a41b08d02 100644
> --- a/drivers/hv/mshv_vtl_main.c
> +++ b/drivers/hv/mshv_vtl_main.c
> @@ -129,6 +129,7 @@ mshv_ioctl_create_vtl(void __user *user_arg, struct device *module_dev)
> file = anon_inode_getfile("mshv_vtl", &mshv_vtl_fops,
> vtl, O_RDWR);
> if (IS_ERR(file)) {
> + put_unused_fd(fd);
> kfree(vtl);
> return PTR_ERR(file);
> }
> --
> 2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl()
2026-07-08 1:28 [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl() Yi Xie
2026-07-08 1:42 ` sashiko-bot
2026-07-08 13:05 ` Hamza Mahfooz
@ 2026-07-09 16:05 ` Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-07-09 16:05 UTC (permalink / raw)
To: Yi Xie, linux-hyperv, Haiyang Zhang, Hamza Mahfooz,
K. Y. Srinivasan, Wei Liu
Cc: LKML
> put_unused_fd() if anon_inode_getfile() fails.
How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
See also:
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.2-rc2#n145
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v7.2-rc2#n34
* Would you like to complete the exception handling by using another goto chain?
* How do you think about to increase the application of scope-based resource management?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-09 16:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 1:28 [PATCH] mshv: fix fd leak in mshv_ioctl_create_vtl() Yi Xie
2026-07-08 1:42 ` sashiko-bot
2026-07-08 13:05 ` Hamza Mahfooz
2026-07-09 16:05 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox