Skip to content

fs/pseudofile: fix buffer sizing and sparse growth - #19704

Merged
linguini1 merged 1 commit into
apache:masterfrom
YWHKKX:pseudofile-buffer-sizing
Aug 7, 2026
Merged

fs/pseudofile: fix buffer sizing and sparse growth#19704
linguini1 merged 1 commit into
apache:masterfrom
YWHKKX:pseudofile-buffer-sizing

Conversation

@YWHKKX

@YWHKKX YWHKKX commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix incorrect in-memory buffer sizing when a pseudofile is extended.
  • Grow the allocation by doubling instead of shift-based round-up.
  • Clear newly addressed bytes on growth; truncate growth uses the same expand path.

Impact

  • New/changed feature? NO (bug fix only).
  • Impact on user / API? NO.
  • Impact on build / hardware / documentation? NO.
  • Impact on compatibility? NO.

Testing

I confirm that changes are verified on local setup and work as intended:

  • Build Host: WSL2 Ubuntu 24.04 (x86_64), gcc 13 + gcc-multilib
  • Target: arch=sim (32-bit) + KASAN, CONFIG_PSEUDOFS_FILE=y
  • Repro: open a pseudofile, seek far ahead, then write

Before

open: OK
lseek: OK
write: Segmentation fault (rc=139)

After

open: OK
lseek: OK
write returned -1 errno=12

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation.
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

@YWHKKX
YWHKKX requested a review from Donny9 as a code owner August 6, 2026 03:21
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
Comment thread fs/vfs/fs_pseudofile.c Outdated
@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

hifive1-revb

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @YWHKKX :-)

Please:

@jerpelea jerpelea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please sign the patch
git commit -s

@YWHKKX
YWHKKX force-pushed the pseudofile-buffer-sizing branch from dc39783 to da33256 Compare August 6, 2026 08:56
Grow the in-memory pseudofile buffer by doubling instead of
1<<LOG2_CEIL, which can under-allocate on 32-bit targets for large
expand sizes. Also:
* reject size_t wrap before expand on write (-EFBIG)
* clear newly addressed bytes when the file grows
* route truncate growth through the same expand path

Impact: CONFIG_PSEUDOFS_FILE expand/write/truncate only; no API or
build-system change.

Testing: host arithmetic PoC blocked; WSL sim:pseudofile-poc
(SIM_M32+KASAN) write returns -ENOMEM instead of SIGSEGV in memcpy.

Signed-off-by: ywhkkx <2076064543@qq.com>
@YWHKKX
YWHKKX force-pushed the pseudofile-buffer-sizing branch from 419043c to c52c411 Compare August 6, 2026 09:43
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@YWHKKX please squash your change into one patch.

@YWHKKX

YWHKKX commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 already squashed to c52c411

@linguini1 linguini1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of the updated expand/write/truncate paths on current master.

Please provide some more testing detail. Did you perform any runtime tests?

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @YWHKKX :-) Before and after runtime tests are welcome as @linguini1 noted :-)

@YWHKKX

YWHKKX commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @linguini1 @cederom :-)

Yes — runtime tested on WSL2 with sim (32-bit) + KASAN, CONFIG_PSEUDOFS_FILE=y.

Before: write after a large seek crashes (SIGSEGV, rc=139).
After (this PR): write fails safely with -ENOMEM (errno=12); no crash.

@linguini1

Copy link
Copy Markdown
Contributor

Can you please give a concrete test setup or runtime logs?

@YWHKKX

YWHKKX commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @linguini1.

Concrete test setup

  • Host: WSL2, Ubuntu 24.04, x86_64
  • Toolchain: gcc 13 + gcc-multilib
  • Repos: nuttx + nuttx-apps (side by side)
  • Configure:
    ./tools/configure.sh -a ../nuttx-apps sim:
    (local sim defconfig enables at least:
    CONFIG_SIM_M32=y,
    CONFIG_MM_KASAN=y,
    CONFIG_MM_KASAN_INSTRUMENT_ALL=y,
    CONFIG_PSEUDOFS_FILE=y,
    and a small init-time test app)
  • Build/run:
    $ make -j$(nproc)
    $ ./nuttx

The init-time test opens a pseudofile, seeks to a large offset,
then writes a small buffer.

Runtime logs

Before this PR:
open: OK
lseek: OK
write: Segmentation fault
exit status: 139

After this PR:
open: OK
lseek: OK
write returned -1 errno=12
(-ENOMEM, no crash)

@acassis

acassis commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@linguini1 PTAL, here already replied

@linguini1
linguini1 merged commit 1ceda8c into apache:master Aug 7, 2026
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants