@@ -1065,26 +1065,39 @@ int ocfs2_find_entry(const char *name, int namelen,
1065
1065
{
1066
1066
struct buffer_head * bh ;
1067
1067
struct ocfs2_dir_entry * res_dir = NULL ;
1068
+ int ret = 0 ;
1068
1069
1069
1070
if (ocfs2_dir_indexed (dir ))
1070
1071
return ocfs2_find_entry_dx (name , namelen , dir , lookup );
1071
1072
1073
+ if (unlikely (i_size_read (dir ) <= 0 )) {
1074
+ ret = - EFSCORRUPTED ;
1075
+ mlog_errno (ret );
1076
+ goto out ;
1077
+ }
1072
1078
/*
1073
1079
* The unindexed dir code only uses part of the lookup
1074
1080
* structure, so there's no reason to push it down further
1075
1081
* than this.
1076
1082
*/
1077
- if (OCFS2_I (dir )-> ip_dyn_features & OCFS2_INLINE_DATA_FL )
1083
+ if (OCFS2_I (dir )-> ip_dyn_features & OCFS2_INLINE_DATA_FL ) {
1084
+ if (unlikely (i_size_read (dir ) > dir -> i_sb -> s_blocksize )) {
1085
+ ret = - EFSCORRUPTED ;
1086
+ mlog_errno (ret );
1087
+ goto out ;
1088
+ }
1078
1089
bh = ocfs2_find_entry_id (name , namelen , dir , & res_dir );
1079
- else
1090
+ } else {
1080
1091
bh = ocfs2_find_entry_el (name , namelen , dir , & res_dir );
1092
+ }
1081
1093
1082
1094
if (bh == NULL )
1083
1095
return - ENOENT ;
1084
1096
1085
1097
lookup -> dl_leaf_bh = bh ;
1086
1098
lookup -> dl_entry = res_dir ;
1087
- return 0 ;
1099
+ out :
1100
+ return ret ;
1088
1101
}
1089
1102
1090
1103
/*
@@ -2010,6 +2023,7 @@ int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name,
2010
2023
*
2011
2024
* Return 0 if the name does not exist
2012
2025
* Return -EEXIST if the directory contains the name
2026
+ * Return -EFSCORRUPTED if found corruption
2013
2027
*
2014
2028
* Callers should have i_rwsem + a cluster lock on dir
2015
2029
*/
@@ -2023,9 +2037,12 @@ int ocfs2_check_dir_for_entry(struct inode *dir,
2023
2037
trace_ocfs2_check_dir_for_entry (
2024
2038
(unsigned long long )OCFS2_I (dir )-> ip_blkno , namelen , name );
2025
2039
2026
- if (ocfs2_find_entry (name , namelen , dir , & lookup ) == 0 ) {
2040
+ ret = ocfs2_find_entry (name , namelen , dir , & lookup );
2041
+ if (ret == 0 ) {
2027
2042
ret = - EEXIST ;
2028
2043
mlog_errno (ret );
2044
+ } else if (ret == - ENOENT ) {
2045
+ ret = 0 ;
2029
2046
}
2030
2047
2031
2048
ocfs2_free_dir_lookup_result (& lookup );
0 commit comments