From: LiuJunyuan <2058432396@qq.com>
To: gregkh@linuxfoundation.org
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
LiuJunyuan <2058432396@qq.com>
Subject: [PATCH] staging: vme_user: handle zero image size in read/write
Date: Wed, 21 Oct 2026 11:41:38 +0800 [thread overview]
Message-ID: <tencent_FE0C25ACDF20A06CBFD0651E7C4ECD7E5009@qq.com> (raw)
vme_get_size() can return zero for an unallocated image. The existing
image_size - 1 checks underflow in that case and can allow an invalid
position to proceed, wrapping the subsequent count calculation. Check
image_size and *ppos directly instead.
Signed-off-by: LiuJunyuan <2058432396@qq.com>
---
drivers/staging/vme_user/vme_user.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/vme_user/vme_user.c b/drivers/staging/vme_user/vme_user.c
index a472a38ef613..58566c01003a 100644
--- a/drivers/staging/vme_user/vme_user.c
+++ b/drivers/staging/vme_user/vme_user.c
@@ -213,7 +213,7 @@ static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
image_size = vme_get_size(image[minor].resource);
/* Ensure we are starting at a valid location */
- if ((*ppos < 0) || (*ppos > (image_size - 1))) {
+ if (*ppos < 0 || image_size == 0 || *ppos >= image_size) {
mutex_unlock(&image[minor].mutex);
return 0;
}
@@ -255,7 +255,7 @@ static ssize_t vme_user_write(struct file *file, const char __user *buf,
image_size = vme_get_size(image[minor].resource);
/* Ensure we are starting at a valid location */
- if ((*ppos < 0) || (*ppos > (image_size - 1))) {
+ if (*ppos < 0 || image_size == 0 || *ppos >= image_size) {
mutex_unlock(&image[minor].mutex);
return 0;
}
--
2.43.0
next reply other threads:[~2026-10-21 3:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 3:41 LiuJunyuan [this message]
2026-10-21 6:02 ` Dan Carpenter
2026-10-21 6:04 ` Dan Carpenter
2026-10-21 6:16 ` Greg KH
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=tencent_FE0C25ACDF20A06CBFD0651E7C4ECD7E5009@qq.com \
--to=2058432396@qq.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@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
all inboxes | Powered by JetHome®