diff options
author | <gerald.jelinek@sun.com> | 2010-07-02 08:22:56 -0600 |
---|---|---|
committer | <gerald.jelinek@sun.com> | 2010-07-02 08:22:56 -0600 |
commit | be614d1f0a69404eb91b32b9dc9fb1d5d9ed0bd3 (patch) | |
tree | 5f05cfb107b4f24dcbb9dbc093a141a4c832579a | |
parent | ac13ce240ba9273d4f6a0b39f769310a90ab85d3 (diff) | |
download | illumos-gate-be614d1f0a69404eb91b32b9dc9fb1d5d9ed0bd3.tar.gz |
6962529 brand native wrapper should be simplified to use ld.so.1 -e options
4 files changed, 66 insertions, 84 deletions
diff --git a/usr/src/lib/brand/solaris10/cmd/s10_isaexec_wrapper.sh b/usr/src/lib/brand/solaris10/cmd/s10_isaexec_wrapper.sh index 3f462efb02..cbaf64f05e 100644 --- a/usr/src/lib/brand/solaris10/cmd/s10_isaexec_wrapper.sh +++ b/usr/src/lib/brand/solaris10/cmd/s10_isaexec_wrapper.sh @@ -40,42 +40,28 @@ # If this script gets setup with a mode that makes it suid, then things won't # work because the script will be running with the incorrect name. # +# The code in s10_native() which which cleans up the initial arguments for +# a wrapped command relies on a well formatted argument list. It assumes that +# the -e options immediately follow the native ld.so.1 command and that these +# options are contiguous with no extra spaces. If additional non -e ld.so.1 +# options are added here, that code must also be updated. +# +n=/.SUNWnative + bname=`/usr/bin/basename $0` dname=`/usr/bin/dirname $0` echo $dname | /usr/bin/grep "^/" >/dev/null || dname=`/bin/pwd`/$dname dname=`(cd $dname 2>/dev/null && /bin/pwd 2>/dev/null)` arch64=/ -LC_ALL=C /usr/bin/file /.SUNWnative/$dname/$bname | /usr/bin/grep "64-bit" \ +LC_ALL=C /usr/bin/file $n/$dname/$bname | /usr/bin/grep "64-bit" \ >/dev/null && arch64=/64/ -n=/.SUNWnative - -unset LD_AUDIT -unset LD_AUDIT_32 -unset LD_AUDIT_64 -unset LD_CONFIG -unset LD_CONFIG_32 -unset LD_CONFIG_64 -unset LD_FLAGS -unset LD_FLAGS_32 -unset LD_FLAGS_64 -unset LD_LOADFLTR -unset LD_LOADFLTR_32 -unset LD_LOADFLTR_64 -unset LD_ORIGIN -unset LD_ORIGIN_32 -unset LD_ORIGIN_64 -unset LD_SIGNAL -unset LD_SIGNAL_32 -unset LD_SIGNAL_64 -unset LD_PRELOAD -unset LD_LIBRARY_PATH -LD_NOCONFIG=1 -LD_LIBRARY_PATH_32=$n/lib:$n/usr/lib:$n/usr/lib/mps -LD_LIBRARY_PATH_64=$n/lib/64:$n/usr/lib/64:$n/usr/lib/mps/64 -LD_PRELOAD_32=s10_npreload.so.1 -LD_PRELOAD_64=s10_npreload.so.1 -export LD_NOCONFIG -export LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 LD_PRELOAD_32 LD_PRELOAD_64 -exec /.SUNWnative/usr/lib/brand/solaris10/s10_native \ - /.SUNWnative/lib${arch64}ld.so.1 /.SUNWnative$dname/$bname "$@" +exec $n/usr/lib/brand/solaris10/s10_native \ + $n/lib${arch64}ld.so.1 \ + -e LD_NOENVIRON=1 \ + -e LD_NOCONFIG=1 \ + -e LD_PRELOAD_32=s10_npreload.so.1 \ + -e LD_PRELOAD_64=s10_npreload.so.1 \ + -e LD_LIBRARY_PATH_32="$n/lib:$n/usr/lib:$n/usr/lib/mps" \ + -e LD_LIBRARY_PATH_64="$n/lib/64:$n/usr/lib/64:$n/usr/lib/mps/64" \ + $n$dname/$bname "$@" diff --git a/usr/src/lib/brand/solaris10/cmd/s10_python_wrapper.sh b/usr/src/lib/brand/solaris10/cmd/s10_python_wrapper.sh index 10b72bf3f6..05ace0ebdd 100644 --- a/usr/src/lib/brand/solaris10/cmd/s10_python_wrapper.sh +++ b/usr/src/lib/brand/solaris10/cmd/s10_python_wrapper.sh @@ -35,19 +35,24 @@ # bit linker and /.SUNWnative/lib/64/ld.so.1 as our 64-bit linker. # For convience we define "n" to be the native path prefix. # +# The code in s10_native() which which cleans up the initial arguments for +# a wrapped command relies on a well formatted argument list. It assumes that +# the -e options immediately follow the native ld.so.1 command and that these +# options are contiguous with no extra spaces. If additional non -e ld.so.1 +# options are added here, that code must also be updated. +# pyname=$0 n=/.SUNWnative -LD_NOCONFIG=1 -LD_LIBRARY_PATH_32=$n/lib:$n/usr/lib:$n/usr/lib/mps -LD_LIBRARY_PATH_64=$n/lib/64:$n/usr/lib/64:$n/usr/lib/mps/64 -LD_PRELOAD_32=s10_npreload.so.1 -LD_PRELOAD_64=s10_npreload.so.1 -export LD_NOCONFIG -export LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 LD_PRELOAD_32 LD_PRELOAD_64 - PYTHONPATH=/.SUNWnative/usr/lib/python2.4/vendor-packages export PYTHONPATH -exec /.SUNWnative/usr/lib/brand/solaris10/s10_native \ - /.SUNWnative/usr/bin/python2.4 /.SUNWnative$pyname "$@" +exec $n/usr/lib/brand/solaris10/s10_native \ + $n/lib/ld.so.1 \ + -e LD_NOENVIRON=1 \ + -e LD_NOCONFIG=1 \ + -e LD_PRELOAD_32=s10_npreload.so.1 \ + -e LD_PRELOAD_64=s10_npreload.so.1 \ + -e LD_LIBRARY_PATH_32="$n/lib:$n/usr/lib:$n/usr/lib/mps" \ + -e LD_LIBRARY_PATH_64="$n/lib/64:$n/usr/lib/64:$n/usr/lib/mps/64" \ + $n/usr/bin/python2.4 $n$pyname "$@" diff --git a/usr/src/lib/brand/solaris10/s10_npreload/common/s10_npreload.c b/usr/src/lib/brand/solaris10/s10_npreload/common/s10_npreload.c index 4916252539..bf0313afa4 100644 --- a/usr/src/lib/brand/solaris10/s10_npreload/common/s10_npreload.c +++ b/usr/src/lib/brand/solaris10/s10_npreload/common/s10_npreload.c @@ -20,8 +20,7 @@ */ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. */ #pragma init(init) @@ -35,35 +34,11 @@ * Its primary function is to perform one brand operation, B_S10_NATIVE, * which checks that this is actually a native process. If it is, then * the operation changes the executable name so that it is no longer - * ld.sol.1. Instead it changes it to be the name of the real native + * ld.so.1. Instead it changes it to be the name of the real native * executable that we're runnning. This allows things like pgrep to work * as expected. Note that this brand operation only changes the process * name wrt the kernel. From the process' perspective, the first * argument and AT_SUN_EXECNAME are still ld.so.1. - * - * The library also unsets the LD_LIBRARY_PATH_* and LD_PRELOAD_* - * environment variables created by the brand's native wrapper scripts - * (e.g., s10_isaexec_wrapper) in order to ensure that execve(2) and its - * ilk, which brand the calling process, do not cause ld.so.1 to link native - * libraries to the resulting process. The native wrapper scripts make - * LD_LIBRARY_PATH_* point to library directories (e.g., /usr/lib) prefixed - * with "/.SUNWnative" in order to make native processes link with native - * libraries. However, if a native process running within a branded zone - * executes exec(2), then the new process becomes branded. Therefore, if this - * library were to not unset the LD_LIBRARY_PATH_* environment variables, then - * if a native process were to invoke an exec(2) function, then the resulting - * process would be branded and linked with native libraries. - * LD_PRELOAD_*, which the native wrapper scripts set to "s10_npreload.so.1" - * (the name of this library), must be cleared as well because - * s10_npreload.so.1 is only preloaded into native processes and can only be - * accessed via the /.SUNWnative library paths. - * - * NOTE: This trick won't work if another library that invokes an exec(2) - * function in its initialization function is initialized before this library. - * Such a problem won't happen if the brand only replaces binaries shipped with - * Solaris (e.g., ifconfig(1M)) with their native counterparts because most (if - * not all) Solaris system libraries don't exec(2) within their initialization - * functions. */ void init(void) @@ -71,14 +46,4 @@ init(void) sysret_t rval; (void) __systemcall(&rval, SYS_brand, B_S10_NATIVE); - - /* - * We can safely use unsetenv(3C) to clear LD_LIBRARY_PATH_* and - * LD_PRELOAD_* because ld.so.1 caches their values before this - * library is initialized. - */ - (void) unsetenv("LD_LIBRARY_PATH_32"); - (void) unsetenv("LD_LIBRARY_PATH_64"); - (void) unsetenv("LD_PRELOAD_32"); - (void) unsetenv("LD_PRELOAD_64"); } diff --git a/usr/src/uts/common/brand/solaris10/s10_brand.c b/usr/src/uts/common/brand/solaris10/s10_brand.c index 6346d66189..2adf25b453 100644 --- a/usr/src/uts/common/brand/solaris10/s10_brand.c +++ b/usr/src/uts/common/brand/solaris10/s10_brand.c @@ -201,6 +201,29 @@ s10_amd64_correct_fsreg(klwp_t *l) } #endif /* __amd64 */ +/* + * The native ld.so.1 is invoked with a set of -e options which we also want to + * strip off. This function assumes the set of -e options immediately follows + * the native ld.so.1 command and is contiguous. This is OK, since we control + * the code in s10_isaexec_wrapper. We do it this way so we don't accidently + * strip a -e option from the native command itself. The format of an ld.so.1 + * -e option looks like: + * -e LD_NOENVIRON=1 + */ +char * +rm_e_options(char *args) +{ + char *p; + + while (strncmp(args, "-e ", 3) == 0) { + args += 3; + if ((p = strchr(args, ' ')) != NULL) + args = p + 1; + } + + return (args); +} + int s10_native() { @@ -208,7 +231,11 @@ s10_native() char *args_new, *comm_new, *p; int len; - len = sizeof (BRAND_NATIVE_LINKER32 " ") - 1; + /* + * len has an extra value for the trailing '\0' so this covers the + * appended " " in the following strcmps. + */ + len = sizeof (BRAND_NATIVE_LINKER32); /* * Make sure that the process' interpreter is the native dynamic linker. @@ -221,13 +248,12 @@ s10_native() */ if (strcmp(up->u_comm, S10_LINKER_NAME) != 0) return (0); - if (strncmp(up->u_psargs, BRAND_NATIVE_LINKER64 " /", len + 4) == 0) + if (strncmp(up->u_psargs, BRAND_NATIVE_LINKER64 " ", len + 3) == 0) len += 3; /* to account for "/64" in the path */ - else if (strncmp(up->u_psargs, BRAND_NATIVE_LINKER32 " /", len + 1) - != 0) + else if (strncmp(up->u_psargs, BRAND_NATIVE_LINKER32 " ", len) != 0) return (0); - args_new = strdup(&up->u_psargs[len]); + args_new = strdup(rm_e_options(&up->u_psargs[len])); if ((p = strchr(args_new, ' ')) != NULL) *p = '\0'; if ((comm_new = strrchr(args_new, '/')) != NULL) |