Commit Graph

381 Commits

Author SHA1 Message Date
Fu Hanxi
b47f9850c7 ci: apply common-scripts CI refactor
Squashes these original commits for release/v5.4 backport traceability:
- 9b289dc5ad6 ci: apply idf-ci 1.x
- 381df980d57 ci: remove pip-cache and other unused jobs
- 32375a0a15e ci: apply common-scripts CI refactor
2026-08-17 14:13:15 +02:00
Jiang Jiang Jian
8a5cd6c388 Merge branch 'bugfix/vfs_fat_readdir_stat_cache_v5.4' into 'release/v5.4'
fix(fatfs): move readdir-stat cache to per-DIR stream (v5.4)

See merge request espressif/esp-idf!50906
2026-08-06 11:58:23 +08:00
Tomáš Rohlínek
fc33b0dcde fix(storage/fatfs): fix FAT32 mount integer overflow (CVE-2026-6682)
The initial CVE-2026-6682 fix hardened the exFAT mount path, but the CVE
as reported by runZero is a FAT32 defect in mount_volume() and is
reachable in the default configuration (exFAT and 64-bit LBA disabled).
This corrects the fix.

Root cause: `fasize *= fs->n_fats` is a DWORD multiply with no overflow
guard. A crafted BPB_FATSz32 such as 0x80000001 with NumFATs=2 wraps
`fasize` to 0x00000002. The wrapped (too-small) FAT size places
`fs->database` inside the FAT region, so a forged directory entry yields
an attacker-controlled `finfo.fsize`; a caller using it as a read length
overflows its buffer with attacker-controlled bytes (CVSS 7.6).

Fix: reject per-FAT and reserved+FAT+root system-area sizes that overflow
DWORD before they are used to derive the data-area base. The exFAT
cluster-heap/bitmap 64-bit promotions are retained as defense-in-depth
and relabeled (they are not CVE-2026-6682). SBOM reason updated.
2026-07-22 20:34:55 +08:00
Tomáš Rohlínek
e9d404254b fix(storage/fatfs): record non-applicable runZero 2026 CVEs in SBOM
Document the three runZero "Seven FatFs bugs" CVEs that require no source change
in this component, so vulnerability scanners have their disposition:

  - CVE-2026-6684: GPT partition-scan loop DoS. Already fixed upstream in R0.16,
    where test_gpt_header() caps the partition-entry count at 128.
  - CVE-2026-6686: read of uninitialized clusters after f_lseek() past EOF.
    Longstanding, behavioral; not a memory-safety defect and zero-filling every
    extended cluster is prohibitively costly on flash.
  - CVE-2026-6688: long-filename overflow in downstream callers. Not exposed in
    ESP-IDF; vfs_fat.c uses bounded copies and fname is bounded by FF_MAX_LFN.

Reference: https://www.runzero.com/blog/fatfs-bugs/
2026-07-22 20:34:55 +08:00
Tomáš Rohlínek
1364005a2e fix(storage/fatfs): clamp exFAT volume-label length in f_getlabel() (CVE-2026-6687)
f_getlabel() extracts the exFAT volume label with a loop bounded by the on-disk
byte dj.dir[XDIR_NumLabel] (0-255):

    for (si = di = hs = 0; si < dj.dir[XDIR_NumLabel]; si++)
        wc = ld_16(dj.dir + XDIR_Label + si * 2);

The exFAT label field holds at most 11 UTF-16 units (22 bytes). A crafted
directory entry with a larger count both reads past the 22-byte label field and,
through put_utf(... &label[di], 4), writes past the end of the caller-provided
label buffer (the canonical API examples use small fixed stack buffers) -> stack
buffer overflow.

Clamp the character count to the exFAT maximum of 11 before the extraction loop.
Record the CVE in the component SBOM.

