Support clang builds; fix the defects clang and its sanitizers exposed
build / build (clang, ) (push) Failing after 7s
build / build (clang, --enable-warnings) (push) Failing after 5s
build / build (gcc, ) (push) Failing after 5s
build / build (gcc, --enable-io-failure-emulation) (push) Failing after 5s
build / build (gcc, --enable-warnings) (push) Failing after 6s
build / out-of-tree (push) Failing after 6s
build / sanitizers (push) Failing after 5s

Clang (22.1.8 on the host, 14.0.6 in the Debian VM) now builds the tree
warning-free with --enable-warnings, in-tree and out-of-tree, with -j, and
the full VM battery passes with CC=clang: 12/12. ASan/UBSan builds run the
real tool paths (mkfs, check, tune, resize, rollback save/restore/reject)
with halt_on_error and report zero errors. Documented in tests/vm/RESULTS.md;
the CI gained clang+warnings, out-of-tree and sanitizer jobs.

Fixes found by this work:

- reiserfscore/Makefile.am: reiserfs_err.c and reiserfs_err.h shared one
  recipe. With -j, make runs the recipe once per stale target, so two
  compile_et invocations race: one deletes reiserfs_err.c ("no input
  files") while another job compiles it. Attached the recipe to
  reiserfs_err.c only; reiserfs_err.h merely depends on it. Reproduced
  with clang+ASan, stable across 5 clang / 3 asan / 3 gcc parallel builds.

- reiserfscore/Makefile.am: the rule read the source-local
  reiserfs_err.et, so VPATH builds could not find it. Use $(srcdir)/.
  make distcheck now passes.

- reiserfscore/reiserfslib.c: reiserfs_close() did fsync(fs->fs_dev) after
  reiserfs_free() released fs -- a 4-byte heap-use-after-free, flagged
  exactly at reiserfslib.c:406/407 by ASan (found by clang+ASan; gcc never
  caught it because the freed heap usually still holds the old value).
  Moved fsync before the free; reiserfs_flush() has already written
  journal and dirty buffers at that point and free_buffers() never
  writes, so the ordering preserves durability semantics.

- fsck/semantic_check.c, fsck/semantic_rebuild.c: three %K arguments passed
  &tmp_deh->deh2_dir_id where a struct reiserfs_key * is expected. It
  printed the right values only because deh2_dir_id sits at offset 4 and
  the key is read from the pointer as if dir_id sat at offset 0. Build a
  proper local key with set_key_dirid()/set_key_objectid() (the same
  idiom debugreiserfs/scan.c already uses). Verified -Waddress-of-packed-
  member (clang-only) is gone and output is unchanged.

- reiserfscore/hashes.c: four unreachable *(int *)0 = 0 stores (guarded by
  len >= 16/12/8/4 tests that cannot hold after the while (len >= 16)
  loop, len <= 15). Removed; clang's -Wnull-dereference goes quiet.
  Behavior verified: keyed_hash/yura_hash/r5_hash outputs for 16 inputs
  from 0 to 17 bytes are byte-identical before and after.

run_in_vm.sh: propagate CC into the guest, force a remount of /mnt/data
(the host rewrites the backing file under the guest), exclude generated
reiserfs_err.[ch] from the source tar. run_tests.sh: report which compiler
the battery actually used.
This commit is contained in:
lgcosta committed 2026-11-12 08:51:29 -03:00
1 parent 5a7382185b
commit 7b5421ce49
11 files changed
+287 -35

No files matched your search

+9 -3
View File
@@ -3,9 +3,15 @@ lib_LTLIBRARIES = libreiserfscore.la
reiserfsdir = $(includedir)/reiserfs
reiserfs_HEADERS = reiserfs_err.h
reiserfs_err.c reiserfs_err.h: reiserfs_err.et
$(RM) -f reisefs_err.c reiserfs_err.h
compile_et reiserfs_err.et
# compile_et writes reiserfs_err.c AND reiserfs_err.h in one pass. Keep the
# recipe on a single target: when one recipe is shared by two targets, parallel
# make can run it concurrently for both, and one run deletes the .c while
# another job is still compiling it ("no input files"). reiserfs_err.h only
# depends on reiserfs_err.c, so the recipe always runs exactly once.
reiserfs_err.c: $(srcdir)/reiserfs_err.et
$(RM) -f reiserfs_err.c reiserfs_err.h
compile_et $(srcdir)/reiserfs_err.et
reiserfs_err.h: reiserfs_err.c
BUILT_SOURCES = reiserfs_err.h reiserfs_err.c
+3 -9
View File
@@ -83,10 +83,9 @@ u32 keyed_hash(const signed char *msg, int len)
msg += 16;
}
/* len <= 15 here: the while loop above consumed every full 16-byte
block, so the "len >= 16" test that used to sit here was dead. */
if (len >= 12) {
if (len >= 16)
*(int *)0 = 0;
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
b = (u32) msg[4] |
@@ -101,8 +100,6 @@ u32 keyed_hash(const signed char *msg, int len)
d |= msg[i];
}
} else if (len >= 8) {
if (len >= 12)
*(int *)0 = 0;
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
b = (u32) msg[4] |
@@ -114,8 +111,6 @@ u32 keyed_hash(const signed char *msg, int len)
c |= msg[i];
}
} else if (len >= 4) {
if (len >= 8)
*(int *)0 = 0;
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
@@ -125,8 +120,7 @@ u32 keyed_hash(const signed char *msg, int len)
b |= msg[i];
}
} else {
if (len >= 4)
*(int *)0 = 0;
/* len <= 3 here. */
a = b = c = d = pad;
for (i = 0; i < len; i++) {
a <<= 8;
+6 -1
View File
@@ -403,8 +403,13 @@ void reiserfs_close(reiserfs_filsys_t fs)
reiserfs_close_ondisk_bitmap(fs);
reiserfs_flush(fs);
reiserfs_free(fs);
/* fsync must run while fs is still valid: reiserfs_free() releases
the handler, and reading fs->fs_dev after it was a use-after-free.
reiserfs_flush() has already written the journal and every dirty
buffer (free_buffers() inside reiserfs_free only validates and
frees), so the data is on the device by this point. */
fsync(fs->fs_dev);
reiserfs_free(fs);
}
int reiserfs_new_blocknrs(reiserfs_filsys_t fs,