Commit Graph
93 Commits
Author SHA1 Message Date
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
Tomáš Rohlínek a43526d303 fix(storage/vfs): Fix typo in code snippet in docs 2026-03-17 18:37:35 +01:00
Tomáš Rohlínek c277b9da28 fix(storage/vfs): Remove va_end leak in ioctl caused by early return in macro 2026-01-29 12:42:03 +01:00
Tomáš Rohlínek 3303fe626c fix(storage/fatfs): Correct mounting procedure 2025-06-11 22:23:36 +02:00
Tomáš Rohlínek 0a9105a406 feat(network/lwip): Add checks for maximum socket count 2025-05-26 19:23:31 +08:00
Tomáš Rohlínek 8e0239f04b fix(storage/console): fix test configuration 2025-03-12 20:06:31 +08:00
Tomáš Rohlínek c6d24bddf7 fix(storage/vfs_console): stop new console opens from overwriting existing fds 2025-03-12 20:06:31 +08:00
Tomáš Rohlínek 653fa4a1f5 fix(storage/vfs): incorrect log level in esp_vfs_register_fd_range
Closes https://github.com/espressif/esp-idf/issues/14327
2025-02-07 15:24:08 +08:00
Tomáš Rohlínek a92d5e9358 fix(storage/fatfsgen): broken test_apps scripts for fatfsgen 2025-01-17 18:31:50 +01:00
Tomáš Rohlínek d6d4de0907 feat(storage/vfs): make all member pointer of vfs_ops struct const 2024-12-12 13:49:46 +01:00
Tomáš Rohlínek def8b9b639 feat(storage/vfs): move semihost to new vfs API 2024-11-28 13:56:34 +01:00
Tomáš Rohlínek 7fe45180db feat(storage/vfs): move l2tap to new vfs API 2024-11-28 13:56:34 +01:00
Tomáš Rohlínek 0cd2e72dc1 feat(storage/esp_vfs_console): move console to new vfs API 2024-11-28 13:56:33 +01:00
Tomáš Rohlínek 4ff53bc9c7 feat(storage/vfs): move jtag driver to new vfs API 2024-11-28 13:56:33 +01:00
Tomáš Rohlínek 0aa10dcb43 feat(storage/vfs): move uart driver to new vfs API 2024-11-28 13:56:33 +01:00
Tomáš Rohlínek 906b3df54b feat(storage/vfs): move nullfs to new API 2024-11-28 13:56:32 +01:00
Tomáš Rohlínek 39197864a1 feat(storage/vfs): make part of nullfs API private 2024-11-28 13:56:32 +01:00
Tomáš Rohlínek bb305bd109 feat(storage/esp_vfs_console): move cdcacm driver to new vfs API 2024-11-28 13:56:32 +01:00
Tomáš Rohlínek e5ab487e3c feat(storage/vfs): update docs to new version of API 2024-11-28 13:56:31 +01:00
Tomáš Rohlínek 6b07039281 feat(storage/spiffs): move spiffs to new VFS API 2024-11-28 13:56:31 +01:00
Tomáš Rohlínek 09d222c38d feat(storage/fatfs): move fatfs to new VFS API 2024-11-28 13:56:31 +01:00
Tomáš Rohlínek ced490fc6e feat(storage/vfs): make subcomponent pointers const 2024-11-28 13:56:26 +01:00
Tomáš Rohlínek 18e20c0bc5 feat(storage/vfs): change names related to minified vfs 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek 040ad5ca20 feat(storage/vfs): add test for ESP_VFS_FLAG_STATIC 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek 3cab84f033 fix(storage/vfs): clarify minified related documentation 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek 923fb635b4 feat(storage/vfs): add documentation for minified_vfs 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek 3cfc78ee67 feat(storage/vfs): update documentation for minified vfs functions 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek 755adf3b4f feat(storage/vfs): impelement sparse vfs struct 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek cec0525460 fix(storage/vfs): update select sanity checks 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek fe0fc40049 fix(storage/vfs): incorrect registration checks 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek 36d821f70c feat(storage/vfs): add more extensive checks to vfs tests 2024-10-22 14:50:31 +08:00
Tomáš Rohlínek b6a9acfc07 feat(storage/vfs): Add minified vfs implementation 2024-10-22 14:50:31 +08:00
Tomas Rohlinek fe51222a02 Merge branch 'feat/simplify_storage_examples' into 'master'
feat(storage/fatfs): update fatfs examples