Note: f_getlabel() takes no destination-buffer size, so under UTF-8 output
(FF_LFN_UNICODE == 2) 11 units can still expand to up to 34 bytes; the clamp
downgrades this from attacker-unbounded to spec-bounded. ESP-IDF's VFS layer
does not call f_getlabel(); direct callers on untrusted media should size their
buffer accordingly. A complete fix requires an upstream size-aware API change.

Reference: https://www.runzero.com/blog/fatfs-bugs/
2026-07-22 20:34:55 +08:00
Tomáš Rohlínek
703cb336b1 fix(storage/fatfs): guard dirty-cache refill against unsigned LBA wrap (CVE-2026-6685)
After a direct multi-sector disk_read()/disk_write(), FatFs decides whether the
cached sector overlaps the direct-I/O range with:

    fp->sect - sect < cc          (and the FF_FS_TINY variant fs->winsect - sect < cc)

`sect`, `fp->sect` and `fs->winsect` are unsigned LBA_t. On 32-bit LBA_t builds,
if the cached sector is below `sect`, the subtraction wraps to a huge value that
can still compare `< cc`, so the code computes a bogus large offset:

  - in f_write() it mis-copies from the direct write buffer (data corruption);
  - in f_read() it is worse: memcpy(rbuff + (wrapped_offset * SS), ...) is an
    out-of-bounds WRITE into the caller-supplied read buffer.

Add an explicit lower-bound check (fp->sect >= sect, resp. fs->winsect >= sect)
before the range test on both the read and write paths and both the FF_FS_TINY
and normal variants, so the condition is exactly "cached sector lies within
[sect, sect + cc)". Record the CVE in the component SBOM.

Reference: https://www.runzero.com/blog/fatfs-bugs/
2026-07-22 20:34:55 +08:00
Tomáš Rohlínek
df3df94c58 fix(storage/fatfs): reject empty exFAT cluster heap (CVE-2026-6683)
CVE-2026-6683 is an exFAT divide-by-zero: with NumClusters == 0 the filesystem
object has fs->n_fatent == 2, and the exFAT "percent in use" update in sync_fs()
computes ... * 100 / (fs->n_fatent - 2) -> division by zero.

That vulnerable exFAT PercInUse sync path was introduced in FatFs R0.16 and is
NOT present in this R0.15 release, so the divide-by-zero itself is not reachable
here. As defense-in-depth (and to keep parity with newer releases) reject an
empty exFAT cluster heap at mount time, which is a malformed volume regardless.

Record the CVE disposition in the component SBOM.

Reference: https://www.runzero.com/blog/fatfs-bugs/
2026-07-22 20:34:55 +08:00
Tomáš Rohlínek
b5c012dc19 fix(storage/fatfs): fix exFAT mount integer overflow (CVE-2026-6682)
The exFAT mount path validates that the media is large enough to hold the
declared cluster heap with:

    if (maxlba < (QWORD)fs->database + ncl * fs->csize) ...

`ncl` (DWORD, up to MAX_EXFAT) and `fs->csize` (WORD) are both promoted to
`unsigned int`, so `ncl * fs->csize` is evaluated in 32-bit arithmetic and can
wrap before the QWORD promotion of the sum. A crafted image with a large
NumClusters/SecPerClus can therefore make an undersized volume pass the "size
is large enough" check; subsequent cluster->sector math then addresses media
outside the actual device.

Promote the multiply to 64-bit ((QWORD)ncl * fs->csize). Apply the same
promotion to the bitmap-base computation ((LBA_t)fs->csize * (bcl - 2)), which
has the identical overflow shape. Record the CVE in the component SBOM.

