Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zdb_il: use flex array member to access ZIL records #16832

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

robn
Copy link
Member

@robn robn commented Dec 3, 2024

Motivation and Context

Working on something else, I had cause to compile with optimisations disabled, and the build broke.

$ ./configure ... CFLAGS='-g -O0' CXXFLAGS='-g -O0'
...
$ make
...
cmd/zdb/zdb_il.c: In function ‘zil_prt_rec_create’:
cmd/zdb/zdb_il.c:82:31: error: ‘strlen’ reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread]
   82 |                 link = name + strlen(name) + 1;
      |                               ^~~~~~~~~~~~
In file included from cmd/zdb/zdb_il.c:43:
./include/sys/zil.h:271:25: note: at offset 104 into source object ‘lr_create’ of size 104
  271 |         _lr_create_t    lr_create;      /* common create portion */
      |                         ^~~~~~~~~
./include/sys/zil.h:271:25: note: at offset [168, 17179869452] into source object ‘lr_create’ of size 104
cmd/zdb/zdb_il.c: In function ‘zil_prt_rec_rename’:
cmd/zdb/zdb_il.c:128:27: error: ‘strlen’ reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread]
  128 |         char *tnm = snm + strlen(snm) + 1;
      |                           ^~~~~~~~~~~
./include/sys/zil.h:333:25: note: at offset 48 into source object ‘lr_rename’ of size 48
  333 |         _lr_rename_t    lr_rename;      /* common rename portion */
      |                         ^~~~~~~~~
...

I suppose in an optimised build, these things are gone long before anything can see them and complain them.

Description

In 6f50f8e we added flex arrays to lr_XX_t structs to silence kernel bounds check warnings. Userspace code was mostly not updated to use them though.

This commit switches the handful of complaints over to use the flex arrays, and all is well again.

How Has This Been Tested?

Compiled with and without optimisations, and with/without ASAN. No complaints from anyone.

Ran the slog test suite, a major user of zdb -i. All passed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

In 6f50f8e we added flex arrays to lr_XX_t structs to silence kernel
bounds check warnings. Userspace code was mostly not updated to use them
though.

It seems that in the right circumstances, compilers can get confused
about sizes in the same way, and throw warnings. This commits switch
those uses over to use the flex array fields also.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <[email protected]>
cmd/zdb/zdb_il.c Show resolved Hide resolved
@amotin amotin added the Status: Code Review Needed Ready for review and testing label Dec 3, 2024
@amotin amotin added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Dec 4, 2024
@amotin amotin merged commit 2507db6 into openzfs:master Dec 5, 2024
24 checks passed
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Dec 5, 2024
In 6f50f8e we added flex arrays to lr_XX_t structs to silence kernel
bounds check warnings. Userspace code was mostly not updated to use them
though.

It seems that in the right circumstances, compilers can get confused
about sizes in the same way, and throw warnings. This commits switch
those uses over to use the flex array fields also.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Sponsored-by: https://despairlabs.com/sponsor/
Closes openzfs#16832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants