[PATCH 3.16 157/366] udf: Detect incorrect directory size

2018-11-11 Thread Ben Hutchings
3.16.61-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Jan Kara 

commit fa65653e575fbd958bdf5fb9c4a71a324e39510d upstream.

Detect when a directory entry is (possibly partially) beyond directory
size and return EIO in that case since it means the filesystem is
corrupted. Otherwise directory operations can further corrupt the
directory and possibly also oops the kernel.

CC: Anatoly Trosinenko 
Reported-and-tested-by: Anatoly Trosinenko 
Signed-off-by: Jan Kara 
Signed-off-by: Ben Hutchings 
---
 fs/udf/directory.c | 3 +++
 1 file changed, 3 insertions(+)

--- a/fs/udf/directory.c
+++ b/fs/udf/directory.c
@@ -151,6 +151,9 @@ struct fileIdentDesc *udf_fileident_read
   sizeof(struct fileIdentDesc));
}
}
+   /* Got last entry outside of dir size - fs is corrupted! */
+   if (*nf_pos > dir->i_size)
+   return NULL;
return fi;
 }
 



[PATCH 3.16 157/366] udf: Detect incorrect directory size

2018-11-11 Thread Ben Hutchings
3.16.61-rc1 review patch.  If anyone has any objections, please let me know.

--

From: Jan Kara 

commit fa65653e575fbd958bdf5fb9c4a71a324e39510d upstream.

Detect when a directory entry is (possibly partially) beyond directory
size and return EIO in that case since it means the filesystem is
corrupted. Otherwise directory operations can further corrupt the
directory and possibly also oops the kernel.

CC: Anatoly Trosinenko 
Reported-and-tested-by: Anatoly Trosinenko 
Signed-off-by: Jan Kara 
Signed-off-by: Ben Hutchings 
---
 fs/udf/directory.c | 3 +++
 1 file changed, 3 insertions(+)

--- a/fs/udf/directory.c
+++ b/fs/udf/directory.c
@@ -151,6 +151,9 @@ struct fileIdentDesc *udf_fileident_read
   sizeof(struct fileIdentDesc));
}
}
+   /* Got last entry outside of dir size - fs is corrupted! */
+   if (*nf_pos > dir->i_size)
+   return NULL;
return fi;
 }