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

illegal read of byte preceding an automatic (stack allocate) variable #73718

Closed
RobertHenry6bev opened this issue Aug 10, 2022 · 4 comments · Fixed by #83906
Closed

illegal read of byte preceding an automatic (stack allocate) variable #73718

RobertHenry6bev opened this issue Aug 10, 2022 · 4 comments · Fixed by #83906

Comments

@RobertHenry6bev
Copy link
Contributor

Description

Compiling on/for x64 architecture on linux with clang-14.

The function CMiniMdBase::InitColsForTable

CMiniColDef pCols[9]; // The col defs to init.

allocates an automatic array variable of CMiniColDef[9]. The base address of this array is passed down through UsesAllocatedMemory(). UsesAllocatedMemory apparently implements some kind of marking of the preceding byte to determine if the block was obtained from a memory allocator.

But in this case, the block is an automatic in some nearby frame. In our case, the preceding bytes contain a pointer pTemplate. Uses AllocatedMemory reads a byte from that pointer, which one depends on endianness.

You can't do thatt.

Reproduction Steps

Compile with -fsanitize=address and stop at first fail.

Expected behavior

no errors detected by asan

Actual behavior

Read an adjacent memory location.

Regression?

No response

Known Workarounds

Probably put a dummy slot in the frame before the [9] vector to emulate what's done when those CMiniColDefs are allocated dynamically.

Configuration

No response

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 10, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 11, 2022
@ghost
Copy link

ghost commented Aug 11, 2022

Tagging subscribers to this area: @hoyosjs
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Compiling on/for x64 architecture on linux with clang-14.

The function CMiniMdBase::InitColsForTable

CMiniColDef pCols[9]; // The col defs to init.

allocates an automatic array variable of CMiniColDef[9]. The base address of this array is passed down through UsesAllocatedMemory(). UsesAllocatedMemory apparently implements some kind of marking of the preceding byte to determine if the block was obtained from a memory allocator.

But in this case, the block is an automatic in some nearby frame. In our case, the preceding bytes contain a pointer pTemplate. Uses AllocatedMemory reads a byte from that pointer, which one depends on endianness.

You can't do thatt.

Reproduction Steps

Compile with -fsanitize=address and stop at first fail.

Expected behavior

no errors detected by asan

Actual behavior

Read an adjacent memory location.

Regression?

No response

Known Workarounds

Probably put a dummy slot in the frame before the [9] vector to emulate what's done when those CMiniColDefs are allocated dynamically.

Configuration

No response

Other information

No response

Author: RobertHenry6bev
Assignees: -
Labels:

area-Infrastructure-coreclr, untriaged, in-pr

Milestone: -

@AntonLapounov AntonLapounov added area-Diagnostics-coreclr and removed untriaged New issue has not been triaged by the area owner area-Infrastructure-coreclr labels Aug 11, 2022
@ghost
Copy link

ghost commented Aug 11, 2022

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Compiling on/for x64 architecture on linux with clang-14.

The function CMiniMdBase::InitColsForTable

CMiniColDef pCols[9]; // The col defs to init.

allocates an automatic array variable of CMiniColDef[9]. The base address of this array is passed down through UsesAllocatedMemory(). UsesAllocatedMemory apparently implements some kind of marking of the preceding byte to determine if the block was obtained from a memory allocator.

But in this case, the block is an automatic in some nearby frame. In our case, the preceding bytes contain a pointer pTemplate. Uses AllocatedMemory reads a byte from that pointer, which one depends on endianness.

You can't do thatt.

Reproduction Steps

Compile with -fsanitize=address and stop at first fail.

Expected behavior

no errors detected by asan

Actual behavior

Read an adjacent memory location.

Regression?

No response

Known Workarounds

Probably put a dummy slot in the frame before the [9] vector to emulate what's done when those CMiniColDefs are allocated dynamically.

Configuration

No response

Other information

No response

Author: RobertHenry6bev
Assignees: -
Labels:

area-Diagnostics-coreclr, area-Infrastructure-coreclr, in-pr

Milestone: -

@tommcdon tommcdon added this to the 8.0.0 milestone Aug 12, 2022
@mikelle-rogers
Copy link
Member

Moving to future as this long term work to enable sanitizers is ongoing. This will be fixed as part of that.

@mikelle-rogers mikelle-rogers modified the milestones: 8.0.0, Future Jan 6, 2023
jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this issue Mar 24, 2023
jkotas pushed a commit that referenced this issue Mar 25, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants