Re: [PATCH] jffs2: keep alloc_sem held when a write retry cannot reserve space

From: Shuai Liu

Date: Mon Nov 16 2026 - 01:40:37 EST


Hi,

I independently verified this fix with the syzbot C reproducer on top
of Linux 7.4-rc3 (master), using mtdram with 128 KiB total size /
4 KiB erase size, CONFIG_JFFS2_SUMMARY=y and CONFIG_PROVE_LOCKING=y,
closely matching the syzbot configuration. The patch applies cleanly
to this tree.

Baseline (before the patch):

- The fail-nth scan in the reproducer triggers the lockdep warning
at N=10:

WARNING: bad unlock balance detected!
repro/67 is trying to release lock (&c->alloc_sem) at:
jffs2_do_create+0x229/0x250 fs/jffs2/write.c:474
but there are no more locks to release!

- The call chain matches the syzbot report: jffs2_sum_add_kvec()
fails with -ENOMEM, jffs2_write_dnode() drops alloc_sem for the
retry reservation which then fails with -ENOSPC, and
jffs2_do_create() calls jffs2_complete_reservation() on a lock it
no longer holds.

With the patch applied:

- 2 runs x 2000 fail-nth rounds, zero lockdep reports.
- The failure path is still reached: in one run the injected
allocation failure landed in jffs2_sum_add_kvec() ("Write of 68
bytes at 0x0001e00c failed. returned -12, retlen 0"), creat()
still returns -ENOSPC as expected, and the second unlock is now
balanced.

Tested-by: Shuai Liu <847807867@xxxxxx>

AI assistance disclosure: the two-state test environment (kernel
config, QEMU setup and log analysis) was prepared with the help of an
AI coding assistant, per Documentation/process/coding-assistants.rst.
The conclusions above are from actual test runs.

Best regards,
Shuai Liu