public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: most: video: fix read() length underflow
@ 2026-03-05  1:57 Alexandru Hossu
  2026-03-05  6:30 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Hossu @ 2026-03-05  1:57 UTC (permalink / raw)
  To: parthiban.veerasooran
  Cc: christian.gromm, gregkh, linux-staging, linux-kernel,
	Alexandru Hossu

Avoid unsigned underflow when fh->offs exceeds mbo->processed_length.
Use size_t for length calculations and clamp invalid offsets.

Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>
---
 drivers/staging/most/video/video.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
index 04351f8ccccf..8c4800be875e 100644
--- a/drivers/staging/most/video/video.c
+++ b/drivers/staging/most/video/video.c
@@ -158,7 +158,7 @@ static ssize_t comp_vdev_read(struct file *filp, char __user *buf,
 {
 	struct comp_fh *fh = to_comp_fh(filp);
 	struct most_video_dev *mdev = fh->mdev;
-	int ret = 0;
+	ssize_t ret = 0;
 
 	if (*pos)
 		return -ESPIPE;
@@ -177,8 +177,19 @@ static ssize_t comp_vdev_read(struct file *filp, char __user *buf,
 
 	while (count > 0 && data_ready(mdev)) {
 		struct mbo *const mbo = get_top_mbo(mdev);
-		int const rem = mbo->processed_length - fh->offs;
-		int const cnt = rem < count ? rem : count;
+		size_t rem, cnt;
+
+		if (fh->offs >= mbo->processed_length) {
+			fh->offs = 0;
+			spin_lock_irq(&mdev->list_lock);
+			list_del(&mbo->list);
+			spin_unlock_irq(&mdev->list_lock);
+			most_put_mbo(mbo);
+			continue;
+		}
+
+		rem = mbo->processed_length - fh->offs;
+		cnt = min_t(size_t, rem, count);
 
 		if (copy_to_user(buf, mbo->virt_address + fh->offs, cnt)) {
 			v4l2_err(&mdev->v4l2_dev, "read: copy_to_user failed\n");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-05 10:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05  1:57 [PATCH] staging: most: video: fix read() length underflow Alexandru Hossu
2026-03-05  6:30 ` Dan Carpenter
2026-03-05 10:16   ` Alexandru Hossu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox