diff options
Diffstat (limited to 'usr/src')
36 files changed, 406 insertions, 119 deletions
diff --git a/usr/src/cmd/mdb/common/modules/libc/libc.c b/usr/src/cmd/mdb/common/modules/libc/libc.c index 44e4f49b87..03aad86cc2 100644 --- a/usr/src/cmd/mdb/common/modules/libc/libc.c +++ b/usr/src/cmd/mdb/common/modules/libc/libc.c @@ -856,12 +856,17 @@ d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) prt_addr(uberdata.ulwp_replace_last, 1), prt_addr(uberdata.atforklist, 0)); - HD("robustlocks robustlist progname"); - mdb_printf(OFFSTR "%s %s %s\n", + HD("robustlocks robustlist"); + mdb_printf(OFFSTR "%s %s\n", OFFSET(robustlocks), prt_addr(uberdata.robustlocks, 1), - prt_addr(uberdata.robustlist, 1), - prt_addr(uberdata.progname, 0)); + prt_addr(uberdata.robustlist, 1)); + + HD("progname ub_broot"); + mdb_printf(OFFSTR "%s %s\n", + OFFSET(progname), + prt_addr(uberdata.progname, 0), + prt_addr(uberdata.ub_broot, 1)); HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail"); mdb_printf(OFFSTR "%s %s %-10d %d\n", diff --git a/usr/src/cmd/pgrep/pgrep.c b/usr/src/cmd/pgrep/pgrep.c index 4531f11267..857f6ef818 100644 --- a/usr/src/cmd/pgrep/pgrep.c +++ b/usr/src/cmd/pgrep/pgrep.c @@ -597,6 +597,8 @@ main(int argc, char *argv[]) const char *optstr; optdesc_t *optd; int nmatches, c; + const char *zroot; + char buf[PATH_MAX]; DIR *dirp; @@ -626,6 +628,12 @@ main(int argc, char *argv[]) opterr = 0; + zroot = zone_get_nroot(); + if (zroot != NULL) { + (void) snprintf(buf, sizeof (buf), "%s/%s", zroot, g_procdir); + g_procdir = buf; + } + while (optind < argc) { while ((c = getopt(argc, argv, optstr)) != (int)EOF) { diff --git a/usr/src/cmd/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c index 8e4e18aafc..982c860d0d 100644 --- a/usr/src/cmd/prstat/prstat.c +++ b/usr/src/cmd/prstat/prstat.c @@ -182,6 +182,33 @@ static optdesc_t opts = { -1 /* sort in decreasing order */ }; + +static int +proc_snprintf(char *_RESTRICT_KYWD s, size_t n, + const char *_RESTRICT_KYWD fmt, ...) +{ + static boolean_t ptools_zroot_valid = B_FALSE; + static const char *ptools_zroot = NULL; + va_list args; + int ret, nret = 0; + + if (ptools_zroot_valid == B_FALSE) { + ptools_zroot_valid = B_TRUE; + ptools_zroot = zone_get_nroot(); + } + + if (ptools_zroot != NULL) { + nret = snprintf(s, n, "%s", ptools_zroot); + if (nret > n) + return (nret); + } + va_start(args, fmt); + ret = vsnprintf(s + nret, n - nret, fmt, args); + va_end(args); + + return (ret + nret); +} + /* * Print timestamp as decimal reprentation of time_t value (-d u was specified) * or the standard date format (-d d was specified). @@ -854,9 +881,9 @@ lwp_update(lwp_info_t *lwp, pid_t pid, id_t lwpid, struct prusage *usage) static int read_procfile(fd_t **fd, char *pidstr, char *file, void *buf, size_t bufsize) { - char procfile[MAX_PROCFS_PATH]; + char procfile[PATH_MAX]; - (void) snprintf(procfile, MAX_PROCFS_PATH, + (void) proc_snprintf(procfile, PATH_MAX, "/proc/%s/%s", pidstr, file); if ((*fd = fd_open(procfile, O_RDONLY, *fd)) == NULL) return (1); @@ -1382,6 +1409,7 @@ main(int argc, char **argv) int timeout; struct pollfd pollset; char key; + char procpath[PATH_MAX]; (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); @@ -1584,7 +1612,8 @@ main(int argc, char **argv) list_setkeyfunc(NULL, &opts, &lgroups, LT_LGRPS); if (opts.o_outpmode & OPT_TERMCAP) curses_on(); - if ((procdir = opendir("/proc")) == NULL) + (void) proc_snprintf(procpath, sizeof (procpath), "/proc"); + if ((procdir = opendir(procpath)) == NULL) Die(gettext("cannot open /proc directory\n")); if (opts.o_outpmode & OPT_TTY) { (void) printf(gettext("Please wait...\r")); diff --git a/usr/src/cmd/ptools/Makefile.bld b/usr/src/cmd/ptools/Makefile.bld index 9b8716f590..e8bb27b043 100644 --- a/usr/src/cmd/ptools/Makefile.bld +++ b/usr/src/cmd/ptools/Makefile.bld @@ -71,6 +71,12 @@ CERRWARN_pargs += -_gcc=-Wno-type-limits CERRWARN += $(CERRWARN_$(PROG)) +# +# Common code definitions +# +COBJS = ptools_common.o +CINC = -I../../common + # pargs depends on ../../common/elfcap components # pmadvise depends on pmap components @@ -81,14 +87,32 @@ CPPFLAGS_pargs = -I$(ELFCAP) OBJS_pargs = elfcap.o SRCS_pargs = $(ELFCAP)/elfcap.c -CPPFLAGS_pmap = -I$(PMAP) -OBJS_pmap = pmap_common.o +CPPFLAGS_pmap = -I$(PMAP) $(CINC) +OBJS_pmap = pmap_common.o $(COBJS) SRCS_pmap = $(PMAP)/pmap_common.c -CPPFLAGS_pmadvise = -I$(PMAP) -OBJS_pmadvise = pmap_common.o +CPPFLAGS_pmadvise = -I$(PMAP) $(CINC) +OBJS_pmadvise = pmap_common.o $(COBJS) SRCS_pmadvise = $(PMAP)/pmap_common.c +CPPFLAGS_preap = $(CINC) +OBJS_preap = $(COBJS) + +CPPFLAGS_psig = $(CINC) +OBJS_psig = $(COBJS) + +CPPFLAGS_ptime = $(CINC) +OBJS_ptime = $(COBJS) + +CPPFLAGS_ptree = $(CINC) +OBJS_ptree = $(COBJS) + +CPPFLAGS_pwait = $(CINC) +OBJS_pwait = $(COBJS) + +CPPFLAGS_pwdx = $(CINC) +OBJS_pwdx = $(COBJS) + CPPFLAGS += $(CPPFLAGS_$(PROG)) OBJS += $(OBJS_$(PROG)) SRCS += $(SRCS_$(PROG)) @@ -111,6 +135,10 @@ pmap_common.o: $(PMAP)/pmap_common.c $(COMPILE.c) $< $(POST_PROCESS_O) +%.o: ../../common/%.c + $(COMPILE.c) $< + $(POST_PROCESS_O) + all: $(PROG) ROOTBINPROG=$(ROOTBIN)/$(PROG) diff --git a/usr/src/cmd/ptools/common/ptools_common.c b/usr/src/cmd/ptools/common/ptools_common.c new file mode 100644 index 0000000000..a747ab213e --- /dev/null +++ b/usr/src/cmd/ptools/common/ptools_common.c @@ -0,0 +1,50 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2014 Joyent, Inc. All rights reserved. + */ + +#include <sys/feature_tests.h> +#include <stdio.h> +#include <stdarg.h> +#include <sys/types.h> +#include <zone.h> + +/* + * Common routines for ptools. + */ + +int +proc_snprintf(char *_RESTRICT_KYWD s, size_t n, + const char *_RESTRICT_KYWD fmt, ...) +{ + static boolean_t ptools_zroot_valid = B_FALSE; + static const char *ptools_zroot = NULL; + va_list args; + int ret, nret = 0; + + if (ptools_zroot_valid == B_FALSE) { + ptools_zroot_valid = B_TRUE; + ptools_zroot = zone_get_nroot(); + } + + if (ptools_zroot != NULL) { + nret = snprintf(s, n, "%s", ptools_zroot); + if (nret > n) + return (nret); + } + va_start(args, fmt); + ret = vsnprintf(s + nret, n - nret, fmt, args); + va_end(args); + + return (ret + nret); +} diff --git a/usr/src/cmd/ptools/common/ptools_common.h b/usr/src/cmd/ptools/common/ptools_common.h new file mode 100644 index 0000000000..52bcae9e51 --- /dev/null +++ b/usr/src/cmd/ptools/common/ptools_common.h @@ -0,0 +1,36 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2014 Joyent, Inc. All rights reserved. + */ + +#ifndef _PTOOLS_COMMON_H +#define _PTOOLS_COMMON_H + +#include <sys/feature_tests.h> + +/* + * Common functions for the ptools. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +extern int proc_snprintf(char *_RESTRICT_KYWD, size_t, + const char *_RESTRICT_KYWD, ...); + +#ifdef __cplusplus +} +#endif + +#endif /* _PTOOLS_COMMON_H */ diff --git a/usr/src/cmd/ptools/pargs/pargs.c b/usr/src/cmd/ptools/pargs/pargs.c index 12979a1ae0..97f3751a05 100644 --- a/usr/src/cmd/ptools/pargs/pargs.c +++ b/usr/src/cmd/ptools/pargs/pargs.c @@ -811,6 +811,7 @@ static struct aux_id aux_arr[] = { { AT_SUN_AUXFLAGS, "AT_SUN_AUXFLAGS", at_flags }, { AT_SUN_EMULATOR, "AT_SUN_EMULATOR", at_str }, { AT_SUN_BRANDNAME, "AT_SUN_BRANDNAME", at_str }, + { AT_SUN_BRAND_NROOT, "AT_SUN_BRAND_NROOT", at_str }, { AT_SUN_BRAND_AUX1, "AT_SUN_BRAND_AUX1", at_null }, { AT_SUN_BRAND_AUX2, "AT_SUN_BRAND_AUX2", at_null }, { AT_SUN_BRAND_AUX3, "AT_SUN_BRAND_AUX3", at_null } diff --git a/usr/src/cmd/ptools/pmap/pmap.c b/usr/src/cmd/ptools/pmap/pmap.c index 78bfa6b596..03f8bde791 100644 --- a/usr/src/cmd/ptools/pmap/pmap.c +++ b/usr/src/cmd/ptools/pmap/pmap.c @@ -22,6 +22,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2014, Joyent, Inc. All rights reserved. */ #include <stdio.h> @@ -42,6 +43,7 @@ #include <sys/mman.h> #include <sys/lgrp_user.h> #include <libproc.h> +#include "ptools_common.h" #include "pmap_common.h" @@ -199,7 +201,7 @@ main(int argc, char **argv) const char *bar; struct rlimit rlim; struct stat64 statbuf; - char buf[128]; + char buf[PATH_MAX]; int mapfd; int prg_gflags = PGRAB_RDONLY; int prr_flags = 0; @@ -358,7 +360,7 @@ main(int argc, char **argv) proc_unctrl_psinfo(&psinfo); if (Pstate(Pr) != PS_DEAD) { - (void) snprintf(buf, sizeof (buf), + (void) proc_snprintf(buf, sizeof (buf), "/proc/%d/map", (int)psinfo.pr_pid); if ((mapfd = open(buf, O_RDONLY)) < 0) { (void) fprintf(stderr, "%s: cannot " @@ -590,7 +592,7 @@ rmapping_iter(struct ps_prochandle *Pr, proc_map_f *func, void *cd) prmap_t *prmapp, *pmp; ssize_t n; - (void) snprintf(mapname, sizeof (mapname), + (void) proc_snprintf(mapname, sizeof (mapname), "/proc/%d/rmap", (int)Pstatus(Pr)->pr_pid); if ((mapfd = open(mapname, O_RDONLY)) < 0 || fstat(mapfd, &st) != 0) { @@ -631,7 +633,7 @@ xmapping_iter(struct ps_prochandle *Pr, proc_xmap_f *func, void *cd, int doswap) prxmap_t *prmapp, *pmp; ssize_t n; - (void) snprintf(mapname, sizeof (mapname), + (void) proc_snprintf(mapname, sizeof (mapname), "/proc/%d/xmap", (int)Pstatus(Pr)->pr_pid); if ((mapfd = open(mapname, O_RDONLY)) < 0 || fstat(mapfd, &st) != 0) { diff --git a/usr/src/cmd/ptools/pmap/pmap_common.c b/usr/src/cmd/ptools/pmap/pmap_common.c index fff55ffdbc..81f42d67f7 100644 --- a/usr/src/cmd/ptools/pmap/pmap_common.c +++ b/usr/src/cmd/ptools/pmap/pmap_common.c @@ -37,6 +37,7 @@ #include <sys/types.h> #include "pmap_common.h" +#include "ptools_common.h" /* * We compare the high memory addresses since stacks are faulted in from @@ -88,7 +89,7 @@ make_name(struct ps_prochandle *Pr, int lflag, uintptr_t addr, return (NULL); /* first see if we can find a path via /proc */ - (void) snprintf(path, sizeof (path), "/proc/%d/path/%s", + (void) proc_snprintf(path, sizeof (path), "/proc/%d/path/%s", (int)Psp->pr_pid, mapname); len = readlink(path, buf, bufsz - 1); if (len >= 0) { @@ -97,7 +98,7 @@ make_name(struct ps_prochandle *Pr, int lflag, uintptr_t addr, } /* fall back to object information reported by /proc */ - (void) snprintf(path, sizeof (path), + (void) proc_snprintf(path, sizeof (path), "/proc/%d/object/%s", (int)Psp->pr_pid, mapname); if (stat(path, &statb) == 0) { dev_t dev = statb.st_dev; diff --git a/usr/src/cmd/ptools/preap/preap.c b/usr/src/cmd/ptools/preap/preap.c index 8d30b8027c..6d8eb75611 100644 --- a/usr/src/cmd/ptools/preap/preap.c +++ b/usr/src/cmd/ptools/preap/preap.c @@ -24,8 +24,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -37,6 +35,8 @@ #include <sys/types.h> #include <sys/wait.h> #include <libproc.h> +#include <limits.h> +#include "ptools_common.h" #define NOREAP_TIME 60 /* wait 60 seconds before allow a reap */ @@ -53,11 +53,11 @@ intr(int sig) static int open_usage(pid_t pid, int *perr) { - char path[64]; + char path[PATH_MAX]; struct stat64 st; int fd; - (void) snprintf(path, sizeof (path), "/proc/%d/usage", (int)pid); + (void) proc_snprintf(path, sizeof (path), "/proc/%d/usage", (int)pid); /* * Attempt to open the usage file, and return the fd if we can diff --git a/usr/src/cmd/ptools/psig/psig.c b/usr/src/cmd/ptools/psig/psig.c index 70af35cb5e..848fda834c 100644 --- a/usr/src/cmd/ptools/psig/psig.c +++ b/usr/src/cmd/ptools/psig/psig.c @@ -21,10 +21,9 @@ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2014, Joyent, Inc. All rights reserved. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> #include <stdio_ext.h> #include <stdlib.h> @@ -37,6 +36,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <libproc.h> +#include "ptools_common.h" /* evil knowledge of libc internals */ #include "../../../lib/libc/inc/thr_uberdata.h" @@ -172,7 +172,7 @@ lwp_iter(void *cd, const lwpstatus_t *lwpstatus) static int look(char *arg) { - char pathname[100]; + char pathname[PATH_MAX]; struct stat statb; int fd = -1; int sig, gcode; @@ -199,7 +199,8 @@ look(char *arg) (void) memcpy(&psinfo, psinfop, sizeof (psinfo_t)); proc_unctrl_psinfo(&psinfo); - (void) sprintf(pathname, "/proc/%d/sigact", (int)psinfo.pr_pid); + (void) proc_snprintf(pathname, sizeof (pathname), "/proc/%d/sigact", + (int)psinfo.pr_pid); if ((fd = open(pathname, O_RDONLY)) < 0) { perr("open sigact"); goto look_error; @@ -213,8 +214,8 @@ look(char *arg) action = malloc(maxsig * sizeof (struct sigaction)); if (action == NULL) { (void) fprintf(stderr, - "%s: cannot malloc() space for %d sigaction structures\n", - command, maxsig); + "%s: cannot malloc() space for %d sigaction structures\n", + command, maxsig); goto look_error; } if (read(fd, (char *)action, maxsig * sizeof (struct sigaction)) != @@ -239,7 +240,7 @@ look(char *arg) if (psinfo.pr_dmodel != PR_MODEL_NATIVE) { caddr32_t addr; aharraddr = uberaddr + - offsetof(uberdata32_t, siguaction); + offsetof(uberdata32_t, siguaction); aharrlen = sizeof (siguaction32_t) * NSIG; (void) Pread(Pr, &addr, sizeof (addr), uberaddr + offsetof(uberdata32_t, sigacthandler)); @@ -248,7 +249,7 @@ look(char *arg) #endif { aharraddr = uberaddr + - offsetof(uberdata_t, siguaction); + offsetof(uberdata_t, siguaction); aharrlen = sizeof (siguaction_t) * NSIG; (void) Pread(Pr, &intfnaddr, sizeof (intfnaddr), uberaddr + offsetof(uberdata_t, sigacthandler)); @@ -323,7 +324,7 @@ look(char *arg) (void) printf("\t%-8s", hname); else (void) printf("\t0x%-8lx", - (ulong_t)haddr); + (ulong_t)haddr); s = sigflags(sig, sp->sa_flags); (void) printf("%s", (*s != '\0')? s : "\t0"); @@ -334,7 +335,7 @@ look(char *arg) } } else if (sig == SIGCLD) { s = sigflags(sig, - sp->sa_flags & (SA_NOCLDWAIT|SA_NOCLDSTOP)); + sp->sa_flags & (SA_NOCLDWAIT|SA_NOCLDSTOP)); if (*s != '\0') (void) printf("\t\t%s", s); } @@ -371,7 +372,7 @@ sigflags(int sig, int flags) static char code_buf[100]; char *str = code_buf; int flagmask = - (SA_ONSTACK|SA_RESETHAND|SA_RESTART|SA_SIGINFO|SA_NODEFER); + (SA_ONSTACK|SA_RESETHAND|SA_RESTART|SA_SIGINFO|SA_NODEFER); if (sig == SIGCLD) flagmask |= (SA_NOCLDSTOP|SA_NOCLDWAIT); @@ -414,19 +415,19 @@ deinterpose(int sig, void *aharr, psinfo_t *psinfo, struct sigaction *sp) #ifdef _LP64 if (psinfo->pr_dmodel != PR_MODEL_NATIVE) { struct sigaction32 *sa32 = (struct sigaction32 *) - ((uintptr_t)aharr + sig * sizeof (siguaction32_t) + - offsetof(siguaction32_t, sig_uaction)); + ((uintptr_t)aharr + sig * sizeof (siguaction32_t) + + offsetof(siguaction32_t, sig_uaction)); sp->sa_flags = sa32->sa_flags; sp->sa_handler = (void (*)())(uintptr_t)sa32->sa_handler; (void) memcpy(&sp->sa_mask, &sa32->sa_mask, - sizeof (sp->sa_mask)); + sizeof (sp->sa_mask)); } else #endif { struct sigaction *sa = (struct sigaction *) - ((uintptr_t)aharr + sig * sizeof (siguaction_t) + - offsetof(siguaction_t, sig_uaction)); + ((uintptr_t)aharr + sig * sizeof (siguaction_t) + + offsetof(siguaction_t, sig_uaction)); sp->sa_flags = sa->sa_flags; sp->sa_handler = sa->sa_handler; diff --git a/usr/src/cmd/ptools/ptime/ptime.c b/usr/src/cmd/ptools/ptime/ptime.c index c3a05ff51c..7c9be226e1 100644 --- a/usr/src/cmd/ptools/ptime/ptime.c +++ b/usr/src/cmd/ptools/ptime/ptime.c @@ -25,7 +25,7 @@ * Portions Copyright 2008 Chad Mynhier */ /* - * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2014, Joyent, Inc. All rights reserved. */ #include <stdio.h> @@ -41,6 +41,8 @@ #include <sys/time.h> #include <signal.h> #include <libproc.h> +#include <limits.h> +#include "ptools_common.h" static int look(pid_t); static void hr_min_sec(char *, long); @@ -189,7 +191,7 @@ main(int argc, char **argv) static int look(pid_t pid) { - char pathname[100]; + char pathname[PATH_MAX]; int rval = 0; int fd; psinfo_t psinfo; @@ -201,7 +203,8 @@ look(pid_t pid) if (proc_get_psinfo(pid, &psinfo) < 0) return (perr("read psinfo")); - (void) sprintf(pathname, "/proc/%d/usage", (int)pid); + (void) proc_snprintf(pathname, sizeof (pathname), "/proc/%d/usage", + (int)pid); if ((fd = open(pathname, O_RDONLY)) < 0) return (perr("open usage")); diff --git a/usr/src/cmd/ptools/ptree/ptree.c b/usr/src/cmd/ptools/ptree/ptree.c index 27fef9b7f0..92a65e2f44 100644 --- a/usr/src/cmd/ptools/ptree/ptree.c +++ b/usr/src/cmd/ptools/ptree/ptree.c @@ -21,14 +21,13 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2014, Joyent, Inc. All rights reserved. */ /* * ptree -- print family tree of processes */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <assert.h> #include <stdio.h> #include <string.h> @@ -48,6 +47,7 @@ #include <sys/ctfs.h> #include <libcontract_priv.h> #include <sys/stat.h> +#include "ptools_common.h" #define FAKEDPID0(p) (p->pid == 0 && p->psargs[0] == '\0') @@ -103,10 +103,11 @@ main(int argc, char **argv) char *s; int n; int retc = 0; + char ppath[PATH_MAX]; DIR *dirp; struct dirent *dentp; - char pname[100]; + char pname[PATH_MAX]; int pdlen; ps_t *p; @@ -169,16 +170,18 @@ main(int argc, char **argv) psize = 0; ps = NULL; + (void) proc_snprintf(ppath, sizeof (ppath), "/proc"); + /* * Search the /proc directory for all processes. */ - if ((dirp = opendir("/proc")) == NULL) { - (void) fprintf(stderr, "%s: cannot open /proc directory\n", - command); + if ((dirp = opendir(ppath)) == NULL) { + (void) fprintf(stderr, "%s: cannot open %s directory\n", + command, ppath); return (1); } - (void) strcpy(pname, "/proc"); + (void) strcpy(pname, ppath); pdlen = strlen(pname); pname[pdlen++] = '/'; diff --git a/usr/src/cmd/ptools/pwait/pwait.c b/usr/src/cmd/ptools/pwait/pwait.c index 0733c355cf..ec11573477 100644 --- a/usr/src/cmd/ptools/pwait/pwait.c +++ b/usr/src/cmd/ptools/pwait/pwait.c @@ -23,8 +23,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> #include <stdio_ext.h> #include <ctype.h> @@ -39,6 +37,8 @@ #include <poll.h> #include <procfs.h> #include <sys/resource.h> +#include <limits.h> +#include "ptools_common.h" static int count_my_files(); static char *command; @@ -49,6 +49,7 @@ static char *command; int main(int argc, char **argv) { + char buf[PATH_MAX]; unsigned long remain = 0; struct pollfd *pollfd; struct pollfd *pfd; @@ -75,10 +76,12 @@ main(int argc, char **argv) (void) fprintf(stderr, "usage:\t%s [-v] pid ...\n", command); (void) fprintf(stderr, " (wait for processes to terminate)\n"); (void) fprintf(stderr, - " -v: verbose; report terminations to standard out\n"); + " -v: verbose; report terminations to standard out\n"); return (2); } + (void) proc_snprintf(buf, sizeof (buf), "/proc/"); + /* make sure we have enough file descriptors */ if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { int nfiles = count_my_files(); @@ -87,8 +90,8 @@ main(int argc, char **argv) rlim.rlim_cur = argc + nfiles + SLOP; if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) { (void) fprintf(stderr, - "%s: insufficient file descriptors\n", - command); + "%s: insufficient file descriptors\n", + command); return (2); } } @@ -108,11 +111,11 @@ main(int argc, char **argv) if (strchr(arg, '/') != NULL) (void) strncpy(psinfofile, arg, sizeof (psinfofile)); else { - (void) strcpy(psinfofile, "/proc/"); + (void) strcpy(psinfofile, buf); (void) strncat(psinfofile, arg, sizeof (psinfofile)-6); } (void) strncat(psinfofile, "/psinfo", - sizeof (psinfofile)-strlen(psinfofile)); + sizeof (psinfofile)-strlen(psinfofile)); pfd = &pollfd[i]; if ((pfd->fd = open(psinfofile, O_RDONLY)) >= 0) { @@ -126,7 +129,7 @@ main(int argc, char **argv) pfd->revents = 0; } else if (errno == ENOENT) { (void) fprintf(stderr, "%s: no such process: %s\n", - command, arg); + command, arg); } else { perror(arg); } @@ -160,9 +163,9 @@ main(int argc, char **argv) if (pread(pfd->fd, &psinfo, sizeof (psinfo), (off_t)0) == sizeof (psinfo)) { - (void) printf( - "%s: terminated, wait status 0x%.4x\n", - arg, psinfo.pr_wstat); + (void) printf("%s: terminated, " + "wait status 0x%.4x\n", + arg, psinfo.pr_wstat); } else { (void) printf( "%s: terminated\n", arg); @@ -170,10 +173,10 @@ main(int argc, char **argv) } if (pfd->revents & POLLNVAL) (void) printf("%s: system process\n", - arg); + arg); if (pfd->revents & ~(POLLPRI|POLLHUP|POLLNVAL)) (void) printf("%s: unknown error\n", - arg); + arg); } (void) close(pfd->fd); diff --git a/usr/src/cmd/ptools/pwdx/pwdx.c b/usr/src/cmd/ptools/pwdx/pwdx.c index adf42c0877..4a2c6f0c3f 100644 --- a/usr/src/cmd/ptools/pwdx/pwdx.c +++ b/usr/src/cmd/ptools/pwdx/pwdx.c @@ -22,10 +22,9 @@ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2014, Joyent, Inc. All rights reserved. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> #include <unistd.h> #include <string.h> @@ -33,6 +32,8 @@ #include <libproc.h> #include <sys/param.h> +#include "ptools_common.h" + static char *command; static int @@ -49,7 +50,7 @@ show_cwd(const char *arg) return (1); } - (void) snprintf(proc, sizeof (proc), "/proc/%d/path/cwd", + (void) proc_snprintf(proc, sizeof (proc), "/proc/%d/path/cwd", (int)p.pr_pid); if ((ret = readlink(proc, cwd, sizeof (cwd) - 1)) <= 0) { diff --git a/usr/src/cmd/sgs/libconv/common/corenote.c b/usr/src/cmd/sgs/libconv/common/corenote.c index d24fdf6769..863c3bc917 100644 --- a/usr/src/cmd/sgs/libconv/common/corenote.c +++ b/usr/src/cmd/sgs/libconv/common/corenote.c @@ -105,19 +105,20 @@ conv_cnote_auxv_type(Word type, Conv_fmt_flags_t fmt_flags, static const conv_ds_msg_t ds_types_2000_2011 = { CONV_DS_MSG_INIT(2000, types_2000_2011) }; - static const Msg types_2014_2023[] = { + static const Msg types_2014_2024[] = { MSG_AUXV_AT_SUN_EXECNAME, MSG_AUXV_AT_SUN_MMU, MSG_AUXV_AT_SUN_LDDATA, MSG_AUXV_AT_SUN_AUXFLAGS, MSG_AUXV_AT_SUN_EMULATOR, MSG_AUXV_AT_SUN_BRANDNAME, MSG_AUXV_AT_SUN_BRAND_AUX1, MSG_AUXV_AT_SUN_BRAND_AUX2, - MSG_AUXV_AT_SUN_BRAND_AUX3, MSG_AUXV_AT_SUN_HWCAP2 + MSG_AUXV_AT_SUN_BRAND_AUX3, MSG_AUXV_AT_SUN_HWCAP2, + MSG_AUXV_AT_SUN_BRAND_NROOT }; - static const conv_ds_msg_t ds_types_2014_2023 = { - CONV_DS_MSG_INIT(2014, types_2014_2023) }; + static const conv_ds_msg_t ds_types_2014_2024 = { + CONV_DS_MSG_INIT(2014, types_2014_2024) }; static const conv_ds_t *ds[] = { CONV_DS_ADDR(ds_types_0_25), CONV_DS_ADDR(ds_types_2000_2011), - CONV_DS_ADDR(ds_types_2014_2023), NULL }; + CONV_DS_ADDR(ds_types_2014_2024), NULL }; return (conv_map_ds(ELFOSABI_NONE, EM_NONE, type, ds, fmt_flags, inv_buf)); diff --git a/usr/src/cmd/sgs/libconv/common/corenote.msg b/usr/src/cmd/sgs/libconv/common/corenote.msg index 2813a78080..c68b826f72 100644 --- a/usr/src/cmd/sgs/libconv/common/corenote.msg +++ b/usr/src/cmd/sgs/libconv/common/corenote.msg @@ -103,6 +103,7 @@ @ MSG_AUXV_AT_SUN_BRAND_AUX2 "SUN_BRAND_AUX2" @ MSG_AUXV_AT_SUN_BRAND_AUX3 "SUN_BRAND_AUX3" @ MSG_AUXV_AT_SUN_HWCAP2 "SUN_HWCAP2" +@ MSG_AUXV_AT_SUN_BRAND_NROOT "SUN_BRAND_NROOT" @ MSG_CC_CONTENT_STACK "STACK" diff --git a/usr/src/head/zone.h b/usr/src/head/zone.h index ae03d2453c..14af0f8ff3 100644 --- a/usr/src/head/zone.h +++ b/usr/src/head/zone.h @@ -70,6 +70,7 @@ extern int zone_add_datalink(zoneid_t, datalink_id_t); extern int zone_remove_datalink(zoneid_t, datalink_id_t); extern int zone_check_datalink(zoneid_t *, datalink_id_t); extern int zone_list_datalink(zoneid_t, int *, datalink_id_t *); +extern const char *zone_get_nroot(void); #ifdef __cplusplus } diff --git a/usr/src/lib/brand/lx/lx_support/lx_support.c b/usr/src/lib/brand/lx/lx_support/lx_support.c index 250240707e..206fa2a9e9 100644 --- a/usr/src/lib/brand/lx/lx_support/lx_support.c +++ b/usr/src/lib/brand/lx/lx_support/lx_support.c @@ -443,8 +443,6 @@ static int lxs_verify(char *xmlfile) { zone_dochandle_t handle; - struct zone_dstab dstab; - struct zone_devtab devtab; boolean_t audio, restart; char *idev, *odev, *kvers; char hostidp[HW_HOSTID_LEN]; @@ -458,32 +456,6 @@ lxs_verify(char *xmlfile) } /* - * Check to see whether the zone has any ZFS datasets configured. - */ - if (zonecfg_setdsent(handle) != Z_OK) { - zonecfg_fini_handle(handle); - lxs_err(gettext("zonecfg provided an invalid XML file")); - } - - if (zonecfg_getdsent(handle, &dstab) == Z_OK) { - zonecfg_fini_handle(handle); - lxs_err(gettext("lx zones do not support ZFS datasets")); - } - - /* - * Check to see whether the zone has any devices configured. - */ - if (zonecfg_setdevent(handle) != Z_OK) { - zonecfg_fini_handle(handle); - lxs_err(gettext("zonecfg provided an invalid XML file")); - } - - if (zonecfg_getdevent(handle, &devtab) == Z_OK) { - zonecfg_fini_handle(handle); - lxs_err(gettext("lx zones do not support added devices")); - } - - /* * Check to see whether the zone has hostid emulation enabled. */ if (zonecfg_get_hostid(handle, hostidp, sizeof (hostidp)) == Z_OK) { diff --git a/usr/src/lib/libc/inc/thr_uberdata.h b/usr/src/lib/libc/inc/thr_uberdata.h index de0d4a6b05..1bb08d69b2 100644 --- a/usr/src/lib/libc/inc/thr_uberdata.h +++ b/usr/src/lib/libc/inc/thr_uberdata.h @@ -944,6 +944,7 @@ typedef struct uberdata { robust_t **robustlocks; /* table of registered robust locks */ robust_t *robustlist; /* list of registered robust locks */ char *progname; /* the basename of the program, from argv[0] */ + char *ub_broot; /* the root of the native code in the brand */ struct uberdata **tdb_bootstrap; tdb_t tdb; /* thread debug interfaces (for libc_db) */ } uberdata_t; diff --git a/usr/src/lib/libc/port/gen/getauxv.c b/usr/src/lib/libc/port/gen/getauxv.c index 500675719c..4356a01392 100644 --- a/usr/src/lib/libc/port/gen/getauxv.c +++ b/usr/src/lib/libc/port/gen/getauxv.c @@ -24,9 +24,8 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "lint.h" +#include "thr_uberdata.h" #include <libc.h> #include <fcntl.h> #include <stdlib.h> @@ -38,6 +37,7 @@ #include <thread.h> #include <synch.h> #include <atomic.h> +#include <limits.h> static mutex_t auxlock = DEFAULTMUTEX; @@ -59,11 +59,20 @@ _getaux(int type) if (auxb == NULL) { lmutex_lock(&auxlock); if (auxb == NULL) { + uberdata_t *udp = curthread->ul_uberdata; struct stat statb; auxv_t *buf = NULL; + char *path = "/proc/self/auxv"; + char pbuf[PATH_MAX]; int fd; - if ((fd = open("/proc/self/auxv", O_RDONLY)) != -1 && + if (udp->ub_broot != NULL) { + (void) snprintf(pbuf, sizeof (pbuf), + "%s/proc/self/auxv", udp->ub_broot); + path = pbuf; + } + + if ((fd = open(path, O_RDONLY)) != -1 && fstat(fd, &statb) != -1) buf = libc_malloc( statb.st_size + sizeof (auxv_t)); diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index d17f543041..ecbb16fe85 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -3051,6 +3051,7 @@ $endif zone_list; zone_list_datalink; zonept; + zone_get_nroot; zone_remove_datalink; zone_setattr; zone_shutdown; diff --git a/usr/src/lib/libc/port/sys/zone.c b/usr/src/lib/libc/port/sys/zone.c index 182a7f22f7..8cf28c3ccf 100644 --- a/usr/src/lib/libc/port/sys/zone.c +++ b/usr/src/lib/libc/port/sys/zone.c @@ -26,6 +26,7 @@ */ #include "lint.h" +#include "thr_uberdata.h" #include <sys/types.h> #include <sys/syscall.h> #include <sys/zone.h> @@ -244,3 +245,10 @@ zone_list_datalink(zoneid_t zoneid, int *dlnump, datalink_id_t *linkids) { return (syscall(SYS_zone, ZONE_LIST_DATALINK, zoneid, dlnump, linkids)); } + +const char * +zone_get_nroot() +{ + uberdata_t *udp = curthread->ul_uberdata; + return (udp->ub_broot); +} diff --git a/usr/src/lib/libc/port/threads/thr.c b/usr/src/lib/libc/port/threads/thr.c index b5d848449d..6050b03fbd 100644 --- a/usr/src/lib/libc/port/threads/thr.c +++ b/usr/src/lib/libc/port/threads/thr.c @@ -136,6 +136,7 @@ uberdata_t __uberdata = { NULL, /* robustlocks */ NULL, /* robustlist */ NULL, /* progname */ + NULL, /* ub_broot */ NULL, /* __tdb_bootstrap */ { /* tdb */ NULL, /* tdb_sync_addr_hash */ @@ -1219,6 +1220,24 @@ extern void atfork_init(void); extern void __proc64id(void); #endif +static void +init_brandroot(uberdata_t *udp) +{ + Dl_argsinfo_t args; + + udp->ub_broot = NULL; + if (dlinfo(RTLD_SELF, RTLD_DI_ARGSINFO, &args) < 0) + return; + + while (args.dla_auxv->a_type != AT_NULL) { + if (args.dla_auxv->a_type == AT_SUN_BRAND_NROOT) { + udp->ub_broot = args.dla_auxv->a_un.a_ptr; + return; + } + args.dla_auxv++; + } +} + /* * libc_init() is called by ld.so.1 for library initialization. * We perform minimal initialization; enough to work with the main thread. @@ -1255,6 +1274,13 @@ libc_init(void) (void) _atexit(__cleanup); /* + * Every libc, regardless of link map, needs to go through and check its + * aux vectors so as to indicate whether or not this has been given a + * brand root with which we use to qualify various other data. + */ + init_brandroot(udp); + + /* * We keep our uberdata on one of (a) the first alternate link map * or (b) the primary link map. We switch to the primary link map * and stay there once we see it. All intermediate link maps are diff --git a/usr/src/lib/libcurses/screen/setupterm.c b/usr/src/lib/libcurses/screen/setupterm.c index c1f4bdeb04..f67e8751b7 100644 --- a/usr/src/lib/libcurses/screen/setupterm.c +++ b/usr/src/lib/libcurses/screen/setupterm.c @@ -37,8 +37,6 @@ * contributors. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /*LINTLIBRARY*/ #include <stdio.h> @@ -48,6 +46,7 @@ #include <string.h> #include <unistd.h> #include <errno.h> +#include <zone.h> #include "curses_inc.h" #define TERMPATH "/usr/share/lib/terminfo/" @@ -272,9 +271,11 @@ setupterm(char *term, int filenum, int *errret) } if (tfd < 0) { + const char *zroot = zone_get_nroot(); /* /usr/share/lib/terminfo/?/$TERM */ if (snprintf(fname, sizeof (fname), - "%s/%c/%s", TERMPATH, *term, term) >= sizeof (fname)) { + "%s/%s/%c/%s", zroot == NULL ? "" : zroot, TERMPATH, + *term, term) >= sizeof (fname)) { term_errno = TERMINFO_TOO_LONG; goto out_err; } diff --git a/usr/src/lib/libdtrace/common/dt_open.c b/usr/src/lib/libdtrace/common/dt_open.c index ffb2fe9a8f..7edeac8f10 100644 --- a/usr/src/lib/libdtrace/common/dt_open.c +++ b/usr/src/lib/libdtrace/common/dt_open.c @@ -40,6 +40,7 @@ #include <fcntl.h> #include <errno.h> #include <assert.h> +#include <zone.h> #define _POSIX_PTHREAD_SEMANTICS #include <dirent.h> @@ -683,8 +684,8 @@ const dtrace_pattr_t _dtrace_prvdesc = { { DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_COMMON }, }; -const char *_dtrace_defcpp = "/usr/ccs/lib/cpp"; /* default cpp(1) to invoke */ -const char *_dtrace_defld = "/usr/ccs/bin/ld"; /* default ld(1) to invoke */ +const char *_dtrace_defcpp = "/usr/lib/cpp"; /* default cpp(1) to invoke */ +const char *_dtrace_defld = "/usr/bin/ld"; /* default ld(1) to invoke */ const char *_dtrace_libdir = "/usr/lib/dtrace"; /* default library directory */ const char *_dtrace_provdir = "/dev/dtrace/provider"; /* provider directory */ @@ -824,6 +825,8 @@ dt_vopen(int version, int flags, int *errp, dt_provmod_t *provmod = NULL; int i, err; struct rlimit rl; + const char *zroot; + char *libpath = NULL; const dt_intrinsic_t *dinp; const dt_typedef_t *dtyp; @@ -956,11 +959,19 @@ alloc: dtp->dt_provs = calloc(dtp->dt_provbuckets, sizeof (dt_provider_t *)); dt_proc_init(dtp); dtp->dt_vmax = DT_VERS_LATEST; - dtp->dt_cpp_path = strdup(_dtrace_defcpp); + zroot = zone_get_nroot(); + if (zroot != NULL) { + (void) asprintf(&dtp->dt_ld_path, "%s/%s", zroot, + _dtrace_defld); + (void) asprintf(&dtp->dt_cpp_path, "%s/%s", zroot, + _dtrace_defcpp); + } else { + dtp->dt_ld_path = strdup(_dtrace_defld); + dtp->dt_cpp_path = strdup(_dtrace_defcpp); + } dtp->dt_cpp_argv = malloc(sizeof (char *)); dtp->dt_cpp_argc = 1; dtp->dt_cpp_args = 1; - dtp->dt_ld_path = strdup(_dtrace_defld); dtp->dt_provmod = provmod; dtp->dt_vector = vector; dtp->dt_varg = arg; @@ -1305,9 +1316,15 @@ alloc: * compile, and to provide better error reporting (because the full * reporting of compiler errors requires dtrace_open() to succeed). */ - if (dtrace_setopt(dtp, "libdir", _dtrace_libdir) != 0) + if (zroot != NULL) + (void) asprintf(&libpath, "%s/%s", zroot, _dtrace_libdir); + if (dtrace_setopt(dtp, "libdir", + libpath != NULL ? libpath : _dtrace_libdir) != 0) return (set_open_errno(dtp, errp, dtp->dt_errno)); + if (libpath != NULL) + free(libpath); + return (dtp); } diff --git a/usr/src/lib/libproc/common/Pcontrol.c b/usr/src/lib/libproc/common/Pcontrol.c index 751c0c3f8a..bde48d1416 100644 --- a/usr/src/lib/libproc/common/Pcontrol.c +++ b/usr/src/lib/libproc/common/Pcontrol.c @@ -337,10 +337,16 @@ static const ps_ops_t P_live_ops = { void _libproc_init(void) { + const char *root; + _libproc_debug = getenv("LIBPROC_DEBUG") != NULL; _libproc_no_qsort = getenv("LIBPROC_NO_QSORT") != NULL; _libproc_incore_elf = getenv("LIBPROC_INCORE_ELF") != NULL; + if ((root = zone_get_nroot()) != NULL) + (void) snprintf(procfs_path, sizeof (procfs_path), "%s/proc", + root); + (void) sigfillset(&blockable_sigs); (void) sigdelset(&blockable_sigs, SIGKILL); (void) sigdelset(&blockable_sigs, SIGSTOP); diff --git a/usr/src/uts/common/brand/lx/os/lx_brand.c b/usr/src/uts/common/brand/lx/os/lx_brand.c index 76e781159a..c4c0419f31 100644 --- a/usr/src/uts/common/brand/lx/os/lx_brand.c +++ b/usr/src/uts/common/brand/lx/os/lx_brand.c @@ -95,6 +95,8 @@ static int lx_elfexec(struct vnode *vp, struct execa *uap, struct uarg *args, struct intpdata *idata, int level, long *execsz, int setid, caddr_t exec_file, struct cred *cred, int brand_action); +static boolean_t lx_native_exec(uint8_t, const char **); + /* lx brand */ struct brand_ops lx_brops = { lx_init_brand_data, @@ -117,6 +119,7 @@ struct brand_ops lx_brops = { NSIG, lx_exit_with_sig, lx_wait_filter, + lx_native_exec }; struct brand_mach_ops lx_mops = { @@ -1109,6 +1112,16 @@ lx_elfexec(struct vnode *vp, struct execa *uap, struct uarg *args, return (0); } +boolean_t +lx_native_exec(uint8_t osabi, const char **interp) +{ + if (osabi != ELFOSABI_SOLARIS) + return (B_FALSE); + + *interp = "/native"; + return (B_TRUE); +} + int _init(void) { diff --git a/usr/src/uts/common/brand/sn1/sn1_brand.c b/usr/src/uts/common/brand/sn1/sn1_brand.c index 65a7760f63..013926a619 100644 --- a/usr/src/uts/common/brand/sn1/sn1_brand.c +++ b/usr/src/uts/common/brand/sn1/sn1_brand.c @@ -81,6 +81,7 @@ struct brand_ops sn1_brops = { NSIG, NULL, NULL, + NULL }; #ifdef sparc diff --git a/usr/src/uts/common/brand/sngl/sngl_brand.c b/usr/src/uts/common/brand/sngl/sngl_brand.c index b0d658a1d0..cb4e8bd0c6 100644 --- a/usr/src/uts/common/brand/sngl/sngl_brand.c +++ b/usr/src/uts/common/brand/sngl/sngl_brand.c @@ -83,6 +83,7 @@ struct brand_ops sngl_brops = { NSIG, NULL, NULL, + NULL }; #ifdef __amd64 diff --git a/usr/src/uts/common/brand/solaris10/s10_brand.c b/usr/src/uts/common/brand/solaris10/s10_brand.c index 23ba010af7..e6b97ff5ab 100644 --- a/usr/src/uts/common/brand/solaris10/s10_brand.c +++ b/usr/src/uts/common/brand/solaris10/s10_brand.c @@ -86,6 +86,7 @@ struct brand_ops s10_brops = { S10_NSIG, NULL, NULL, + NULL }; #ifdef sparc diff --git a/usr/src/uts/common/exec/elf/elf.c b/usr/src/uts/common/exec/elf/elf.c index 749f18ebbf..dbea4d0fde 100644 --- a/usr/src/uts/common/exec/elf/elf.c +++ b/usr/src/uts/common/exec/elf/elf.c @@ -255,7 +255,7 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap, caddr_t bssbase = 0; caddr_t brkbase = 0; size_t brksize = 0; - ssize_t dlnsize; + ssize_t dlnsize, nsize = 0; aux_entry_t *aux; int error; ssize_t resid; @@ -345,14 +345,40 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap, #endif /* _LP64 */ /* - * We delay invoking the brand callback until we've figured out - * what kind of elf binary we're trying to run, 32-bit or 64-bit. - * We do this because now the brand library can just check - * args->to_model to see if the target is 32-bit or 64-bit without - * having do duplicate all the code above. + * We delay invoking the brand callback until we've figured out what + * kind of elf binary we're trying to run, 32-bit or 64-bit. We do this + * because now the brand library can just check args->to_model to see if + * the target is 32-bit or 64-bit without having do duplicate all the + * code above. + * + * We also give the brand a chance to indicate that based on the ELF + * OSABI of the target binary it should become unbranded and optionally + * indicate that it should be treated as existing in a specific prefix. + * + * Note that if a brand opts to go down this route it does not actually + * end up being debranded. In other words, future programs that exec + * will still be considered for branding unless this escape hatch is + * used. Consider the case of lx brand for example. If a user runs + * /native/usr/sbin/dtrace -c /bin/ls, the isaexec and normal executable + * of DTrace that's in /native will take this escape hatch and be run + * and interpreted using the normal system call table; however, the + * execution of a non-illumos binary in the form of /bin/ls will still + * be branded and be subject to all of the normal actions of the brand. */ if ((level < 2) && (brand_action != EBA_NATIVE) && (PROC_IS_BRANDED(p))) { + if (BROP(p)->b_native_exec(ehdrp->e_ident[EI_OSABI], + &args->brand_nroot) == B_TRUE) { + ASSERT(ehdrp->e_ident[EI_OSABI]); + brand_action = EBA_NATIVE; + /* Add one for the trailing '/' in the path */ + if (args->brand_nroot != NULL) + nsize = strlen(args->brand_nroot) + 1; + } + } + + if ((level < 2) && + (brand_action != EBA_NATIVE) && (PROC_IS_BRANDED(p))) { error = BROP(p)->b_elfexec(vp, uap, args, idatap, level + 1, execsz, setid, exec_file, cred, brand_action); @@ -471,6 +497,14 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap, if (args->emulator != NULL) args->auxsize += sizeof (aux_entry_t); + /* + * If this is a native binary that's been given a modified interpreter + * root, inform it that the native system exists at that root. + */ + if (args->brand_nroot != NULL) { + args->auxsize += sizeof (aux_entry_t); + } + if ((brand_action != EBA_NATIVE) && (PROC_IS_BRANDED(p))) { branded = 1; /* @@ -548,17 +582,22 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap, char *p; struct vnode *nvp; - dlnsize = dyphdr->p_filesz; + dlnsize = dyphdr->p_filesz + nsize; if (dlnsize > MAXPATHLEN || dlnsize <= 0) goto bad; + if (nsize != 0) { + bcopy(args->brand_nroot, dlnp, nsize - 1); + dlnp[nsize - 1] = '/'; + } + /* * Read in "interpreter" pathname. */ - if ((error = vn_rdwr(UIO_READ, vp, dlnp, dyphdr->p_filesz, - (offset_t)dyphdr->p_offset, UIO_SYSSPACE, 0, (rlim64_t)0, - CRED(), &resid)) != 0) { + if ((error = vn_rdwr(UIO_READ, vp, dlnp + nsize, + dyphdr->p_filesz, (offset_t)dyphdr->p_offset, UIO_SYSSPACE, + 0, (rlim64_t)0, CRED(), &resid)) != 0) { uprintf("%s: Cannot obtain interpreter pathname\n", exec_file); goto bad; diff --git a/usr/src/uts/common/os/exec.c b/usr/src/uts/common/os/exec.c index d421483279..1d16255cc5 100644 --- a/usr/src/uts/common/os/exec.c +++ b/usr/src/uts/common/os/exec.c @@ -1628,8 +1628,9 @@ stk_copyin(execa_t *uap, uarg_t *args, intpdata_t *intp, void **auxvpp) args->ne = args->na - argc; /* - * Add AT_SUN_PLATFORM, AT_SUN_EXECNAME, AT_SUN_BRANDNAME, and - * AT_SUN_EMULATOR strings, as well as AT_RANDOM array, to the stack. + * Add AT_SUN_PLATFORM, AT_SUN_EXECNAME, AT_SUN_BRANDNAME, + * AT_SUN_BRAND_NROOT, and AT_SUN_EMULATOR strings, as well as AT_RANDOM + * array, to the stack. */ if (auxvpp != NULL && *auxvpp != NULL) { if ((error = stk_add(args, platform, UIO_SYSSPACE)) != 0) @@ -1664,6 +1665,11 @@ stk_copyin(execa_t *uap, uarg_t *args, intpdata_t *intp, void **auxvpp) if ((error = stk_byte_add(args, rdata, sizeof (rdata))) != 0) return (error); + + if (args->brand_nroot != NULL && + (error = stk_add(args, args->brand_nroot, + UIO_SYSSPACE)) != 0) + return (error); } /* @@ -1784,6 +1790,10 @@ stk_copyout(uarg_t *args, char *usrstack, void **auxvpp, user_t *up) ADDAUX(*a, AT_SUN_EMULATOR, (long)&ustrp[*--offp]) ADDAUX(*a, AT_RANDOM, (long)&ustrp[*--offp]) + if (args->brand_nroot != NULL) { + ADDAUX(*a, + AT_SUN_BRAND_NROOT, (long)&ustrp[*--offp]) + } } else { auxv32_t **a = (auxv32_t **)auxvpp; ADDAUX(*a, @@ -1797,6 +1807,10 @@ stk_copyout(uarg_t *args, char *usrstack, void **auxvpp, user_t *up) ADDAUX(*a, AT_SUN_EMULATOR, (int)(uintptr_t)&ustrp[*--offp]) ADDAUX(*a, AT_RANDOM, (int)(uintptr_t)&ustrp[*--offp]) + if (args->brand_nroot != NULL) { + ADDAUX(*a, AT_SUN_BRAND_NROOT, + (int)(uintptr_t)&ustrp[*--offp]) + } } } diff --git a/usr/src/uts/common/sys/auxv.h b/usr/src/uts/common/sys/auxv.h index d0b83e10c8..b7db2c6454 100644 --- a/usr/src/uts/common/sys/auxv.h +++ b/usr/src/uts/common/sys/auxv.h @@ -201,6 +201,7 @@ extern uint_t getisax(uint32_t *, uint_t); #define AT_SUN_BRAND_AUX1 2020 #define AT_SUN_BRAND_AUX2 2021 #define AT_SUN_BRAND_AUX3 2022 +#define AT_SUN_BRAND_NROOT 2024 /* * Note that 2023 is reserved for the AT_SUN_HWCAP2 word defined above. diff --git a/usr/src/uts/common/sys/brand.h b/usr/src/uts/common/sys/brand.h index dfbbd870db..9436c4e145 100644 --- a/usr/src/uts/common/sys/brand.h +++ b/usr/src/uts/common/sys/brand.h @@ -128,6 +128,7 @@ struct brand_ops { int b_nsig; void (*b_exit_with_sig)(proc_t *, sigqueue_t *, void *); boolean_t (*b_wait_filter)(proc_t *, proc_t *); + boolean_t (*b_native_exec)(uint8_t, const char **); }; /* diff --git a/usr/src/uts/common/sys/exec.h b/usr/src/uts/common/sys/exec.h index 85808e1834..8509d51a9f 100644 --- a/usr/src/uts/common/sys/exec.h +++ b/usr/src/uts/common/sys/exec.h @@ -106,6 +106,7 @@ typedef struct uarg { vnode_t *ex_vp; char *emulator; char *brandname; + const char *brand_nroot; char *auxp_auxflags; /* addr of auxflags auxv on the user stack */ char *auxp_brand; /* address of first brand auxv on user stack */ cred_t *pfcred; |