Thread (3 messages) 3 messages, 2 authors, 2017-07-13

[PATCH] vfs: in iomap seek_{hole,data}, return -ENXIO for negative offsets

From: Darrick J. Wong <hidden>
Date: 2017-07-12 17:36:54
Also in: linux-fsdevel, linux-xfs
Subsystem: filesystems (vfs and infrastructure), the rest · Maintainers: Alexander Viro, Christian Brauner, Linus Torvalds

In the iomap implementations of SEEK_HOLE and SEEK_DATA, make sure we
return -ENXIO for negative offsets instead of badgering the iomap
provider with garbage requests.

Inspired-by: Mateusz S [off-list ref]
Signed-off-by: Darrick J. Wong <redacted>
---
 fs/iomap.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/iomap.c b/fs/iomap.c
index 432eed8..16f5c074 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -610,8 +610,8 @@ iomap_seek_hole(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
 	loff_t length = size - offset;
 	loff_t ret;
 
-	/* Nothing to be found beyond the end of the file. */
-	if (offset >= size)
+	/* Nothing to be found before or beyond the end of the file. */
+	if (offset < 0 || offset >= size)
 		return -ENXIO;
 
 	while (length > 0) {
@@ -656,8 +656,8 @@ iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops)
 	loff_t length = size - offset;
 	loff_t ret;
 
-	/* Nothing to be found beyond the end of the file. */
-	if (offset >= size)
+	/* Nothing to be found before or beyond the end of the file. */
+	if (offset < 0 || offset >= size)
 		return -ENXIO;
 
 	while (length > 0) {
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help