Skip to content

TestErasureCodeShec_arguments: fix stack-use-after-scope#57435

Closed
Svelar wants to merge 1 commit intoceph:mainfrom
Svelar:asan_shec_arg
Closed

TestErasureCodeShec_arguments: fix stack-use-after-scope#57435
Svelar wants to merge 1 commit intoceph:mainfrom
Svelar:asan_shec_arg

Conversation

@Svelar
Copy link
Member

@Svelar Svelar commented May 13, 2024

When sanitizer is enabled, unittest_erasure_code_shec_arguments shows,

==412235==ERROR: AddressSanitizer: stack-use-after-scope on address 0xffffca8362c0 at pc 0xaaaab4f1d2b8 bp 0xffffca8356d0 sp 0xffffca8356c8
READ of size 4 at 0xffffca8362c0 thread T0
    #0 0xaaaab4f1d2b4 in getint(std::initializer_list<int>) /root/ceph/src/test/erasure-code/TestErasureCodeShec_arguments.cc:46:21
    #1 0xaaaab4f25cac in int std::__invoke_impl<int, int (*&)(std::initializer_list<int>), std::initializer_list<int>&>(std::__invoke_other, int (*&)(std::initializer_list<int>), std::initializer_list<int>&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14
    #2 0xaaaab4f24e90 in std::__invoke_result<int (*&)(std::initializer_list<int>), std::initializer_list<int>&>::type std::__invoke<int (*&)(std::initializer_list<int>), std::initializer_list<int>&>(int (*&)(std::initializer_list<int>), std::initializer_list<int>&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:96:14
    #3 0xaaaab4f248e8 in bool std::ranges::__any_of_fn::operator()<std::initializer_list<int>*, std::initializer_list<int>*, int (*)(std::initializer_list<int>), std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int> >(std::initializer_list<int>*, std::initializer_list<int>*, std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int>, int (*)(std::initializer_list<int>)) const /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/ranges_algo.h:109:30
    #4 0xaaaab4f1d72c in bool std::ranges::__any_of_fn::operator()<std::array<std::initializer_list<int>, 27ul>&, int (*)(std::initializer_list<int>), std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int> >(std::array<std::initializer_list<int>, 27ul>&, std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int>, int (*)(std::initializer_list<int>)) const /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/ranges_algo.h:120:9
    #5 0xaaaab4f0fca8 in create_table_shec432() /root/ceph/src/test/erasure-code/TestErasureCodeShec_arguments.cc:96:15
    #6 0xaaaab4f1b140 in main /root/ceph/src/test/erasure-code/TestErasureCodeShec_arguments.cc:361:3
    #7 0xffff9b9673f8 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #8 0xffff9b9674c8 in __libc_start_main csu/../csu/libc-start.c:392:3
    #9 0xaaaab4e5b8ac in _start (/root/ceph/build/bin/unittest_erasure_code_shec_arguments+0x11b8ac) (BuildId: c1fce44a2cd8b7e33e7f07b2de20b9a2f57c314a)

keep a as initializer_list could fix this error.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

When sanitizer is enabled, unittest_erasure_code_shec_arguments shows,

