@@ -34,6 +34,7 @@ static int exfat_get_uniname_from_ext_entry(struct super_block *sb,
34
34
{
35
35
int i , err ;
36
36
struct exfat_entry_set_cache es ;
37
+ unsigned int uni_len = 0 , len ;
37
38
38
39
err = exfat_get_dentry_set (& es , sb , p_dir , entry , ES_ALL_ENTRIES );
39
40
if (err )
@@ -52,7 +53,10 @@ static int exfat_get_uniname_from_ext_entry(struct super_block *sb,
52
53
if (exfat_get_entry_type (ep ) != TYPE_EXTEND )
53
54
break ;
54
55
55
- exfat_extract_uni_name (ep , uniname );
56
+ len = exfat_extract_uni_name (ep , uniname );
57
+ uni_len += len ;
58
+ if (len != EXFAT_FILE_NAME_LEN || uni_len >= MAX_NAME_LENGTH )
59
+ break ;
56
60
uniname += EXFAT_FILE_NAME_LEN ;
57
61
}
58
62
@@ -214,7 +218,10 @@ static void exfat_free_namebuf(struct exfat_dentry_namebuf *nb)
214
218
exfat_init_namebuf (nb );
215
219
}
216
220
217
- /* skip iterating emit_dots when dir is empty */
221
+ /*
222
+ * Before calling dir_emit*(), sbi->s_lock should be released
223
+ * because page fault can occur in dir_emit*().
224
+ */
218
225
#define ITER_POS_FILLED_DOTS (2)
219
226
static int exfat_iterate (struct file * file , struct dir_context * ctx )
220
227
{
@@ -229,11 +236,10 @@ static int exfat_iterate(struct file *file, struct dir_context *ctx)
229
236
int err = 0 , fake_offset = 0 ;
230
237
231
238
exfat_init_namebuf (nb );
232
- mutex_lock (& EXFAT_SB (sb )-> s_lock );
233
239
234
240
cpos = ctx -> pos ;
235
241
if (!dir_emit_dots (file , ctx ))
236
- goto unlock ;
242
+ goto out ;
237
243
238
244
if (ctx -> pos == ITER_POS_FILLED_DOTS ) {
239
245
cpos = 0 ;
@@ -245,16 +251,18 @@ static int exfat_iterate(struct file *file, struct dir_context *ctx)
245
251
/* name buffer should be allocated before use */
246
252
err = exfat_alloc_namebuf (nb );
247
253
if (err )
248
- goto unlock ;
254
+ goto out ;
249
255
get_new :
256
+ mutex_lock (& EXFAT_SB (sb )-> s_lock );
257
+
250
258
if (ei -> flags == ALLOC_NO_FAT_CHAIN && cpos >= i_size_read (inode ))
251
259
goto end_of_dir ;
252
260
253
261
err = exfat_readdir (inode , & cpos , & de );
254
262
if (err ) {
255
263
/*
256
- * At least we tried to read a sector. Move cpos to next sector
257
- * position (should be aligned).
264
+ * At least we tried to read a sector.
265
+ * Move cpos to next sector position (should be aligned).
258
266
*/
259
267
if (err == - EIO ) {
260
268
cpos += 1 << (sb -> s_blocksize_bits );
@@ -277,26 +285,19 @@ static int exfat_iterate(struct file *file, struct dir_context *ctx)
277
285
inum = iunique (sb , EXFAT_ROOT_INO );
278
286
}
279
287
280
- /*
281
- * Before calling dir_emit(), sb_lock should be released.
282
- * Because page fault can occur in dir_emit() when the size
283
- * of buffer given from user is larger than one page size.
284
- */
285
288
mutex_unlock (& EXFAT_SB (sb )-> s_lock );
286
289
if (!dir_emit (ctx , nb -> lfn , strlen (nb -> lfn ), inum ,
287
290
(de .attr & ATTR_SUBDIR ) ? DT_DIR : DT_REG ))
288
- goto out_unlocked ;
289
- mutex_lock (& EXFAT_SB (sb )-> s_lock );
291
+ goto out ;
290
292
ctx -> pos = cpos ;
291
293
goto get_new ;
292
294
293
295
end_of_dir :
294
296
if (!cpos && fake_offset )
295
297
cpos = ITER_POS_FILLED_DOTS ;
296
298
ctx -> pos = cpos ;
297
- unlock :
298
299
mutex_unlock (& EXFAT_SB (sb )-> s_lock );
299
- out_unlocked :
300
+ out :
300
301
/*
301
302
* To improve performance, free namebuf after unlock sb_lock.
302
303
* If namebuf is not allocated, this function do nothing
@@ -1079,7 +1080,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
1079
1080
if (entry_type == TYPE_EXTEND ) {
1080
1081
unsigned short entry_uniname [16 ], unichar ;
1081
1082
1082
- if (step != DIRENT_STEP_NAME ) {
1083
+ if (step != DIRENT_STEP_NAME ||
1084
+ name_len >= MAX_NAME_LENGTH ) {
1083
1085
step = DIRENT_STEP_FILE ;
1084
1086
continue ;
1085
1087
}
0 commit comments