Skip to content

blktrace: fix three bugs in merge_blktrace_iologs path - #2099

Merged
axboe merged 1 commit into
axboe:masterfrom
wangxp006:master
Jun 2, 2026
Merged

axboe merged 1 commit into
axboe:masterfrom
wangxp006:master

Conversation

@wangxp006

Copy link
Copy Markdown
Contributor
  1. fread pointer: pass the trace buffer pointer (t) instead of pointer to the pointer (&t), and use sizeof(*t) for the struct size instead of the pointer size. This caused "iolog short read" and made the merge path dead code.
  2. stdio buffer use-after-free: fclose the merged file before freeing the custom stdio buffer set up via setvbuf. Previously free(merge_buf) was called while merge_fp still referenced it.
  3. double free on merge success: read_iolog_file and merge_blktrace_file are both FIO_OPT_STR_STORE char pointers. Assigning one to the other made them point to the same memory, causing a double free when options_free frees both. Fix by transferring ownership and NULLing merge_blktrace_file.

Reproduction:
./fio --name=merge --merge-blktrace-only --merge_blktrace_file=/tmp/result.log --merge_blktrace_scalars=100 --merge_blktrace_iters=1 --read_iolog=/data_disk6/randy/tmp/bt1.blktrace.220

Before fix: "iolog short read" error (Bug 1 makes merge dead code).
After Bug 1 only: "double free or corruption (fasttop)" crash during
put_job -> options_free, caused by Bugs 2 and 3 unmasked by Bug 1
fix.

@sitsofe

sitsofe commented May 29, 2026

Copy link
Copy Markdown
Collaborator

@wangxp006 would you be able to include a real name in front of your email address with the commit author/signed off by?

@lukasstraub2 these changes look required to me after your commit 5ab088a - do you agree?

@lukasstraub2

Copy link
Copy Markdown
Contributor

Yes, looks good to me from a quick look.

1. fread pointer: pass the trace buffer pointer (t) instead of pointer
   to the pointer (&t), and use sizeof(*t) for the struct size instead
   of the pointer size. This caused "iolog short read" and made the
   merge path dead code.
2. stdio buffer use-after-free: fclose the merged file before freeing
   the custom stdio buffer set up via setvbuf. Previously
   free(merge_buf) was called while merge_fp still referenced it.
3. double free on merge success: read_iolog_file and
   merge_blktrace_file are both FIO_OPT_STR_STORE char pointers.
   Assigning one to the other made them point to the same memory,
   causing a double free when options_free frees both. Fix by
   transferring ownership and NULLing merge_blktrace_file.

Reproduction:
  ./fio       --name=merge       --merge-blktrace-only       --merge_blktrace_file=/tmp/result.log       --merge_blktrace_scalars=100       --merge_blktrace_iters=1       --read_iolog=/data_disk6/randy/tmp/bt1.blktrace.220

  Before fix: "iolog short read" error (Bug 1 makes merge dead code).
  After Bug 1 only: "double free or corruption (fasttop)" crash during
  put_job -> options_free, caused by Bugs 2 and 3 unmasked by Bug 1
  fix.

Signed-off-by: xiaopeng.wang <wangxp006@163.com>
@wangxp006

Copy link
Copy Markdown
Contributor Author

@wangxp006 would you be able to include a real name in front of your email address with the commit author/signed off by?

@lukasstraub2 these changes look required to me after your commit 5ab088a - do you agree?

I have already added the real name in front of the email address for the “Signed-off-by” line.

@sitsofe

sitsofe commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

@vincentkfu this looks good to me.

@axboe
axboe merged commit 5b476c9 into axboe:master Jun 2, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

⌂ 换网址