Skip to contentSkip to conversation

ext4: in ext4_seek_{hole,data}, return -ENXIO for negative offsets

PATCH In review Darrick J. Wong 2 participants 2 messages Jul 12, 2017 – Aug 24, 2017 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: in ext4_seek_{hole,data}, return -ENXIO for negative offsets

NOTE: The pending iomap SEEK_HOLE/DATA conversion patch will make all this obsolete; this is a fix more appropriate for pre-4.13 ext4.
---
In the ext4 implementations of SEEK_HOLE and SEEK_DATA, make sure we return -ENXIO for negative offsets instead of banging around inside the extent code and returning -EFSCORRUPTED.

---
 fs/ext4/file.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/file.c +2 -2
index 02ce7e7..923e765 100644
@@ -576,7 +576,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)
 	inode_lock(inode);
 
 	isize = i_size_read(inode);
-	if (offset >= isize) {
+	if (offset < 0 || offset >= isize) {
 		inode_unlock(inode);
 		return -ENXIO;
 	}
@@ -639,7 +639,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)
 	inode_lock(inode);
 
 	isize = i_size_read(inode);
-	if (offset >= isize) {
+	if (offset < 0 || offset >= isize) {
 		inode_unlock(inode);
 		return -ENXIO;
 	}
maintainer
#1 lore raw
Quoted 9 lines · Darrick J. Wong

NOTE: The pending iomap SEEK_HOLE/DATA conversion patch will make all this obsolete; this is a fix more appropriate for pre-4.13 ext4.
---
In the ext4 implementations of SEEK_HOLE and SEEK_DATA, make sure we return -ENXIO for negative offsets instead of banging around inside the extent code and returning -EFSCORRUPTED.

Sorry, I missed this patch earlier. It's not going to make the 4.13 final, but I'll apply it with a "cc: [email protected] # 4.6" tag so it can land in 4.13.x as well as older LTS kernels.

- Ted