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

Matrix-free: out of bounds vector access #15426

Closed
tamiko opened this issue Jun 22, 2023 · 4 comments · Fixed by #15430
Closed

Matrix-free: out of bounds vector access #15426

tamiko opened this issue Jun 22, 2023 · 4 comments · Fixed by #15430

Comments

@tamiko
Copy link
Member

tamiko commented Jun 22, 2023

My desktop system has a "hardened" libstdc++ library version installed that has assertions for bounds checks compiled in. When running the testsuite a number of matrix-free tests are failing for me with an assert. For example:

/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; reference = unsigned int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Here is an exemplary stack trace how the assertion is triggered:

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007fffb94afd63 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007fffb9460f26 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fffb944a87c in __GI_abort () at abort.c:79
#4  0x00007fffaeb0f78f in std::__glibcxx_assert_fail(char const*, int, char const*, char const*)
    (file=<optimized out>, line=<optimized out>, function=<optimized out>, condition=<optimized out>)
    at /var/tmp/portage/sys-devel/gcc-13.1.1_p20230527/work/gcc-13-20230527/libstdc++-v3/src/c++11/debug.cc:61
#5  0x000055555568bcb7 in std::vector<unsigned int, std::allocator<unsigned int> >::operator[](unsigned long) (this=0x5555559ae0a8, __n=128)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/stl_vector.h:1125
#6  0x00007fffee0d6fb7 in dealii::internal::MatrixFreeFunctions::DoFInfo::compute_cell_index_compression(std::vector<unsigned char, std::allocator<unsigned char> > const&)
    (this=0x5555559ae040, irregular_cells=std::vector of length 32, capacity 32 = {...}) at /home/tamiko/workspace/dealii/source/matrix_free/dof_info.cc:640
#7  0x00007fffee0d6066 in dealii::internal::MatrixFreeFunctions::DoFInfo::reorder_cells(dealii::internal::MatrixFreeFunctions::TaskInfo const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&)
    (this=0x5555559ae040, task_info=..., renumbering=std::vector of length 64, capacity 64 = {...}, constraint_pool_row_index=std::vector of length 1, capacity 1 = {...}, irregular_cells=std::vector of length 32, capacity 32 = {...}) at /home/tamiko/workspace/dealii/source/matrix_free/dof_info.cc:524
#8  0x00007ffff1cbe85f in dealii::internal::compute_dof_info<2, double>(std::vector<dealii::AffineConstraints<double> const*, std::allocator<dealii::AffineConstraints<double> const*> > const&, std::vector<dealii::IndexSet, std::allocator<dealii::IndexSet> > const&, std::vector<dealii::SmartPointer<dealii::DoFHandler<2, 2> const, void>, std::allocator<dealii::SmartPointer<dealii::DoFHandler<2, 2> const, void> > > const&, dealii::Table<2, dealii::internal::MatrixFreeFunctions::ShapeInfo<double> > const&, unsigned int, unsigned int, bool, std::vector<unsigned int, std::allocator<unsigned int> > const&, bool, bool, bool, bool, dealii::internal::MatrixFreeFunctions::TaskInfo&, std::vector<std::pair<unsigned int, unsigned int>, std::allocator<std::pair<unsigned int, unsigned int> > >&, std::vector<dealii::internal::MatrixFreeFunctions::DoFInfo, std::allocator<dealii::internal::MatrixFreeFunctions::DoFInfo> >&, dealii::internal::MatrixFreeFunctions::FaceSetup<2>&, dealii::internal::MatrixFreeFunctions::ConstraintValues<double>&, bool)
    (constraint=std::vector of length 1, capacity 1 = {...}, locally_owned_dofs=std::vector of length 1, capacity 1 = {...}, dof_handler=std::vector of length 1, capacity 1 = {...}, shape_infos=..., cell_level_index_end_local=64, mg_level=4294967295, hold_all_faces_to_owned_cells=false, cell_vectorization_category=std::vector of length 0, capacity 0, cell_vectorization_categories_strict=false, do_face_integrals=true, build_inner_faces=true, overlap_communication_computation=true, task_info=..., cell_level_index=std::vector of length 64, capacity 64 = {...}, dof_info=std::vector of length 1, capacity 1 = {...}, face_setup=..., constraint_values=..., use_vector_data_exchanger_full=false) at /home/tamiko/workspace/dealii/include/deal.II/matrix_free/matrix_free.templates.h:1843
