Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exfat: fix unexpected EOF while reading dir

If the position is not aligned with the dentry size, the return
value of readdir() will be NULL and errno is 0, which means the
end of the directory stream is reached.

If the position is aligned with dentry size, but there is no file
or directory at the position, exfat_readdir() will continue to
get dentry from the next dentry. So the dentry gotten by readdir()
may not be at the position.

After this commit, if the position is not aligned with the dentry
size, round the position up to the dentry size and continue to get
the dentry.

Fixes: ca06197382bd ("exfat: add directory operations")
Cc: stable@vger.kernel.org # v5.7+
Reported-by: Wang Yugui <wangyugui@e16-tech.com>
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

authored by

Yuezhang Mo and committed by
Namjae Jeon
6cb5d1a1 c9c3395d

+1 -4
+1 -4
fs/exfat/dir.c
··· 234 234 fake_offset = 1; 235 235 } 236 236 237 - if (cpos & (DENTRY_SIZE - 1)) { 238 - err = -ENOENT; 239 - goto unlock; 240 - } 237 + cpos = round_up(cpos, DENTRY_SIZE); 241 238 242 239 /* name buffer should be allocated before use */ 243 240 err = exfat_alloc_namebuf(nb);