Commit Graph
431 Commits
Author SHA1 Message Date
Martin Vychodil c734860ba1 Merge branch 'feature/fatfs_bdl_v6.0' into 'release/v6.0'
feat(fatfs): Add BDL support to FatFS component (v6.0)

See merge request espressif/esp-idf!52557
2026-09-10 16:10:00 +08:00
Martin Vychodil e0c1910bb0 Merge branch 'fix/fatfs-vfs-fcntl-setfl_v6.0_2' into 'release/v6.0'
fix(fatfs): preserve access mode in VFS F_SETFL (v6.0)

See merge request espressif/esp-idf!51922
2026-09-10 16:07:28 +08:00
sonika.rathi 00e6b37985 fix(fatfs): avoid stack overflow in BDL diskio partition test
(cherry picked from commit 1d08a22a14)
2026-09-10 08:36:18 +02:00
LiPeng 841c3a4de7 fix(fatfs): fix a memory leak bug when FF_USE_DYN_BUFFER was enabled
BDL diskio test part only; the rest of the commit is already on release/v6.0
via 4f7b1af0f9, which predates components/fatfs/test_apps/bdl.

(cherry picked from commit a8b5b8d582)
2026-09-10 08:36:12 +02:00
Martin VychodilandCursor 0a3ee6d019 feat(fatfs): Added BDL support to FatFS component
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 09:39:11 +02:00
Fu Hanxi ddb9fd017c ci: apply idf-ci 1.x 2026-09-03 20:24:50 +02:00
Martin Vychodil 62041d5fc6 Merge branch 'fix/sdmmc_dma_aligned_buffer_leak_v6.0' into 'release/v6.0'
fix(sdmmc): release aligned buffer on card deinit (v6.0)

See merge request espressif/esp-idf!52258
2026-09-03 23:35:18 +08:00
Jiang Jiang Jian d153041ffe Merge branch 'contrib/github_pr_18960_v6.0' into 'release/v6.0'
Fix default value type of FATFS_PRINT_LLI and FATFS_PRINT_FLOAT (GitHub PR) (v6.0)

See merge request espressif/esp-idf!51907
2026-09-03 19:53:44 +08:00
Adam Múdry 233fa3f948 fix(sdmmc): release aligned DMA buffer on card deinit 2026-08-31 14:14:22 +02:00
Martin VychodilandCursor 5fc9a1ea04 fix(fatfs): preserve access mode in VFS F_SETFL
F_SETFL was replacing the whole flags word, so fcntl(fd, F_SETFL, O_APPEND)
made F_GETFL report O_RDONLY|O_APPEND. Keep O_ACCMODE and apply only POSIX
status flags.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 15:51:42 +02:00
mutatrum 381d456f7e Fix default value type of FATFS_PRINT_LLI and FATFS_PRINT_FLOAT 2026-08-20 10:03:49 +02:00
Adam Múdry 109cd54902 feat(esp_partition): Add esp_partition_flash_binary() CMake function
Add a new CMake function esp_partition_flash_binary() that provides a
unified API for registering partition data binaries to be flashed. It
replaces the direct esptool_py_flash_target calls scattered across
components (spiffs, fatfs, nvs_flash) with a single function that:

- Resolves partition offset from the partition table automatically
- Determines encryption requirements (auto-detect or ALWAYS_PLAINTEXT)
- Creates per-partition flash targets (e.g. idf.py <partition>-flash)
- Optionally includes the binary in `idf.py flash` via FLASH_IN_PROJECT

On the linux target, the function registers binaries for pre-loading
into the emulated flash. A build-time manifest (linux_flash_data.txt)
is generated via file(GENERATE), and partition_linux.c reads it at
runtime to copy each binary into the memory-mapped flash buffer at
the correct offset.

