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

Use "read" to fetch misaligned 64bit values from bundle header #63431

Merged
merged 3 commits into from
Jan 7, 2022

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Jan 6, 2022

Fixes: #62273

Misalligned reads may cause crashes on ARM32, depending on system config.

@ghost
Copy link

ghost commented Jan 6, 2022

Tagging subscribers to this area: @agocke, @vitek-karas, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #62273

Misalligned reads may cause crashes on ARM32, depending on system config.

Author: VSadov
Assignees: -
Labels:

arch-arm32, area-Single-File

Milestone: -

@VSadov VSadov added the Servicing-consider Issue for next servicing release review label Jan 6, 2022
@VSadov VSadov requested a review from janvorli January 6, 2022 04:08
@VSadov VSadov changed the title Use "read" to fetch misaligned 64bit values from mem-mapped header Use "read" to fetch misaligned 64bit values from bundle header Jan 6, 2022
if (bundle_major_version >= 6)
{
reader.read(&fixed_data.compressedSize, sizeof(int64_t));
}

fixed_data.type = *(file_type_t*)reader.read_direct(sizeof(file_type_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the size of file_type_t here and how is it guaranteed to be aligned? or do reads of its size not need aligning?

Copy link
Member

Choose a reason for hiding this comment

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

It is an enum with base uint8_t, defined here:

enum file_type_t : uint8_t

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

I wonder if the read_direct of header_fixed_v2_t wouldn't potentially suffer from the same issue. It has 64 bit members. Maybe it would be safer and more future proof to drop the read_direct completely and always use just the read.

// Return a pointer to the requested bytes within the memory-mapped file.
// Skip over len bytes.
const char* read_direct(int64_t len)
uint8_t read_byte()
Copy link
Member

Choose a reason for hiding this comment

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

Nit: since this is only used from one place, is it worth adding? Why not just use the read even for the single byte file type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just noticed the same thing - there is read(), which is the same as read_byte()

@VSadov
Copy link
Member Author

VSadov commented Jan 6, 2022

I've removed read_direct. It does seem unsafe.

@jeffschwMSFT jeffschwMSFT removed the Servicing-consider Issue for next servicing release review label Jan 6, 2022
@jeffschwMSFT jeffschwMSFT added this to the 6.0.x milestone Jan 6, 2022
Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@VSadov
Copy link
Member Author

VSadov commented Jan 7, 2022

Just FYI. I have got Raspbian installed on my PI and I was able to reproduce the failure. (after setting cpu/alignment handler to 4)

Now I am at the stage where I want to make sure that the fix actually fixes the problem - i.e. whether after the fix there is no Bus error and apps are able to run.

@VSadov
Copy link
Member Author

VSadov commented Jan 7, 2022

I have validated that an app built with singlefilehost that contains the fix runs on Raspbian (bullseye arm32) regardless of /proc/cpu/alignment settings. 👍

@VSadov VSadov merged commit b1edcf1 into dotnet:main Jan 7, 2022
@VSadov VSadov deleted the alignRead branch January 7, 2022 03:54
@VSadov
Copy link
Member Author

VSadov commented Jan 7, 2022

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2022

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1669737088

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Bus error when running PublishSingleFile=true .NET 6.0 app on linux-arm (Raspbian)
5 participants