Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs/fat/fs_fat32util.c: fix potential exception due to dividing zero during mounting when fat is corrupted #15167

Merged

Conversation

Windrow14
Copy link
Contributor

Summary

Some bytes in boot sector might be corrupted for some reason. When this happens, the Nuttx system will crash due to dividing zero. It is better to return a mounting error, instead of crashing the system.

nsh> mount -t vfat /dev/mmcsd1 /mnt
nsh> dd if=/dev/mmcsd1 of=/mnt/file bs=32 count=1
32bytes copied, 0 usec, 4294967295 KB/s
nsh> hexdump /mnt/file
/mnt/file at 00000000:
0000: eb 58 90 4e 55 54 54 58 20 20 20 00 02 20 20 00 .X.NUTTX   ..  .
0010: 02 00 00 00 00 f8 00 00 3f 00 ff 00 00 00 00 00 ........?.......
nsh> dd if=/dev/mmcsd1 of=/dev/mmcsd1 bs=1 count=1 skip=11 seek=13
1bytes copied, 0 usec, 4294967295 KB/s
nsh> dd if=/dev/mmcsd1 of=/mnt/file bs=32 count=1
32bytes copied, 0 usec, 4294967295 KB/s
nsh> hexdump /mnt/file
/mnt/file at 00000000:
0000: eb 58 90 4e 55 54 54 58 20 20 20 00 02 00 20 00 .X.NUTTX   ... .
0010: 02 00 00 00 00 f8 00 00 3f 00 ff 00 00 00 00 00 ........?.......
nsh> umount /mnt
nsh> mount -t vfat /dev/mmcsd1 /mnt
[CPU0] xtensa_user_panic: User Exception: EXCCAUSE=0006 task: nsh_main
[CPU0] _assert: Current Version: NuttX  12.4.0 fc53a57fe5 Dec 11 2024 17:10:38 xtensa
[CPU0] _assert: Assertion failed user panic: at file: common/xtensa_assert.c:187 task(CPU0): nsh_main process: nsh_main 0x42011554

Impact

A check of fs_fatsecperclus' value when read from device driver is added. Return an error if it is zero.
When "sector per cluster" byte is corrupted to zero, mounting the FAT will end up in failure instead of system exception.

Testing

(reboot)
nsh> mount -t vfat /dev/mmcsd1 /mnt
nsh: mount: mount failed: 22

…uring mounting when fat is corrupted

Check fs_fatsecperclus' value when read from eMMC device. Return an error if it is zero.

Signed-off-by: Yinzhe Wu <[email protected]>
Reviewed-by: Jacky Cao <[email protected]>
Tested-by: Yinzhe Wu <[email protected]>
@github-actions github-actions bot added Area: File System File System issues Size: XS The size of the change in this PR is very small labels Dec 13, 2024
@Windrow14
Copy link
Contributor Author

@JackyCaoYJ

@xiaoxiang781216 xiaoxiang781216 merged commit 5cdc6c7 into apache:master Dec 13, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: File System File System issues Size: XS The size of the change in this PR is very small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants