libc0.1: getauxval() nonfunctional on kfreebsd

Andreas Metzler ametzler at downhill.at.eu.org
Fri Jul 26 09:27:50 PDT 2013


On 2013-07-26 Petr Salinger <Petr.Salinger at seznam.cz> wrote:
> Hi.

> it does work. Try i.e.

> ~$ LD_SHOW_AUXV=1 /bin/true
[...]
> The AT_* constant are standardized only partially,
> FreeBSD kernel knows these:

> /* Values for a_type. */
> #define AT_NULL         0       /* Terminates the vector. */
> #define AT_IGNORE       1       /* Ignored entry. */
> #define AT_EXECFD       2       /* File descriptor of program to load. */
> #define AT_PHDR         3       /* Program header of program already loaded. */
> #define AT_PHENT        4       /* Size of each program header entry. */
> #define AT_PHNUM        5       /* Number of program header entries. */
> #define AT_PAGESZ       6       /* Page size in bytes. */
> #define AT_BASE         7       /* Interpreter's base address. */
> #define AT_FLAGS        8       /* Flags (unused for i386). */
> #define AT_ENTRY        9       /* Where interpreter should transfer control. */
> #define AT_NOTELF       10      /* Program is not ELF ?? */
> #define AT_UID          11      /* Real uid. */
> #define AT_EUID         12      /* Effective uid. */
> #define AT_GID          13      /* Real gid. */
> #define AT_EGID         14      /* Effective gid. */
> #define AT_EXECPATH     15      /* Path to the executable. */
> #define AT_CANARY       16      /* Canary for SSP. */
> #define AT_CANARYLEN    17      /* Length of the canary. */
> #define AT_OSRELDATE    18      /* OSRELDATE. */
> #define AT_NCPUS        19      /* Number of CPUs. */
> #define AT_PAGESIZES    20      /* Pagesizes. */
> #define AT_PAGESIZESLEN 21      /* Number of pagesizes. */
> #define AT_TIMEKEEP     22      /* Pointer to timehands. */
> #define AT_STACKPROT    23      /* Initial stack protection. */

> #define AT_COUNT        24      /* Count of defined aux entry types. */
[...]

Hello Petr,

I hope I understanding you correctly, please tell if I do not. ;-)

> The number 23 is AT_STACKPROT, and value 7 is correct one.

> The {e,}{u,g}id values are not passed from kernel (see above)
> and therefore "On success, getauxval() returns the value
> corresponding to type. If type is not found, 0 is returned."

That means: AT_UID/et.al. are defined in the header, the kernel knows
about them, but they are not usable though getauxval().

> Unfortunately, glibc so far does not allow
> to override AT_* constant lists by a sysdeps bits.

That is where the actual bug is, i.e. the headers are at odds with
the kernel?
(sid_kfreebsd-i386-dchroot)ametzler at fischer:~$ printf '#include <sys/auxv.h>\nat_secure is AT_SECURE\nat_stackprot is AT_STACKPROT\n' | gcc -E -  | tail -n2
at_secure is 23
at_stackprot is AT_STACKPROT

> What is your use case for getauxval() ?

p11-kit 0.18.5 uses getauxval (AT_SECURE) to detect SUID or SGID
execution.
<http://cgit.freedesktop.org/p11-glue/p11-kit/commit/?h=stable&id=d9808323cb288540c93f0a74b825714cab3c96eb>

It checks at configure time for the function with
AC_CHECK_FUNCS([getauxval], but not whether AT_SECURE works. If
getauxval is missing a replacement will be used. The fact that
getauxval(AT_SECURE) does not throw a compiler error on freebsd (as
in: error: 'AT_SECURE' undeclared) makes writing a configure test
unnecessarily complicated.

cu Andreas
-- 
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'


More information about the p11-glue mailing list