Bug 243179 - fsck_msdosfs: Off-by-two in determination of FAT type
Summary: fsck_msdosfs: Off-by-two in determination of FAT type
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Xin LI
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-08 08:51 UTC by Xin LI
Modified: 2020-01-28 07:50 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xin LI freebsd_committer freebsd_triage 2020-01-08 08:51:31 UTC
The FAT type determination in fsck_msdosfs is wrong.

In the code we used NumClusters as the upper (non-inclusive) boundary of valid cluster number, so the actual value was 2 (CLUST_FIRST) more than the real number of clusters.

Therefore, it's not right to use NumClusters as it is today to determine FAT type.
Comment 1 Xin LI freebsd_committer freebsd_triage 2020-01-08 08:56:32 UTC
Proposed fix: https://reviews.freebsd.org/D23082
Comment 2 commit-hook freebsd_committer freebsd_triage 2020-01-11 17:42:20 UTC
A commit references this bug:

Author: delphij
Date: Sat Jan 11 17:41:20 UTC 2020
New revision: 356636
URL: https://svnweb.freebsd.org/changeset/base/356636

Log:
  Correct off-by-two issue when determining FAT type.

  In the code we used NumClusters as the upper (non-inclusive) boundary
  of valid cluster number, so the actual value was 2 (CLUST_FIRST) more
  than the real number of clusters. This causes a FAT16 media with
  65524 clusters be treated as FAT32 and might affect FAT12 media with
  4084 clusters as well.

  To fix this, we increment NumClusters by CLUST_FIRST after the type
  determination.

  PR:		243179
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D23082

Changes:
  head/sbin/fsck_msdosfs/boot.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2020-01-28 07:50:18 UTC
A commit references this bug:

Author: delphij
Date: Tue Jan 28 07:49:52 UTC 2020
New revision: 357196
URL: https://svnweb.freebsd.org/changeset/base/357196

Log:
  MFC r356629, r356636

  r356629:
  Apply typo fix from NetBSD, we have already applied all NetBSD changes so
  update the NetBSD tag while I'm there.

  r356636:
  Correct off-by-two issue when determining FAT type.

  In the code we used NumClusters as the upper (non-inclusive) boundary
  of valid cluster number, so the actual value was 2 (CLUST_FIRST) more
  than the real number of clusters. This causes a FAT16 media with
  65524 clusters be treated as FAT32 and might affect FAT12 media with
  4084 clusters as well.

  To fix this, we increment NumClusters by CLUST_FIRST after the type
  determination.

  PR:		243179

Changes:
_U  stable/12/
  stable/12/sbin/fsck_msdosfs/boot.c