Reference: https://www.runzero.com/blog/fatfs-bugs/
2026-07-22 20:34:55 +08:00
sonika.rathi
f1a8475ad8 fix(fatfs): move readdir-stat cache to per-DIR stream
Move cached_fileinfo and dir_path from vfs_fat_ctx_t to vfs_fat_dir_t so
each open DIR* has its own readdir→stat cache.
2026-07-17 19:10:54 +02:00
sonika.rathi
a2146843ce fix(storage): mark storage pytest apps flaky in CI 2026-05-21 19:54:07 +02:00
sonika.rathi
b59dbdf548 fix(fatfs): fix readdir/stat path buffer sizing in test 2026-05-05 12:17:02 +02:00
Evgeny Torbin
f7395255da test: format all test scripts 2026-03-11 07:34:34 +01:00
Martin Vychodil
ae6c5ee7a0 Merge branch 'fix/fatfs_test_apps_remove_esp32c3_from_sdcard_sdmode_test_v5.4' into 'release/v5.4'
fix(fatfs): fatfs test_apps remove esp32c3 from sdcard_sdmode test (v5.4)

See merge request espressif/esp-idf!45498
2026-02-05 22:35:15 +08:00
Adam Múdry
e0e2348ee9 fix: wl_fatfsgen.py conform to lower Python version 2026-01-28 14:07:41 +01:00
Adam Múdry
1ec2776034 fix(fatfs): Calculate max_pos in wl_fatfsgen.py safe mode correctly 2026-01-28 14:07:41 +01:00
Adam Múdry
a5801fa24b fix(fatfs): fatfs test_apps remove esp32c3 from sdcard_sdmode test 2026-01-28 13:51:01 +01:00
Tomáš Rohlínek
3303fe626c fix(storage/fatfs): Correct mounting procedure 2025-06-11 22:23:36 +02:00
Martin Vychodil
e9a6f2064a fix(storage/fatfs): Fix static function names (no s_ prefix for internal functions) 2025-06-11 12:43:04 +02:00
Martin Vychodil
08323709bb fix(storage/fatfs): Fix usage of rootdir parameter in FatFS mounting API (WL version)
Deployment of the root directory count parameter was wrong
for FAT12/16 formatting (WL version).
This fix resolves the issue and allows application of any number of rootdir entries
within appropriate limits.
2025-06-11 12:43:03 +02:00
Martin Vychodil
cf2d528574 feat(storage/fatfs): Add de-facto limits check for Root directory items count (FAT12/FAT16) 2025-06-11 12:24:51 +02:00
Martin Vychodil
e2a26ac6e5 fix(storage/fatfs): Fix generating of FatFS image with WL SAFE mode (wl_fatfsgen.py)
FatFS image with Wear-Levelling in SAFE MODE was missing 2 extra sectors necessary
for the WL SAFE operations.
2025-06-11 12:24:51 +02:00
Martin Vychodil
ef719bea1d fix(storage/fatfs): Fix rootdir entry count handling in fatfsgen.py script (FAT12/FAT16)
FatFS generator script now uses de-facto limits for Root directory items count
when generating FAT12 or FAT16 image.
Also, Root directory is not required to occupy whole sector
(number of items can be anything from the range from 1 to given limit).
2025-06-11 12:14:15 +02:00
Jiang Jiang Jian
aa1db69a13 Merge branch 'feat/remove_const_from_voltopart_v5.4' into 'release/v5.4'
feat(fatfs/diskio): Remove const from PARTITION VolToPart (v5.4)

