* [PATCH] staging: vme_user: validate slave window size against buffer size
@ 2026-05-09 6:58 木口璃音
2026-05-09 7:15 ` gregkh
2026-05-09 7:17 ` gregkh
0 siblings, 2 replies; 6+ messages in thread
From: 木口璃音 @ 2026-05-09 6:58 UTC (permalink / raw)
To: gregkh@linuxfoundation.org; +Cc: linux-staging, linux-kernel, stable, security
This patch addresses the OOB read/write reported earlier
in the security@kernel.org thread (now handled publicly per
Greg's and Willy's guidance).
Tested on Linux 7.1.0-rc2 with KASAN; all three reproducers
fail with -EINVAL after applying this patch and produce no
KASAN splat.
From 506ecfc9b8608fb3a56477b8fd205238a1bf66ff Mon Sep 17 00:00:00 2001
From: Rion Kiguchi <kiguchi.r.sec@gmail.com>
Date: Sat, 9 May 2026 15:38:33 +0900
Subject: [PATCH] staging: vme_user: validate slave window size against buffer
size
The VME_SET_SLAVE ioctl in drivers/staging/vme_user/vme_user.c accepts
a user-controlled slave.size and forwards it to vme_slave_set() without
comparing it against image[minor].size_buf. The slave-image kernel
buffer is allocated at probe time with a fixed size of PCI_BUF_SIZE
(0x20000 / 128 KiB), but the configured VME window size can be made
much larger via the ioctl.
The subsequent read() / write() handlers (vme_user_read /
vme_user_write) clamp the I/O range against vme_get_size() (the
configured window size, attacker-controlled) but never consult
size_buf. The slave I/O paths buffer_to_user() and buffer_from_user()
then index image[minor].kern_buf with *ppos values up to
image_size - 1, well beyond the actual allocation.
Result: a local user with read/write access to /dev/bus/vme/s* can
trigger out-of-bounds read and write of the kernel slab adjacent to
the slave-image buffer.
Fix: reject slave.size > size_buf in the VME_SET_SLAVE handler. Also
add defensive bounds checks against size_buf in buffer_to_user() and
buffer_from_user() so that the I/O paths cannot exceed the
allocation even if a future ioctl path forgets to validate.
Reported-by: Pochix1103 <kiguchi.r.sec@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Rion Kiguchi <kiguchi.r.sec@gmail.com>
---
drivers/staging/vme_user/vme_user.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/vme_user/vme_user.c
b/drivers/staging/vme_user/vme_user.c
index 11e25c2f6..41b8d5b51 100644
--- a/drivers/staging/vme_user/vme_user.c
+++ b/drivers/staging/vme_user/vme_user.c
@@ -156,6 +156,11 @@ static ssize_t buffer_to_user(unsigned int minor,
char __user *buf,
{
void *image_ptr;
+ if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
+ count > image[minor].size_buf - (u64)*ppos) {
+ pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
+ return -EINVAL;
+ }
image_ptr = image[minor].kern_buf + *ppos;
if (copy_to_user(buf, image_ptr, (unsigned long)count))
return -EFAULT;
@@ -168,6 +173,11 @@ static ssize_t buffer_from_user(unsigned int
minor, const char __user *buf,
{
void *image_ptr;
+ if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
+ count > image[minor].size_buf - (u64)*ppos) {
+ pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
+ return -EINVAL;
+ }
image_ptr = image[minor].kern_buf + *ppos;
if (copy_from_user(image_ptr, buf, (unsigned long)count))
return -EFAULT;
@@ -394,6 +404,14 @@ static int vme_user_ioctl(struct inode *inode,
struct file *file,
return -EFAULT;
}
+ /*
+ * Reject window sizes larger than the kernel buffer
+ * allocated at probe time, otherwise subsequent
+ * read/write would access memory beyond kern_buf.
+ */
+ if (slave.size > image[minor].size_buf)
+ return -EINVAL;
+
/* XXX We do not want to push aspace, cycle and width
* to userspace as they are
*/
@@ -401,7 +419,6 @@ static int vme_user_ioctl(struct inode *inode,
struct file *file,
slave.enable, slave.vme_addr, slave.size,
image[minor].pci_buf, slave.aspace,
slave.cycle);
-
break;
}
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: vme_user: validate slave window size against buffer size
2026-05-09 6:58 木口璃音
@ 2026-05-09 7:15 ` gregkh
2026-05-09 7:17 ` gregkh
1 sibling, 0 replies; 6+ messages in thread
From: gregkh @ 2026-05-09 7:15 UTC (permalink / raw)
To: 木口璃音
Cc: linux-staging, linux-kernel, stable, security
On Sat, May 09, 2026 at 03:58:45PM +0900, 木口璃音 wrote:
> This patch addresses the OOB read/write reported earlier
> in the security@kernel.org thread (now handled publicly per
> Greg's and Willy's guidance).
>
> Tested on Linux 7.1.0-rc2 with KASAN; all three reproducers
> fail with -EINVAL after applying this patch and produce no
> KASAN splat.
>
> >From 506ecfc9b8608fb3a56477b8fd205238a1bf66ff Mon Sep 17 00:00:00 2001
> From: Rion Kiguchi <kiguchi.r.sec@gmail.com>
> Date: Sat, 9 May 2026 15:38:33 +0900
> Subject: [PATCH] staging: vme_user: validate slave window size against buffer
> size
This all doesn't belong in the body of the email, please just use git
send-email to send the patch.
>
> The VME_SET_SLAVE ioctl in drivers/staging/vme_user/vme_user.c accepts
> a user-controlled slave.size and forwards it to vme_slave_set() without
> comparing it against image[minor].size_buf. The slave-image kernel
> buffer is allocated at probe time with a fixed size of PCI_BUF_SIZE
> (0x20000 / 128 KiB), but the configured VME window size can be made
> much larger via the ioctl.
>
> The subsequent read() / write() handlers (vme_user_read /
> vme_user_write) clamp the I/O range against vme_get_size() (the
> configured window size, attacker-controlled) but never consult
> size_buf. The slave I/O paths buffer_to_user() and buffer_from_user()
> then index image[minor].kern_buf with *ppos values up to
> image_size - 1, well beyond the actual allocation.
>
> Result: a local user with read/write access to /dev/bus/vme/s* can
> trigger out-of-bounds read and write of the kernel slab adjacent to
> the slave-image buffer.
>
> Fix: reject slave.size > size_buf in the VME_SET_SLAVE handler. Also
> add defensive bounds checks against size_buf in buffer_to_user() and
> buffer_from_user() so that the I/O paths cannot exceed the
> allocation even if a future ioctl path forgets to validate.
>
> Reported-by: Pochix1103 <kiguchi.r.sec@gmail.com>
Ok, but:
> Cc: stable@vger.kernel.org
> Signed-off-by: Rion Kiguchi <kiguchi.r.sec@gmail.com>
You don't have a reported-by and a signed-off-by for the same thing, if
you author and sign off, it's implied you are reporting the issue :)
Also, you have to document the AI tool you used to find and fix this as
per out documentation.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: vme_user: validate slave window size against buffer size
2026-05-09 6:58 木口璃音
2026-05-09 7:15 ` gregkh
@ 2026-05-09 7:17 ` gregkh
1 sibling, 0 replies; 6+ messages in thread
From: gregkh @ 2026-05-09 7:17 UTC (permalink / raw)
To: 木口璃音
Cc: linux-staging, linux-kernel, stable, security
On Sat, May 09, 2026 at 03:58:45PM +0900, 木口璃音 wrote:
> diff --git a/drivers/staging/vme_user/vme_user.c
> b/drivers/staging/vme_user/vme_user.c
> index 11e25c2f6..41b8d5b51 100644
> --- a/drivers/staging/vme_user/vme_user.c
> +++ b/drivers/staging/vme_user/vme_user.c
> @@ -156,6 +156,11 @@ static ssize_t buffer_to_user(unsigned int minor,
> char __user *buf,
> {
> void *image_ptr;
>
> + if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
> + count > image[minor].size_buf - (u64)*ppos) {
> + pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
> + return -EINVAL;
> + }
Also the patch is corrupted :(
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] staging: vme_user: validate slave window size against buffer size
@ 2026-05-09 7:53 Rion Kiguchi
2026-05-09 8:04 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Rion Kiguchi @ 2026-05-09 7:53 UTC (permalink / raw)
To: kiguchi.r.sec; +Cc: stable
The VME_SET_SLAVE ioctl in drivers/staging/vme_user/vme_user.c accepts
a user-controlled slave.size and forwards it to vme_slave_set() without
comparing it against image[minor].size_buf. The slave-image kernel
buffer is allocated at probe time with a fixed size of PCI_BUF_SIZE
(0x20000 / 128 KiB), but the configured VME window size can be made
much larger via the ioctl.
The subsequent read() / write() handlers (vme_user_read /
vme_user_write) clamp the I/O range against vme_get_size() (the
configured window size, attacker-controlled) but never consult
size_buf. The slave I/O paths buffer_to_user() and buffer_from_user()
then index image[minor].kern_buf with *ppos values up to
image_size - 1, well beyond the actual allocation.
Result: a local user with read/write access to /dev/bus/vme/s* can
trigger out-of-bounds read and write of the kernel slab adjacent to
the slave-image buffer.
Fix: reject slave.size > size_buf in the VME_SET_SLAVE handler. Also
add defensive bounds checks against size_buf in buffer_to_user() and
buffer_from_user() so that the I/O paths cannot exceed the
allocation even if a future ioctl path forgets to validate.
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Rion Kiguchi <kiguchi.r.sec@gmail.com>
---
drivers/staging/vme_user/vme_user.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c
index 11e25c2f6..41b8d5b51 100644
--- a/drivers/staging/vme_user/vme_user.c
+++ b/drivers/staging/vme_user/vme_user.c
@@ -156,6 +156,11 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
{
void *image_ptr;
+ if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
+ count > image[minor].size_buf - (u64)*ppos) {
+ pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
+ return -EINVAL;
+ }
image_ptr = image[minor].kern_buf + *ppos;
if (copy_to_user(buf, image_ptr, (unsigned long)count))
return -EFAULT;
@@ -168,6 +173,11 @@ static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
{
void *image_ptr;
+ if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
+ count > image[minor].size_buf - (u64)*ppos) {
+ pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
+ return -EINVAL;
+ }
image_ptr = image[minor].kern_buf + *ppos;
if (copy_from_user(image_ptr, buf, (unsigned long)count))
return -EFAULT;
@@ -394,6 +404,14 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
return -EFAULT;
}
+ /*
+ * Reject window sizes larger than the kernel buffer
+ * allocated at probe time, otherwise subsequent
+ * read/write would access memory beyond kern_buf.
+ */
+ if (slave.size > image[minor].size_buf)
+ return -EINVAL;
+
/* XXX We do not want to push aspace, cycle and width
* to userspace as they are
*/
@@ -401,7 +419,6 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
slave.enable, slave.vme_addr, slave.size,
image[minor].pci_buf, slave.aspace,
slave.cycle);
-
break;
}
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] staging: vme_user: validate slave window size against buffer size
@ 2026-05-09 8:02 Rion Kiguchi
0 siblings, 0 replies; 6+ messages in thread
From: Rion Kiguchi @ 2026-05-09 8:02 UTC (permalink / raw)
To: kiguchi.r.sec; +Cc: stable
The VME_SET_SLAVE ioctl in drivers/staging/vme_user/vme_user.c accepts
a user-controlled slave.size and forwards it to vme_slave_set() without
comparing it against image[minor].size_buf. The slave-image kernel
buffer is allocated at probe time with a fixed size of PCI_BUF_SIZE
(0x20000 / 128 KiB), but the configured VME window size can be made
much larger via the ioctl.
The subsequent read() / write() handlers (vme_user_read /
vme_user_write) clamp the I/O range against vme_get_size() (the
configured window size, attacker-controlled) but never consult
size_buf. The slave I/O paths buffer_to_user() and buffer_from_user()
then index image[minor].kern_buf with *ppos values up to
image_size - 1, well beyond the actual allocation.
Result: a local user with read/write access to /dev/bus/vme/s* can
trigger out-of-bounds read and write of the kernel slab adjacent to
the slave-image buffer.
Fix: reject slave.size > size_buf in the VME_SET_SLAVE handler. Also
add defensive bounds checks against size_buf in buffer_to_user() and
buffer_from_user() so that the I/O paths cannot exceed the
allocation even if a future ioctl path forgets to validate.
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Rion Kiguchi <kiguchi.r.sec@gmail.com>
---
drivers/staging/vme_user/vme_user.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c
index 11e25c2f6..41b8d5b51 100644
--- a/drivers/staging/vme_user/vme_user.c
+++ b/drivers/staging/vme_user/vme_user.c
@@ -156,6 +156,11 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
{
void *image_ptr;
+ if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
+ count > image[minor].size_buf - (u64)*ppos) {
+ pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
+ return -EINVAL;
+ }
image_ptr = image[minor].kern_buf + *ppos;
if (copy_to_user(buf, image_ptr, (unsigned long)count))
return -EFAULT;
@@ -168,6 +173,11 @@ static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
{
void *image_ptr;
+ if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
+ count > image[minor].size_buf - (u64)*ppos) {
+ pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
+ return -EINVAL;
+ }
image_ptr = image[minor].kern_buf + *ppos;
if (copy_from_user(image_ptr, buf, (unsigned long)count))
return -EFAULT;
@@ -394,6 +404,14 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
return -EFAULT;
}
+ /*
+ * Reject window sizes larger than the kernel buffer
+ * allocated at probe time, otherwise subsequent
+ * read/write would access memory beyond kern_buf.
+ */
+ if (slave.size > image[minor].size_buf)
+ return -EINVAL;
+
/* XXX We do not want to push aspace, cycle and width
* to userspace as they are
*/
@@ -401,7 +419,6 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
slave.enable, slave.vme_addr, slave.size,
image[minor].pci_buf, slave.aspace,
slave.cycle);
-
break;
}
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: vme_user: validate slave window size against buffer size
2026-05-09 7:53 Rion Kiguchi
@ 2026-05-09 8:04 ` Greg KH
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2026-05-09 8:04 UTC (permalink / raw)
To: Rion Kiguchi; +Cc: stable
On Sat, May 09, 2026 at 04:53:18PM +0900, Rion Kiguchi wrote:
> The VME_SET_SLAVE ioctl in drivers/staging/vme_user/vme_user.c accepts
> a user-controlled slave.size and forwards it to vme_slave_set() without
> comparing it against image[minor].size_buf. The slave-image kernel
> buffer is allocated at probe time with a fixed size of PCI_BUF_SIZE
> (0x20000 / 128 KiB), but the configured VME window size can be made
> much larger via the ioctl.
>
> The subsequent read() / write() handlers (vme_user_read /
> vme_user_write) clamp the I/O range against vme_get_size() (the
> configured window size, attacker-controlled) but never consult
> size_buf. The slave I/O paths buffer_to_user() and buffer_from_user()
> then index image[minor].kern_buf with *ppos values up to
> image_size - 1, well beyond the actual allocation.
>
> Result: a local user with read/write access to /dev/bus/vme/s* can
> trigger out-of-bounds read and write of the kernel slab adjacent to
> the slave-image buffer.
>
> Fix: reject slave.size > size_buf in the VME_SET_SLAVE handler. Also
> add defensive bounds checks against size_buf in buffer_to_user() and
> buffer_from_user() so that the I/O paths cannot exceed the
> allocation even if a future ioctl path forgets to validate.
>
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-4-7
> Signed-off-by: Rion Kiguchi <kiguchi.r.sec@gmail.com>
> ---
> drivers/staging/vme_user/vme_user.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c
> index 11e25c2f6..41b8d5b51 100644
> --- a/drivers/staging/vme_user/vme_user.c
> +++ b/drivers/staging/vme_user/vme_user.c
> @@ -156,6 +156,11 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
> {
> void *image_ptr;
>
> + if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
> + count > image[minor].size_buf - (u64)*ppos) {
> + pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
> + return -EINVAL;
> + }
Why doesn't the check in vme_user_read() already catch this? You are
duplicating much of the same logic again, are you _SURE_ the
LLM-generated report here is actually correct?
And don't spam the kernel log for when a user sends invalid data, that
would just be a mess. But if you do want to, use the proper device
information, not just a static function name, which is very generic and
impossible to determine what went wrong (i.e. use the correct logging
functions like dev_err() and the like).
And you need an extra blank line after the check here, your LLM should
know better :)
> image_ptr = image[minor].kern_buf + *ppos;
> if (copy_to_user(buf, image_ptr, (unsigned long)count))
> return -EFAULT;
> @@ -168,6 +173,11 @@ static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
> {
> void *image_ptr;
>
> + if (*ppos < 0 || (u64)*ppos >= image[minor].size_buf ||
> + count > image[minor].size_buf - (u64)*ppos) {
> + pr_warn_ratelimited("%s: out-of-bounds access\n", __func__);
> + return -EINVAL;
> + }
Same as above.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-09 8:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09 8:02 [PATCH] staging: vme_user: validate slave window size against buffer size Rion Kiguchi
-- strict thread matches above, loose matches on Subject: below --
2026-05-09 7:53 Rion Kiguchi
2026-05-09 8:04 ` Greg KH
2026-05-09 6:58 木口璃音
2026-05-09 7:15 ` gregkh
2026-05-09 7:17 ` gregkh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox