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

RWX sections (or: custom section permissions) #104

Open
kitlith opened this issue Dec 6, 2019 · 7 comments · May be fixed by #105
Open

RWX sections (or: custom section permissions) #104

kitlith opened this issue Dec 6, 2019 · 7 comments · May be fixed by #105

Comments

@kitlith
Copy link
Contributor

kitlith commented Dec 6, 2019

Hey, I'm looking to use this crate to generate a msp430 binary from the equivilant of a flash dump and a list of symbols, for use with ghidra.

In my case, by default all pages are writable and executable, which is not currently expressable through this API: you can either mark as writable (data) or as executable (code) but not both.

Would it be possible to add a type for self modifying code, or a way to specify the permissions directly?

@bjorn3
Copy link
Contributor

bjorn3 commented Dec 6, 2019

If you want to have more control about the output, at the cost of less ergonomics, you could use the write module of the object crate instead.

@philipc
Copy link
Collaborator

philipc commented Dec 6, 2019

Note that object::write doesn't yet support RWX sections either though.

@bjorn3
Copy link
Contributor

bjorn3 commented Dec 6, 2019

Oops, assumed object would support it.

@m4b
Copy link
Owner

m4b commented Dec 6, 2019

@kitlith yes I think it would be very straightforward to add it, if you want to add a PR, go for it ! My hope was the faerie would be useful for exactly these kind of use cases :)

@kitlith
Copy link
Contributor Author

kitlith commented Dec 6, 2019

Heh, looking through the code I got really confused, because SectionBuilder exists, and allows arbitrary permission setting. It's just per-format and private... which makes sense. For a moment I thought I missed something when I was doing research at 1 AM.

So, for implementing this: should SectionDecl be expanded to be more generic? At least on the elf side sections added via SectionDecl aren't even loaded at runtime, so we'd need to add (at the very least) flags for write, execute, and allocate to SectionDecl. On the other hand, we could continue reserving SectionDecls for notes that are not loaded at runtime, and add a writable flag to FunctionDecl and/or an executable flag to DataDecl.

Though, looking at define_with_symbols, I'm much more likely to do the former because apparently we can't even add symbols to anything other than a SectionDecl.

@kitlith kitlith linked a pull request Dec 6, 2019 that will close this issue
@m4b
Copy link
Owner

m4b commented Dec 8, 2019

@kitlith actually can you paste an invocation you would want?

Do you want something like:

    obj.declare("foo", Decl::function().writeable().executable())?;

From your comments, i think so? As you say custom sections aren't loaded, so I think it makes sense to just add the writeable bit to function, and executable to data; this makes the user api nicer (but requires some annoying boilerplate to be added, like in your PR).

I can't think of another case where we'd want to specify RWX flags for anything else?

@kitlith
Copy link
Contributor Author

kitlith commented Dec 8, 2019

"we can't even add symbols to anything other than a SectionDecl" is my sticking point here, i need to be able to specify symbols at arbitrary points in the section.

I resolved this in the PR by adding a flag to signal if the custom section is loaded or not, which seems extremely reasonable: allows you to create sections that are like '.note.GNU-stack' and sections that are rwx at the same time.

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

Successfully merging a pull request may close this issue.

4 participants