See merge request espressif/esp-idf!38782
2025-05-09 17:55:57 +08:00
Adam Múdry
f7054acf46 feat(fatfs/diskio): Remove const from PARTITION VolToPart
Closes https://github.com/espressif/esp-idf/issues/14148
2025-04-28 01:21:48 +02:00
wuzhenghui
33aca83c63 change(ci): remove esp32c5 from readme since esp32c5 skipped CI build 2025-04-25 17:13:27 +08:00
Adam Múdry
338dab5358 fix(fatfs): Mistake in Kconfig for FATFS_USE_DYN_BUFFERS 2025-04-10 10:53:19 +02:00
Adam Múdry
d4c9da31e2 feat(fatfs): Add Kconfig options to set FF_FS_NOFSINFO value
Closes https://github.com/espressif/esp-idf/issues/15241
2025-02-21 21:35:06 +08:00
Ivan Grokhotkov
80d4c75b89 feat(fatfs): add support for a few fcntl commands 2024-12-04 11:22:02 +01:00
Tomáš Rohlínek
09d222c38d feat(storage/fatfs): move fatfs to new VFS API 2024-11-28 13:56:31 +01:00
wanckl
8a467ffd9a feat(driver_sdspi): c61 sdspi support 2024-10-24 13:54:08 +08:00
sonika.rathi
459f2517a8 feat(fatfs): enable partition handling for sectors less than 128 2024-10-08 13:35:08 +02:00
Alexey Lapshin
4c87af6359 fix(build): fix calloc warnings 2024-09-08 13:53:52 +07:00
Adam Múdry
a1f493b50f fix(vfs): FATFS mount immediately after format if mount failed 2024-07-23 15:44:40 +02:00
wanlei
3cf069c7d8 feat(esp32c61): disable unsupported build test 2024-07-16 16:06:19 +08:00
Denis Feklushkin
2976a5450a fix(fatfs): _FFCONF_DEFINED added to ffconf.h 2024-06-16 16:13:26 +03:00
sonika.rathi
8e3e642db4 fix(fatfs): fix memory overlapping issue in vfs_fat.c 2024-05-22 13:06:59 +02:00
Tomas Rohlinek
f375125e28 Merge branch 'feature/fatfs_ff_strfunc_support' into 'master'
feat(storage/fatfs): add Kconfig settings for FF_USE_STRFUNC

Closes IDFGH-12317

See merge request espressif/esp-idf!30141
2024-05-16 14:20:23 +08:00
sonika.rathi
a1e06ebab0 fix(vfs): fix coverity issue copy of overlapping memory in vfs_fat.c 2024-05-06 13:57:08 +02:00
Adam Múdry
feed6b4afe ci: Increase CONFIG_FATFS_VFS_FSTAT_BLKSIZE size for auto_fsync case 2024-04-23 22:19:23 +02:00
Sonika Rathi
3d813afa01 Merge branch 'bugfix/fatfs_optimize_stat_func' into 'master'
fix(fatfs): Optimizes vfs_fat_stat function to get stat structure after readdir

See merge request espressif/esp-idf!28609
2024-04-23 17:24:03 +08:00
Sonika Rathi
e17da6f9f9 fix(fatfs): Optimizes vfs_fat_stat function to get stat structure after readdir
Closes https://github.com/espressif/esp-idf/issues/10220
2024-04-22 09:07:15 +02:00
Tomáš Rohlínek
ede737763c feat(storage/fatfs): update deprecated syntax for tests 2024-04-17 10:37:31 +02:00
Tomáš Rohlínek
b5d78549a5 feat(storage/fatfs): add tests for dynamic buffers 2024-04-17 10:37:31 +02:00
Tomáš Rohlínek
1447420a91 feat(storage/fatfs): add Kconfig option to enable dynamic window buffers 2024-04-17 10:37:31 +02:00
Tomáš Rohlínek
0bd6330e91 feat(storage/fatfs): add dynamic buffers support to FatFS
Closes https://github.com/espressif/esp-idf/issues/10913
2024-04-17 10:37:28 +02:00
Jiang Jiang Jian
a75bacf781 Merge branch 'fix/wl_fatfs_format' into 'master'
fix(storage/fatfs): fix double mouting of spiflash

Closes IDF-9677

See merge request espressif/esp-idf!30162
2024-04-17 10:48:39 +08:00
Jakob Hasse
bf2bbbde16 ci: Added missing generic tag to psram tests 2024-04-16 09:17:41 +02:00
Tomáš Rohlínek
161604c33c fix(storage/fatfs): change indentation in kconfig 2024-04-16 07:55:46 +02:00
Tomáš Rohlínek
615a9c6742 feat(storage/example): enable host test for flash wl fatfs 2024-04-12 10:26:25 +02:00
Tomáš Rohlínek
7c3b9bde0e feat(storage/fatfs): add testcase with erased spi partition 2024-04-12 10:26:25 +02:00