```
==412235==ERROR: AddressSanitizer: stack-use-after-scope on address 0xffffca8362c0 at pc 0xaaaab4f1d2b8 bp 0xffffca8356d0 sp 0xffffca8356c8
READ of size 4 at 0xffffca8362c0 thread T0
    #0 0xaaaab4f1d2b4 in getint(std::initializer_list<int>) /root/ceph/src/test/erasure-code/TestErasureCodeShec_arguments.cc:46:21
    #1 0xaaaab4f25cac in int std::__invoke_impl<int, int (*&)(std::initializer_list<int>), std::initializer_list<int>&>(std::__invoke_other, int (*&)(std::initializer_list<int>), std::initializer_list<int>&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14
    #2 0xaaaab4f24e90 in std::__invoke_result<int (*&)(std::initializer_list<int>), std::initializer_list<int>&>::type std::__invoke<int (*&)(std::initializer_list<int>), std::initializer_list<int>&>(int (*&)(std::initializer_list<int>), std::initializer_list<int>&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:96:14
    #3 0xaaaab4f248e8 in bool std::ranges::__any_of_fn::operator()<std::initializer_list<int>*, std::initializer_list<int>*, int (*)(std::initializer_list<int>), std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int> >(std::initializer_list<int>*, std::initializer_list<int>*, std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int>, int (*)(std::initializer_list<int>)) const /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/ranges_algo.h:109:30
    #4 0xaaaab4f1d72c in bool std::ranges::__any_of_fn::operator()<std::array<std::initializer_list<int>, 27ul>&, int (*)(std::initializer_list<int>), std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int> >(std::array<std::initializer_list<int>, 27ul>&, std::_Bind_front<bool (*)(unsigned int, int) noexcept, unsigned int>, int (*)(std::initializer_list<int>)) const /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/ranges_algo.h:120:9
    #5 0xaaaab4f0fca8 in create_table_shec432() /root/ceph/src/test/erasure-code/TestErasureCodeShec_arguments.cc:96:15
    #6 0xaaaab4f1b140 in main /root/ceph/src/test/erasure-code/TestErasureCodeShec_arguments.cc:361:3
    ceph#7 0xffff9b9673f8 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    ceph#8 0xffff9b9674c8 in __libc_start_main csu/../csu/libc-start.c:392:3
    ceph#9 0xaaaab4e5b8ac in _start (/root/ceph/build/bin/unittest_erasure_code_shec_arguments+0x11b8ac) (BuildId: c1fce44a2cd8b7e33e7f07b2de20b9a2f57c314a)
```

keep a as initializer_list could fix this error.

Signed-off-by: Rongqi Sun <sunrongqi@huawei.com>
@Svelar Svelar added the cleanup label May 13, 2024
@Svelar Svelar requested a review from adamemerson May 13, 2024 08:50
@github-actions github-actions bot added the tests label May 13, 2024
@Svelar
Copy link
Member Author

Svelar commented May 13, 2024

Ref:

#include <iostream>

const int *get(std::initializer_list<int> is) {
	return is.begin();
}

int main(int argc, char *argv[])
{
	auto p = get({1, 2, 3, 4});
	int i = *p;
}

image

image

@Svelar
Copy link
Member Author

Svelar commented May 23, 2024

jenkins test windows

@Svelar Svelar mentioned this pull request May 23, 2024
14 tasks
@tchaikov
Copy link
Contributor

jenkins test windows

@tchaikov tchaikov self-requested a review May 30, 2024 02:22
@tchaikov
Copy link
Contributor

i will (hopefully) take a look later this week.

@Svelar
Copy link
Member Author

Svelar commented Aug 5, 2024

ping? @tchaikov

}
if (std::popcount(avails) == 4) {
auto a = to_array<std::initializer_list<int>>({
std::initializer_list<std::initializer_list<int>> a {
Copy link
Contributor

@tchaikov tchaikov Aug 6, 2024

Choose a reason for hiding this comment

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

a is already a std::initializer_list<..> before this change. i don't understand what's the difference between before and after this change. which libstdc++ version are you using?

@tchaikov
Copy link
Contributor

tchaikov commented Aug 6, 2024

Ref:

#include <iostream>

const int *get(std::initializer_list<int> is) {
	return is.begin();
}

int main(int argc, char *argv[])
{
	auto p = get({1, 2, 3, 4});
	int i = *p;
}

image

image

this example does not match with what we have in TestErasureCodeShec_arguments.cc, where we do keep a around instead of creating a temporary variable and dereference an iterator of it.

@github-actions
Copy link

github-actions bot commented Oct 6, 2024

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions bot added the stale label Oct 6, 2024
@github-actions
Copy link

github-actions bot commented Nov 5, 2024

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions bot closed this Nov 5, 2024
@tchaikov
Copy link
Contributor

created #64238 to address the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants