lkml.org 
[lkml]   [1999]   [Apr]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: ext3 to include capabilities?

On 07-Apr-99 Pavel Machek wrote:
> PS: And now, questions: Does anyone see a possibility how to add
> suitable information into _existing_ elf executable?
>
> I'd like to be able
>
>#setcap /bin/ping CAP_RAWSOCK
>
> without need to recompile ping. It is not essential feature. Still it
> would be nice.

Well, the most elegant way of including extra information in the ELF file is
with a PT_NOTE segment. This would consist of a Phdr entry in the executable
header, and the note segment itself. At exec time, the kernel would traverse
the NOTE segments, looking for a capability note. When found, it would read it
and do the appropriate things.

I noticed your hack for adding capabilities to an executable in your patch.
While this will work, its pretty ugly and against the intent of ELF's design.
It's also inextensible, and means your ELF files can no longer be processed by
standard tools. Note segments are there specifically so you can add extentions
to an ELF file without changing its format.

The hard part about adding a new segment to an existing file is that the ELF
header is mapped into the address space, so adding an extra Phdr would shift
everything up in the memory mapping. The best way of dealing with this is to
hack the linker to leave appropriate space when you build the executable, but
that's not ideal...

One trick you can do is shift up everything in the executable by 1 page, insert
the extra header and adjust the file offsets in the rest of the affected
headers. This will leave the mapped contents of the address space unchanged,
but change the header as far as the kernel sees it. This works because the
new PT_NOTE segment is not mapped into the address space.


Maybe it's picture time:

Typical dynamic ELF executable:

+---------------+
| Ehdr |
+---------------+
| Phdr (PHdr) |
| Phdr (Load) |
| Phdr (Load) |
| Phdr (Dyn) |
+---------------+
| code/data/etc |
+---------------+

ELF with capabilities:

+--------------------+
| Ehdr | <- what exec() uses; not mapped
+--------------------+
| Phdr (PHdr) | <- points to orig Phdr
| Phdr (Load) | <- points to adjusted offsets
| Phdr (Load) |
| Phdr (Dyn) |
| Phdr (Note/Cap) | <- offset points to capablilty data
+--------------------+
| Capability info | <- not mapped into address space
+--------------------+
:Padding to page size:
: :
+--------------------+<- "delta"
| orig Ehdr | <- mapped into address space
+--------------------+
| orig Phdr (PHdr) | }
| orig Phdr (Load) | } file offsets adjusted by "delta"
| orig Phdr (Load) | }
| orig Phdr (Dyn) | }
+--------------------+
| code/data/etc |
+--------------------+

J

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.071 / U:0.980 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site