Bug 280347

Summary: truncate(2) test program corrupts msdos file system
Product: Base System Reporter: Peter Holm <pho>
Component: kernAssignee: Stefan Eßer <se>
Status: Closed FIXED    
Severity: Affects Only Me CC: kib, markj, mckusick, se
Priority: ---    
Version: 15.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Reproducer shell script none

Description Peter Holm freebsd_committer freebsd_triage 2024-07-18 11:40:44 UTC
Created attachment 252141 [details]
Reproducer shell script

root@mercat1:/usr/src/tools/test/stress2/misc # ./tr8.sh
/mnt: Freeing unused sector 65535 31 0
/dev/md10: remounting read-only due to corruption
/mnt: Freeing unused sector 65535 31 0
truncate8: read: Input/output error
remounted /dev/md10 read-only
truncate8: ftruncate: Bad file descriptor
MSDOS exit status is 2
root@mercat1:/usr/src/tools/test/stress2/misc # uname -a
FreeBSD mercat1.netperf.freebsd.org 15.0-CURRENT FreeBSD 15.0-CURRENT #0 main-n271237-a4469a0d19b64-dirty: Thu Jul 18 09:55:05 CEST 2024     pho@mercat1.netperf.freebsd.org:/usr/src/sys/amd64/compile/PHO amd64
root@mercat1:/usr/src/tools/test/stress2/misc #
Comment 1 Stefan Eßer freebsd_committer freebsd_triage 2024-08-09 17:24:41 UTC
The test fails on the particular MSDOS file system parameters used due to an incorrectly applied cluster number limit for FAT-16 when mounting the file system.
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-08-09 17:33:58 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=45d4e82bf61f91792142a2b9e2af657dab8500fd

commit 45d4e82bf61f91792142a2b9e2af657dab8500fd
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2024-08-09 17:26:27 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2024-08-09 17:26:27 +0000

    msdosfs: fix cluster limit when mounting FAT-16 file systems

    The maximum cluster number was calculated based on the number of data
    cluters that fit in the givem partition size and the size of the FAT
    area. This limit did not take into account that the highest 10 cluster
    numbers are reserved and must not be used for files.

    PR:             280347
    MFC after:      3 days
    Reported by:    pho@FreeBSD.org

 sys/fs/msdosfs/msdosfs_vfsops.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 3 Peter Holm freebsd_committer freebsd_triage 2024-08-12 20:08:29 UTC
The commit fixes the problem seen.
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-08-15 19:06:44 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e8f52a86ee279a1270e31bc5bad436939e44f555

commit e8f52a86ee279a1270e31bc5bad436939e44f555
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2024-08-09 17:26:27 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2024-08-15 19:05:50 +0000

    msdosfs: fix cluster limit when mounting FAT-16 file systems

    The maximum cluster number was calculated based on the number of data
    cluters that fit in the givem partition size and the size of the FAT
    area. This limit did not take into account that the highest 10 cluster
    numbers are reserved and must not be used for files.

    PR:             280347
    Reported by:    pho@FreeBSD.org

    (cherry picked from commit 45d4e82bf61f91792142a2b9e2af657dab8500fd)

 sys/fs/msdosfs/msdosfs_vfsops.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-08-15 19:06:45 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8774fa749d4e6d2726c0ed662a36657782ad0cec

commit 8774fa749d4e6d2726c0ed662a36657782ad0cec
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2024-08-09 17:26:27 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2024-08-15 19:05:08 +0000

    msdosfs: fix cluster limit when mounting FAT-16 file systems

    The maximum cluster number was calculated based on the number of data
    cluters that fit in the givem partition size and the size of the FAT
    area. This limit did not take into account that the highest 10 cluster
    numbers are reserved and must not be used for files.

    PR:             280347
    Reported by:    pho@FreeBSD.org

    (cherry picked from commit 45d4e82bf61f91792142a2b9e2af657dab8500fd)

 sys/fs/msdosfs/msdosfs_vfsops.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-08-15 21:48:03 UTC
A commit in branch releng/13.4 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d5c1fa0ec09e34040c9c9941c27e38b583c60d86

commit d5c1fa0ec09e34040c9c9941c27e38b583c60d86
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2024-08-09 17:26:27 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2024-08-15 21:46:57 +0000

    msdosfs: fix cluster limit when mounting FAT-16 file systems

    The maximum cluster number was calculated based on the number of data
    cluters that fit in the givem partition size and the size of the FAT
    area. This limit did not take into account that the highest 10 cluster
    numbers are reserved and must not be used for files.

    Approved by:    re
    PR:             280347
    Reported by:    pho@FreeBSD.org

    (cherry picked from commit 45d4e82bf61f91792142a2b9e2af657dab8500fd)
    (cherry picked from commit e8f52a86ee279a1270e31bc5bad436939e44f555)

 sys/fs/msdosfs/msdosfs_vfsops.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Comment 7 Kirk McKusick freebsd_committer freebsd_triage 2024-09-09 22:01:05 UTC
Changes have been committed and MFC'ed.