The partition_ops example is updated to use the new function and
includes a custom_partition with pre-built data to demonstrate the
full workflow, including on the linux target.
2026-08-06 14:35:47 +02:00
sonika.rathi 473dd30a96 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 12:09:26 +02:00
Tomáš Rohlínek d4fdaae0dd 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-07 16:36:32 +02:00
Tomáš Rohlínek 5b3090c3e2 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-06 16:19:09 +02:00
Tomáš Rohlínek da6afc4eee 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-06 14:49:08 +02:00
Tomáš Rohlínek 5019c06dd4 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-06 14:49:08 +02:00
Tomáš Rohlínek a407d4f82b 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-06 14:49:08 +02:00
Tomáš Rohlínek 9466a3d529 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-06 14:49:08 +02:00
Martin Vychodil 6e17e8cc9b Merge branch 'bugfix/idfci-8839-remove-orphan-test-configs_v6.0' into 'release/v6.0'
fix(fatfs): re-enable fatfs and vfs psram/ccomp CI tests (v6.0)

See merge request espressif/esp-idf!50185
2026-07-01 16:38:14 +08:00
Martin Vychodil 484cc4f068 Merge branch 'fix/fatfs_instance_init_v6.0' into 'release/v6.0'
Fix: various FATFS/VFS fixes (v6.0)

See merge request espressif/esp-idf!50101
2026-06-30 18:07:13 +08:00
sonika.rathi 8393e608eb fix(fatfs): re-enable fatfs and vfs psram/ccomp CI tests 2026-06-30 09:10:15 +02:00
Jiang Jiang Jian d82a2d4af2 Merge branch 'fix/vfs_fatfs_unregister_path_possible_leak_v6.0' into 'release/v6.0'
Fix esp_vfs_fat_unregister_path possible leak, incorrect check in esp_vfs_register_fs_common and optimize memory usage (v6.0)

See merge request espressif/esp-idf!49638
2026-06-29 15:40:19 +08:00
Martin VychodilandCursor 872ca1fa3c fix(fatfs): Fixed VFS adapter early return paths
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 14:59:28 +02:00
Martin VychodilandCursor 9702ed5257 fix(fatfs): Fixed uninitialized FATFS pointer for already mounted path
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 14:59:23 +02:00
Adam Múdry 318d312607 fix(fatfs): Fix esp_vfs_fat_unregister_path leak if esp_vfs_unregister fails 2026-06-19 14:15:45 +02:00
sonika.rathi 4f8408dca1 fix(storage): mark storage pytest apps flaky in CI 2026-05-21 15:41:09 +02:00
Martin Vychodil c5e8334592 Merge branch 'bugfix/fatfs_memory_leak_with_dyn_buffer_v6.0' into 'release/v6.0'
fix(fatfs): fix a memory leak bug when FF_USE_DYN_BUFFER was enabled (v6.0)

See merge request espressif/esp-idf!47876
2026-05-10 21:37:02 +08:00
Martin Vychodil 7860bb6027 Merge branch 'fix/fatfsgen-sfn-ascii-numeric-tail_v6.0' into 'release/v6.0'
fix(fatfs): fix SFN generation from LFN (numeric tail ASCII encoding, switching to CRC hex numbers to mirror FATFS logic, etc.) (v6.0)

See merge request espressif/esp-idf!47543
2026-05-07 18:34:49 +08:00
sonika.rathi 2257f83940 fix(fatfs): fix readdir/stat path buffer sizing in test 2026-05-05 12:16:18 +02:00
LiPeng 4f7b1af0f9 fix(fatfs): fix a memory leak bug when FF_USE_DYN_BUFFER was enabled 2026-04-24 18:59:28 +08:00
Adam Múdry 123470a4e3 fix(fatfs): fix operator precedence bug in BootSector.__str__ for Python 3.14 compatibility
The condition filtering attributes lacked parentheses, causing the
'not startswith(_)' guard to only apply to str attributes. Python 3.14's
new __firstlineno__ (int) class attribute leaked into the output.

Also includes ruff auto-formatting fixes (imports, trailing commas,
union type annotations).
2026-04-13 16:08:47 +02:00
Adam Múdry 033405abb6 fix(fatfs): fix formatting in relevant python files to satisfy pre-commit check 2026-04-13 15:59:49 +02:00
Adam Múdry abea28451f fix(fatfs): fix a bug in SFN generation from LFN and rewrite to match C algorithm
Rewrite build_lfn_short_entry_name() and add _gen_numname_suffix() helper
to match the gen_numname() algorithm in ff.c. This fixes:

