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

Binaries produced by .Net Maui compile on Android does not enable security flags #9786

Open
paul-kiar opened this issue Feb 12, 2025 · 6 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review

Comments

@paul-kiar
Copy link

Description

When you build a .Net Maui project it generates binaries that do not have all the security flags turned on.

Steps to Reproduce

Reproduction steps

Create a new project
Select .Net Maui App
Select .Net 9.0 
Choose Release mode
Build 
Find the output APK
Use apktool to extract the APK
Use checksec tool to verify flags on the .so files inside the APK

Expected that security flags are set on the output binaries

Actually the flags are:

Partial RELRO

No Canary found

NX enabled

DSO

No RPATH

No RUNPATH

Link to public reproduction project repository

No response

Version with bug

8.0.92 SR9.2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

No response

Affected platforms

Android

Affected platform versions

All

Did you find any workaround?

No response

Relevant log output

@PureWeen PureWeen transferred this issue from dotnet/maui Feb 12, 2025
@dotnet-policy-service dotnet-policy-service bot added the needs-triage Issues that need to be assigned. label Feb 12, 2025
@jpobst jpobst added Area: App+Library Build Issues when building Library projects or Application projects. and removed needs-triage Issues that need to be assigned. t/bug labels Feb 12, 2025
@jonpryor
Copy link
Member

What is checksec, and how does this issue overall differ from:

@jonpryor
Copy link
Member

If checksec refers to checksec.sh on trapkit.de, then:

% checksec.sh --file libxamarin-app.so
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      FILE
Partial RELRO   No canary found   NX enabled    DSO             No RPATH   No RUNPATH   libxamarin-app.so

then this is expected; libxamarin-app.so only has one function, which does not contain arrays, and thus there is nothing to have a stack canary; see also: #8053 (comment)

checksec.sh also doesn't like our AOT-generated binaries, e.g.

% checksec.sh --file libaot-System.Private.CoreLib.dll.so 
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      FILE
Partial RELRO   No canary found   NX enabled    DSO             No RPATH   No RUNPATH   libaot-System.Private.CoreLib.dll.so

@jonpryor jonpryor added the need-info Issues that need more information from the author. label Feb 12, 2025
@paul-kiar
Copy link
Author

Yes it is the checksec.sh script that generates this report as you found.

It is on all binaries generated by maui

The output for a release build library that is in our APK is the same:

Partial RELRO | No Canary found | NX enabled | DSO | No RPATH | No RUNPATH | No Symbols | No | 0 | 0 | ./libaot-Apm.Mobile.Inspections.dll.so

This file is 520kb, there is not just one function in this binary.

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Feb 13, 2025
@paul-kiar
Copy link
Author

After reading #6258, #8053, #8181 yes it appears that they are similar. My search failed to find these bugs (probably because my search terms are all in the pictures).

Full RELRO
Stack Canary
Fortify Source

Is there a way in maui to enable these protections in AOT libraries?

@jonpryor
Copy link
Member

@paul-kiar wrote:

This file is 520kb, there is not just one function in this binary.

Consider again libaot-System.Private.CoreLib.dll.so, which is 4.2MB in size:

% checksec.sh --file libaot-System.Private.CoreLib.dll.so
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      FILE
Partial RELRO   No canary found   NX enabled    DSO             No RPATH   No RUNPATH   libaot-System.Private.CoreLib.dll.so

What does it have?

% nm -D libaot-System.Private.CoreLib.dll.so
000000000043a3e8 D mono_aot_file_info

In fact, there are no functions in this binary. It has one symbol, which is Data (D). This is not executable code, from the dlopen() perspective; executable code would be T. libaot-Apm.Mobile.Inspections.dll.so is in the same scenario: it's AOT data for use by MonoVM's JIT. It has no native callable functions. It has nothing which requires a canary.

Canaries are desirable for (1) executable code, which (2) has on-stack arrays that can be overwritten:

void this_could_use_a_canary (void)
{
    char buf[1];
    sprintf (buf, "%s", "hello");
}

If you're not executable code, there's nowhere for the canary to go.

If you don't have an on-stack buffer, the canary is pointless; the purpose of the canary is to track buffer overruns within the function, and if you don't have a buffer, what is there to overrun?

@paul-kiar asked

Is there a way in maui to enable these protections in AOT libraries?

No.

@paul-kiar
Copy link
Author

Thank you, you may want a official response about this, there are independent researchers reporting this as a security vulnerability, which means you'll get more issues reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review
Projects
None yet
Development

No branches or pull requests

4 participants