]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Correctly determine the real executable in crunched binaries
authorAlex Richardson <arichardson@FreeBSD.org>
Mon, 24 Aug 2020 09:20:23 +0000 (09:20 +0000)
committerAlex Richardson <arichardson@FreeBSD.org>
Mon, 24 Aug 2020 09:20:23 +0000 (09:20 +0000)
commit50e525e40b4800bdf69bd1616e7382c284f13108
tree5b4fc17f169409148ac52c81b0e0896cb744db8a
parentb0f558df9f4edc9b1002af8f49855ade1dc6cbbd
Correctly determine the real executable in crunched binaries

This should fix cases like su setting argv[0] to _su for /bin/sh.
Previously cheribsdbox (a crunched tool we use in CheriBSD to reduce the
size of our minimal disk images to allow loading them onto FPGAs without
waiting forever for the transfer) would complain about _su not being
compiled in, but now that we also look at AT_EXECPATH it correctly
invokes the sh tool.

Note: we use use AT_EXECPATH instead of the KERN_PROC_PATHNAME sysctl to get
the crunchgen binary name since it seems like KERN_PROC_PATHNAME just
returns the last cached path for a given hardlink.
When using `su`, instead of invoking /bin/csh this would invoke the last
used hardlink to cheribsdbox. This caused weird test failures when running
tests due to `id` being executed instead of `echo`:

$ id  # id is a hardlink to /bin/cheribsdbox
$ su postgres -c 'echo 1' # su is also a hardlink
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)

Obtained from: CheriBSD

Reviewed By: emaste, brooks
Differential Revision: https://reviews.freebsd.org/D25998
usr.sbin/crunch/crunchgen/crunched_main.c