#9  0x00007ffff1c7868f in dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::initialize_indices<double>(std::vector<dealii::AffineConstraints<double> const*, std::allocator<dealii::AffineConstraints<double> const*> > const&, std::vector<dealii::IndexSet, std::allocator<dealii::IndexSet> > const&, dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::AdditionalData const&)
    (this=0x7fffffffd720, constraint=std::vector of length 1, capacity 1 = {...}, locally_owned_dofs=std::vector of length 1, capacity 1 = {...}, additional_data=...)
    at /home/tamiko/workspace/dealii/include/deal.II/matrix_free/matrix_free.templates.h:1894
#10 0x00007ffff1c02f47 in dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::internal_reinit<double, 2>(std::shared_ptr<dealii::hp::MappingCollection<2, 2> > const&, std::vector<dealii::DoFHandler<2, 2> const*, std::allocator<dealii::DoFHandler<2, 2> const*> > const&, std::vector<dealii::AffineConstraints<double> const*, std::allocator<dealii::AffineConstraints<double> const*> > const&, std::vector<dealii::IndexSet, std::allocator<dealii::IndexSet> > const&, std::vector<dealii::hp::QCollection<2>, std::allocator<dealii::hp::QCollection<2> > > const&, dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::AdditionalData const&)
    (this=0x7fffffffd720, mapping=std::shared_ptr<dealii::hp::MappingCollection<2, 2>> (use count 1, weak count 0) = {...}, dof_handler=std::vector of length 1, capacity 1 = {...}, constraints=std::vector of length 1, capacity 1 = {...}, locally_owned_dofs=std::vector of length 1, capacity 1 = {...}, quad=std::vector of length 1, capacity 1 = {...}, additional_data=...) at /home/tamiko/workspace/dealii/include/deal.II/matrix_free/matrix_free.templates.h:503
#11 0x00005555556970b3 in dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::reinit<dealii::QGauss<2>, double, dealii::MappingQ1<2, 2> >(dealii::MappingQ1<2, 2> const&, dealii::DoFHandler<2, 2> const&, dealii::AffineConstraints<double> const&, dealii::QGauss<2> const&, dealii::MatrixFree<2, double, dealii::VectorizedArray<dou--Type <RET> for more, q to quit, c to continue without paging--
ble, 2ul> >::AdditionalData const&) (this=0x7fffffffd720, mapping=..., dof_handler=..., constraints_in=..., quad=..., additional_data=...)
    at /home/tamiko/workspace/dealii/include/deal.II/matrix_free/matrix_free.h:3167
#12 0x00005555556926fc in test<2>(unsigned int) (n_refinements=2) at /home/tamiko/workspace/dealii/tests/matrix_free/element_birth_and_death_01.cc:99
#13 0x000055555567ee12 in main(int, char**) (argc=1, argv=0x7fffffffdf38) at /home/tamiko/workspace/dealii/tests/matrix_free/element_birth_and_death_01.cc:208

This was when executing the matrix_free/element_birth_and_death_01 test.

In reference to #15383

@tamiko
Copy link
Member Author

tamiko commented Jun 22, 2023

@kronbichler @peterrum ping

@kronbichler
Copy link
Member

I will look into it in around 6 hours.

@kronbichler
Copy link
Member

I see

==55542== Invalid read of size 4
==55542==    at 0x12500C6C: dealii::internal::MatrixFreeFunctions::DoFInfo::compute_cell_index_compression(std::vector<unsigned char, std::allocator<unsigned char> > const&) (deal.II/source/matrix_free/dof_info.cc:637)
==55542==    by 0x12500028: dealii::internal::MatrixFreeFunctions::DoFInfo::reorder_cells(dealii::internal::MatrixFreeFunctions::TaskInfo const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&) (deal.II/source/matrix_free/dof_info.cc:524)
...
==55542==  Address 0x2f4dd0a0 is 0 bytes after a block of size 512 alloc'd
...
==55542==    by 0x124FF3D0: reserve (vector.tcc:79)
==55542==    by 0x124FF3D0: dealii::internal::MatrixFreeFunctions::DoFInfo::reorder_cells(dealii::internal::MatrixFreeFunctions::TaskInfo const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned int, std::allocator<unsigned int> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&) (deal.II/source/matrix_free/dof_info.cc:350)
...

@tamiko tamiko changed the title Matrix-free: use after free Matrix-free: out of bounds vector access Jun 22, 2023
@tamiko
Copy link
Member Author

tamiko commented Jun 22, 2023

#15430 did indeed fix about 90% of failing matrix free tests. There is some residual fallout due to yet another bounds violation in DoFAccessorImplementation::Implementation::process_object, opening a bug report.

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

Successfully merging a pull request may close this issue.

2 participants