linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/fadvise: validate offset in generic_fadvise
@ 2025-12-22 14:18 klourencodev
  2025-12-22 17:52 ` Andrew Morton
  2025-12-23  9:45 ` David Hildenbrand (Red Hat)
  0 siblings, 2 replies; 5+ messages in thread
From: klourencodev @ 2025-12-22 14:18 UTC (permalink / raw)
  To: linux-mm; +Cc: akpm, david, Kevin Lourenco, Kevin Lourenco

From: Kevin Lourenco <klourencodev@gmail.com>

When converted to (u64) for page calculations, a negative offset
can produce extremely large page indices. This may lead to issues in certain advice modes (excessive readahead or
cache invalidation)

offsets are normally non-negative, but the API does not guarantee this. Since 'len' is already
validated, checking 'offset' here is reasonable to prevent potential system instability.

Signed-off-by: Kevin Lourenco <k.lourenco@criteo.com>
---
 mm/fadvise.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/fadvise.c b/mm/fadvise.c
index 67028e30aa91..b63fe21416ff 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -43,7 +43,7 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
 		return -ESPIPE;
 
 	mapping = file->f_mapping;
-	if (!mapping || len < 0)
+	if (!mapping || len < 0 || offset < 0)
 		return -EINVAL;
 
 	bdi = inode_to_bdi(mapping->host);
-- 
2.47.3



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

end of thread, other threads:[~2025-12-23 16:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-22 14:18 [PATCH] mm/fadvise: validate offset in generic_fadvise klourencodev
2025-12-22 17:52 ` Andrew Morton
2025-12-22 23:38   ` Kevin Lourenco
2025-12-23  9:45 ` David Hildenbrand (Red Hat)
2025-12-23 16:16   ` Kevin Lourenco

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