mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: info: Fix maxsize underflow in snd_info_entry_write()
@ 2026-11-04  6:13 songxiebing
  2026-11-04  7:09 ` Takashi Iwai
  2026-11-04  8:46 ` songxiebing
  0 siblings, 2 replies; 3+ messages in thread
From: songxiebing @ 2026-11-04  6:13 UTC (permalink / raw)
  To: tiwai, perex; +Cc: linux-sound, linux-kernel, songxiebing, stable

From: Bob Song <songxiebing@kylinos.cn>

snd_info_entry_write() computes maxsize as entry->size - pos without
first checking whether pos has already reached entry->size.  If a write
is issued with an offset beyond the entry size, the subtraction
underflows and count is left unclamped, so the write callback is called
with an out-of-range offset and the original count.

The read path already handles this case by returning 0 when
pos >= entry->size.  Add the same check to the write path.

Fixes: d97e1b78239c ("ALSA: info - Check file position validity in common layer")
Cc: <stable@vger.kernel.org>
Signed-off-by: Bob Song <songxiebing@kylinos.cn>
---
 sound/core/info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/core/info.c b/sound/core/info.c
index 3b8ccda04e1a..676b06e0d463 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -171,6 +171,8 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
 	pos = *offset;
 	if (!valid_pos(pos, count))
 		return -EIO;
+	if (pos >= entry->size)
+		return 0;
 	if (count > 0) {
 		size_t maxsize = entry->size - pos;
 		count = min(count, maxsize);
-- 
2.25.1


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

end of thread, other threads:[~2026-11-04  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  6:13 [PATCH] ALSA: info: Fix maxsize underflow in snd_info_entry_write() songxiebing
2026-11-04  7:09 ` Takashi Iwai
2026-11-04  8:46 ` songxiebing

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®