Closes IDF-5705

See merge request espressif/esp-idf!31174
2024-10-18 15:28:44 +08:00
Tomáš Rohlínek 5841495e7f fix(storage/fatfs): fix CMake project names in fatfs examples 2024-10-17 09:21:33 +02:00
Tomas Rohlinek ee6742d764 Merge branch 'fix/incorrect_test_case_spiffs_linux' into 'master'
fix(storage/spiffs): fix incorrect test case configuration

Closes IDFCI-2179

See merge request espressif/esp-idf!33323
2024-10-10 19:50:11 +08:00
Tomáš Rohlínek bcc060b98e docs(storage/fatfs): fix relative links in fatfs examples 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek 908c4c7ce6 docs(storage/fatfs): fix fatfs example links in docs 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek 46982e69da feat(storage/vfs): update example references in documentation 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek d43669b2d7 feat(storage/fatfs): restructure fatfsgen example 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek 33788de979 feat(storage/fatfs): restructure ext_flash example 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek 587290567d feat(storage/fatfs): restructure advanced example 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek 85b5869053 feat(storage/fatfs): restructure basic example 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek f633839ece feat(storage/fatfs): add advanced example for fatfs 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek b9a54fb1f3 feat(storage/fatfs): add minimal FatFS example 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek 84ba1a323c fix(storage/fatfs): move test app to correct directory 2024-10-10 16:41:58 +08:00
Tomáš Rohlínek bab9498a52 docs(storage/vfs): add documentation for existing automounted vfs drivers 2024-09-20 11:49:47 +02:00
Tomáš Rohlínek 1f0763b932 fix(storage/example): correct alloc function 2024-09-09 07:54:42 +02:00
Tomáš Rohlínek 4a185b824d fix(storage/vfs): fix incorrect test case configuration 2024-09-04 12:11:43 +02:00
Tomas Rohlinek 2806ef1e5c Merge branch 'fix/missing_include_guard_ff_conf' into 'master'
fix(fatfs): Add missing include guard to ff_conf.h

Closes IDFGH-13046

See merge request espressif/esp-idf!31769
2024-07-11 13:34:42 +08:00
Tomas Rohlinek 2ccc9bcef9 Merge branch 'fix/unopened_stdout_console' into 'master'
fix(newlib/stdio): incorrect stdout redirect with /dev/console

Closes IDFGH-12416

See merge request espressif/esp-idf!30324
2024-05-29 18:40:09 +08:00
Tomáš Rohlínek c44da2f222 feat(storage/spiffs): add host test for disabled erase check 2024-05-29 11:00:25 +02:00
Tomáš Rohlínek 97af825b14 feat(storage/vfs): make automatic nullfs initialization optional 2024-05-29 10:39:55 +02:00
Tomáš Rohlínek f2a278191b feat(storage/vfs): add documentation for nullfs 2024-05-29 10:39:55 +02:00
Tomáš Rohlínek f753434640 fix(storage/esp_partition): add option to control erase check during write for linux target 2024-05-28 10:05:58 +02:00
Tomáš Rohlínek a30d27e01e feat(storage/vfs): add nullfs test cases for vfs 2024-05-28 08:06:33 +02:00
Tomáš Rohlínek 2b75ed37b9 fix(storage/vfs): always register /dev/null on startup 2024-05-28 07:55:37 +02:00
Tomáš Rohlínek a615f487dd feat(storage/vfs): add /dev/null for unwanted output redirection 2024-05-28 07:54:35 +02:00
Tomáš Rohlínek 0b4fff69c5 fix(newlib/stdio): remove incorrect check in /dev/console init
Closes https://github.com/espressif/esp-idf/issues/13439
2024-05-27 10:43:13 +02:00
Tomáš Rohlínek 0ed8ebddb6 fix(storage/vfs_console): remove possible infinite recursion 2024-05-27 14:11:49 +08: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
Tomas Rohlinek 22d3473f18 Merge branch 'feature/fatfs_use_dynamic_buffer' into 'master'
feat(storage/fatfs): Use dynamic buffers for fatfs