- chr(order) producing raw binary instead of ASCII digits
- Collision for order >= 10 when str(order) makes the name exceed 8 chars
- Hex suffix with dynamic stem shortening (matching C implementation)
- CRC16-CCITT hash for seq > 5 to reduce collision probability

Also fix LDIR_Name2_SIZE typo in long_filename_utils.py (should be
LDIR_Name3_SIZE), which made the assertion guard too permissive.

Add ShortFilenameGenerationTestCase with 9 unit tests covering single-digit,
multi-digit, hash-based, and collision-free generation scenarios.
2026-04-13 15:59:48 +02:00
Marius Vikhammer e741963f13 Merge branch 'ci/common-components-release-v6.0' into 'release/v6.0'
ci: update build-test-rules to use common_components (v6.0)

See merge request espressif/esp-idf!45547
2026-03-23 09:31:28 +08:00
Jiang Jiang Jian 2aaad17dc7 Merge branch 'fix/f_getfree_crash_issue_v6.0' into 'release/v6.0'
fix(fatfs): fix f_getfree crash when volume not mounted or mount failed (v6.0)

See merge request espressif/esp-idf!46716
2026-03-20 16:38:21 +08:00
igor.udot e2a8bbe639 ci: update build-test-rules to use common_components 2026-03-20 15:53:26 +08:00
Jiang Jiang Jian b556757c94 Merge branch 'refactor/fatfs_vfs_change_esp_vfs_fat_register_prototype_v6.0' into 'release/v6.0'
refactor(fatfs): Update esp_vfs_fat_register function prototype (v6.0)

See merge request espressif/esp-idf!45980
2026-03-20 10:55:02 +08:00
Jiang Jiang Jian 8c07347e74 Merge branch 'fix/fatfs_test_apps_remove_esp32c3_from_sdcard_sdmode_test_v6.0' into 'release/v6.0'
fix(fatfs): fatfs test_apps remove esp32c3 from sdcard_sdmode test (v6.0)

See merge request espressif/esp-idf!45497
2026-03-20 10:22:22 +08:00
sonika.rathi 4da0547962 fix(fatfs): remove incorrect retval description from void ff_mutex_delete 2026-03-17 18:44:11 +01:00
sonika.rathi 0a062a1912 fix(fatfs): fix f_getfree crash when volume not mounted or mount failed 2026-03-17 18:44:11 +01:00
Evgeny Torbin 0070b687b5 ci: remove unused test cases 2026-03-12 12:34:23 +01:00
Adam Múdry 785a018380 fix: Update examples etc. to use esp_vfs_fat_register
Instead of deprecated esp_vfs_fat_register_cfg
2026-02-20 13:12:44 +01:00
Adam Múdry 092a5ba5a5 refactor(fatfs): Update esp_vfs_fat_register function prototype
to match esp_vfs_fat_register_cfg
2026-02-20 13:07:09 +01:00
Adam Múdry 45b15bcd21 fix(fatfs): fatfs test_apps remove esp32c3 from sdcard_sdmode test 2026-01-28 13:43:45 +01:00
Adam Múdry 5e66a7f051 fix(fatfs): Calculate max_pos in wl_fatfsgen.py safe mode correctly 2026-01-23 12:55:41 +01:00
Adam Múdry e5598cd050 fix: Satisfy Python formatter 2026-01-23 12:55:41 +01:00
Tomáš Rohlínek 1bf8b030e3 feat(storage/vfs): Remove old API usage 2025-12-17 14:00:22 +01:00
Tomáš Rohlínek f6ba0d8aa0 feat(storage/fatfs): Update default configuration to better fit average usecase 2025-10-15 09:30:02 +02:00
Chen Chen a4710cc206 refactor(driver): remove redundant driver dependencies
now the driver component only contains legacy code for i2c, twai and
touch sensor
2025-09-30 15:47:45 +08:00