Page MenuHomeFreeBSD

Add a tool to modify control features in ELF binaries
ClosedPublic

Authored by emaste on Feb 22 2019, 1:00 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 10, 1:06 AM
Unknown Object (File)
Sun, May 5, 3:18 AM
Unknown Object (File)
Fri, May 3, 11:40 PM
Unknown Object (File)
Fri, May 3, 7:19 AM
Unknown Object (File)
Wed, Apr 24, 1:15 AM
Unknown Object (File)
Wed, Apr 24, 1:15 AM
Unknown Object (File)
Sat, Apr 20, 2:29 PM
Unknown Object (File)
Sat, Apr 20, 2:29 PM
Subscribers

Details

Summary

Add a tool to modify control features in ELF binaries.

Submitted by: Bora Ozarslan borako.ozarslan@gmail.com

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

tools/tools/controlelf/Makefile
4

This is not needed, right ?

6

And this.

23

Why this is needed ? Perhaps you should use #include "" instead of <>.

24

And what is this ?

27

Bump WARNS to max, and perhaps make warnings an error. New code should be clean.

tools/tools/controlelf/controlelf.1
1

Really ?

tools/tools/controlelf/controlelf.c
160

Extra blank line.

161

if (elf != NULL)

164

Checking for error from close(2) is almost always pointless, perhaps except for EBADF.

186

Blank line after '{' if no locals.

191

Use bool's ?

199

return (0);

200

I do not understand this loop, in particular the condition inside the if().

212

No initializers in local declarations.

226

nitems()

245

Excess ().

261

return on the next line.

315

Check for error from lseek.

319

Check errors from read, check for short reads.

326

roundup2().

327

sizeof(char) is sillyness. Why do you need calloc at all ?

336

This is yet another incorrect use of strncmp. At least you must check that strlen(name) == 7.

345

Why this cast ? It looks arbitrary.

362

branch statement on the next line.

tools/tools/controlelf/controlelf.c
200

if (gelf_getphdr(elf, i, phdr) == NULL) probably

212

FWIW this is part of style(9) I dislike, but it is what it is.

tools/tools/controlelf/controlelf.1
24–25

These two lines should be replaced with just:

.\" $FreeBSD$
borako.ozarslan_gmail.com added inline comments.
tools/tools/controlelf/controlelf.c
200

Essentially the for loop is going through each program header and finding the one that is of type PT_NOTE and returning that. In libelf, the recommended way to enumerate through the program headers is this way. The program header is returned inside the phdr which is given as a parameter. The function gelf_getphdr gets the ith program header and replaces the values inside the phdr. On success it returns phdr (the address given to it) and on failure it returns NULL. So that's what the first if is checking for, if the function succeeded or not. Then the second if checks if this program header is of type PT_NOTE. I now see that there may be more than 1 PT_NOTE header.

Fixed Makefile.
Changed code to comply with style(9).
Some cleanup.
Check all PT_NOTE headers until one that has feature control note has been found.
Updated copyright notices.
Get rid of control features that haven't been implemented yet (they are in review). Get rid of all mentions/examples of it.

emaste updated this revision to Diff 60170.
emaste edited reviewers, added: borako.ozarslan_gmail.com; removed: emaste.

initial updates incorporating kib feedback

This revision was not accepted when it landed; it landed in state Needs Review.Sep 27 2019, 4:28 PM
This revision was automatically updated to reflect the committed changes.