Closes IDFGH-9561

See merge request espressif/esp-idf!27501
2024-04-19 13:15:38 +08: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
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
Tomáš Rohlínek f398b7923a fix(storage/fatfs): fix double mouting of spiflash 2024-04-12 10:26:22 +02:00
Tomas Rohlinek f5d49570ee Merge branch 'feature/optimize_fatfs_on_sdmmc' into 'master'
feat(examples/storage): update perf benchmark example

Closes IDF-8420

See merge request espressif/esp-idf!27678
2024-04-09 15:02:06 +08:00
Tomas Rohlinek 0c9937570f feat(examples/storage): update perf benchmark example 2024-04-09 15:02:05 +08:00
Tomáš Rohlínek a17ef2f8d8 feat(storage/fatfs): move fatfs related scripts under control of the storage team 2024-03-19 13:36:40 +01:00
Tomas Rohlinek f8054b1e66 Merge branch 'fix/wl_fatfsgen_safe_mode' into 'master'
fix(storage/fatfs): make wl_fatfsgen.py safe mode aware

Closes IDF-9379

See merge request espressif/esp-idf!29621
2024-03-19 16:19:24 +08:00
Tomáš Rohlínek 7854b955a1 fix(storage/fatfs): make wl_fatfsgen.py safe mode aware 2024-03-13 12:49:49 +01:00
Tomáš Rohlínek 1297a0628a fix(storage/fatfs): check whether sdcard supports triming
Closes https://github.com/espressif/esp-idf/issues/12912
2024-01-05 10:31:56 +01:00
Tomáš Rohlínek 092f5aff29 feat(storage): Update build test rules for storage related components 2024-01-02 13:10:59 +01:00
Tomas Rohlinek 88cc473910 Merge branch 'docs/fatfs_link_lock' into 'master'
Docs(storage/fatfs): Add documentation for FATFS_LINK_LOCK Kconfig option

Closes IDF-8739

See merge request espressif/esp-idf!27472
2023-12-19 18:37:52 +08:00
Tomáš Rohlínek 577af7d6ef docs(storage/fatfs): Refactor FatFs documentation 2023-12-19 08:11:05 +01:00
Tomáš Rohlínek eea16b18db docs(storage/fatfs): Document the new fatfs_link_lock Kconfig option 2023-12-19 08:11:02 +01:00
Tomáš Rohlínek c276c36dfe feat(storage/nvs_flash): add dependencies to nvs_flash test apps 2023-12-11 13:10:54 +01:00
Tomáš Rohlínek 526ce4f5cc feat(storage/fatfs): add sbom file for FatFs 2023-11-28 09:36:40 +01:00
Tomas Rohlinek 38ee8c6373 Merge branch 'fix/fatfs_locking' into 'master'
fix(storage/fatfs): add missing locks in fatfs wrapper for vfs

Closes IDF-8282

See merge request espressif/esp-idf!26747
2023-11-27 19:21:21 +08:00
Tomáš Rohlínek 91e158aa0c fix(storage/fatfs): add missing locks in fatfs wrapper for vfs 2023-11-27 07:47:28 +01:00
Tomáš Rohlínek 559fb2d2bf feat(storage): minimize platforms for tests 2023-11-06 07:41:36 +01:00
Tomáš Rohlínek 3f4698ac47 fix(storage/fatfs): add missing lock release introduced by IMMEDIATE_FSYNC 2023-10-30 10:22:08 +01:00
Tomáš Rohlínek 8f3abfb60e feat(storage): add dependencies for tests 2023-10-27 10:07:40 +02:00
Tomáš Rohlínek 53f4f19cc1 feat(storage): update config for app tests 2023-10-27 10:07:31 +02:00
Tomáš Rohlínek 525776f748 feat(vfs/fatfs): Add option for automatic immediate fsync 2023-10-02 07:06:05 +02:00