Skip to content

Commit

Permalink
OS-4119 lxbrand panic when running native perl inside lx zone
Browse files Browse the repository at this point in the history
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
  • Loading branch information
pfmooney committed Apr 8, 2015
1 parent cc226f2 commit 94e5dec
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 35 deletions.
8 changes: 4 additions & 4 deletions usr/src/uts/common/brand/lx/os/lx_brand.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ uint64_t lx_maxstack64 = LX_MAXSTACK64;

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);
caddr_t exec_file, struct cred *cred, int *brand_action);

static boolean_t lx_native_exec(uint8_t, const char **);
static uint32_t lx_map32limit(proc_t *);
Expand Down Expand Up @@ -1351,10 +1351,10 @@ restoreexecenv(struct execenv *ep, stack_t *sp)
}

extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);

extern int elf32exec(struct vnode *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);

/*
* Exec routine called by elfexec() to load either 32-bit or 64-bit Linux
Expand All @@ -1363,7 +1363,7 @@ extern int elf32exec(struct vnode *, execa_t *, uarg_t *, intpdata_t *, int,
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)
caddr_t exec_file, struct cred *cred, int *brand_action)
{
int error;
vnode_t *nvp;
Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/brand/sn1/sn1_brand.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void sn1_forklwp(klwp_t *, klwp_t *);
void sn1_freelwp(klwp_t *);
void sn1_lwpexit(klwp_t *);
int sn1_elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);

/* sn1 brand */
struct brand_ops sn1_brops = {
Expand Down Expand Up @@ -249,7 +249,7 @@ sn1_init_brand_data(zone_t *zone)
int
sn1_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
int brand_action)
int *brand_action)
{
return (brand_solaris_elfexec(vp, uap, args, idatap, level, execsz,
setid, exec_file, cred, brand_action, &sn1_brand, SN1_BRANDNAME,
Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/brand/sngl/sngl_brand.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void sngl_forklwp(klwp_t *, klwp_t *);
void sngl_freelwp(klwp_t *);
void sngl_lwpexit(klwp_t *);
int sngl_elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);

/* SNGL brand */
struct brand_ops sngl_brops = {
Expand Down Expand Up @@ -233,7 +233,7 @@ sngl_init_brand_data(zone_t *zone)
int
sngl_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
int brand_action)
int *brand_action)
{
return (brand_solaris_elfexec(vp, uap, args, idatap, level, execsz,
setid, exec_file, cred, brand_action, &sngl_brand, SNGL_BRANDNAME,
Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/brand/solaris10/s10_brand.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void s10_forklwp(klwp_t *, klwp_t *);
void s10_freelwp(klwp_t *);
void s10_lwpexit(klwp_t *);
int s10_elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);
void s10_sigset_native_to_s10(sigset_t *);
void s10_sigset_s10_to_native(sigset_t *);

Expand Down Expand Up @@ -418,7 +418,7 @@ s10_init_brand_data(zone_t *zone)
int
s10_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
int brand_action)
int *brand_action)
{
return (brand_solaris_elfexec(vp, uap, args, idatap, level, execsz,
setid, exec_file, cred, brand_action, &s10_brand, S10_BRANDNAME,
Expand Down
5 changes: 3 additions & 2 deletions usr/src/uts/common/exec/aout/aout.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
* Copyright 2015, Joyent, Inc.
*/

#include <sys/types.h>
Expand Down Expand Up @@ -54,7 +55,7 @@

static int aoutexec(vnode_t *vp, execa_t *uap, uarg_t *args,
intpdata_t *idatap, int level, long *execsz, int setid,
caddr_t exec_file, cred_t *cred, int brand_action);
caddr_t exec_file, cred_t *cred, int *brand_action);
static int get_aout_head(struct vnode **vpp, struct exdata *edp, long *execsz,
int *isdyn);
static int aoutcore(vnode_t *vp, proc_t *pp, cred_t *credp,
Expand Down Expand Up @@ -130,7 +131,7 @@ _info(struct modinfo *modinfop)
static int
aoutexec(vnode_t *vp, struct execa *uap, struct uarg *args,
struct intpdata *idatap, int level, long *execsz, int setid,
caddr_t exec_file, cred_t *cred, int brand_action)
caddr_t exec_file, cred_t *cred, int *brand_action)
{
auxv32_t auxflags_auxv32;
int error;
Expand Down
14 changes: 7 additions & 7 deletions usr/src/uts/common/exec/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mapexec_brand(vnode_t *vp, uarg_t *args, Ehdr *ehdr, Addr *uphdr_vaddr,
int
elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
int brand_action)
int *brand_action)
{
caddr_t phdrbase = NULL;
caddr_t bssbase = 0;
Expand Down Expand Up @@ -405,19 +405,19 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
* 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))) {
(*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;
*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))) {
(*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);
Expand Down Expand Up @@ -544,7 +544,7 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
args->auxsize += sizeof (aux_entry_t);
}

if ((brand_action != EBA_NATIVE) && (PROC_IS_BRANDED(p))) {
if ((*brand_action != EBA_NATIVE) && (PROC_IS_BRANDED(p))) {
branded = 1;
/*
* We will be adding 5 entries to the aux vectors. One for
Expand Down Expand Up @@ -842,7 +842,7 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
* malicious user within the zone from crafting a wrapper to
* run native suid commands with unsecure libraries interposed.
*/
if ((brand_action == EBA_NATIVE) && (PROC_IS_BRANDED(p) &&
if ((*brand_action == EBA_NATIVE) && (PROC_IS_BRANDED(p) &&
(setid &= ~EXECSETID_SETID) != 0))
auxf &= ~AF_SUN_SETUGID;

Expand Down Expand Up @@ -2333,7 +2333,7 @@ static struct modlexec modlexec = {
extern int elf32exec(vnode_t *vp, execa_t *uap, uarg_t *args,
intpdata_t *idatap, int level, long *execsz,
int setid, caddr_t exec_file, cred_t *cred,
int brand_action);
int *brand_action);
extern int elf32core(vnode_t *vp, proc_t *p, cred_t *credp,
rlim64_t rlimit, int sig, core_content_t content);

Expand Down
8 changes: 5 additions & 3 deletions usr/src/uts/common/exec/intp/intp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012 Milan Jurik. All rights reserved.
* Copyright 2015, Joyent, Inc.
*/

/* Copyright (c) 1988 AT&T */
Expand Down Expand Up @@ -53,7 +54,7 @@
#include <sys/modctl.h>

extern int intpexec(struct vnode *, struct execa *, struct uarg *,
struct intpdata *, int, long *, int, caddr_t, struct cred *, int);
struct intpdata *, int, long *, int, caddr_t, struct cred *, int *);

static struct execsw esw = {
intpmagicstr,
Expand Down Expand Up @@ -169,7 +170,7 @@ intpexec(
int setid,
caddr_t exec_file,
struct cred *cred,
int brand_action)
int *brand_action)
{
_NOTE(ARGUNUSED(brand_action))
vnode_t *nvp;
Expand All @@ -180,6 +181,7 @@ intpexec(
char *opath;
char devfd[19]; /* 32-bit int fits in 10 digits + 8 for "/dev/fd/" */
int fd = -1;
int custom_action = EBA_NONE;

if (level) { /* Can't recurse */
error = ENOEXEC;
Expand Down Expand Up @@ -228,7 +230,7 @@ intpexec(
}

error = gexec(&nvp, uap, args, &idata, ++level, execsz, exec_file, cred,
EBA_NONE);
&custom_action);

if (!error) {
/*
Expand Down
3 changes: 2 additions & 1 deletion usr/src/uts/common/exec/java/java.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2015, Joyent, Inc.
*/

/*
Expand Down Expand Up @@ -85,7 +86,7 @@ char *jexec_arg = "-jar";
static int
javaexec(vnode_t *vp, struct execa *uap, struct uarg *args,
struct intpdata *idatap, int level, long *execsz, int setid,
caddr_t execfile, cred_t *cred, int brand_action)
caddr_t execfile, cred_t *cred, int *brand_action)
{
struct intpdata idata;
int error;
Expand Down
5 changes: 3 additions & 2 deletions usr/src/uts/common/exec/shbin/shbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2015, Joyent, Inc.
*/

#include <sys/types.h>
Expand Down Expand Up @@ -58,7 +59,7 @@ shbinexec(
int setid,
caddr_t exec_file,
struct cred *cred,
int brand_action);
int *brand_action);

#define SHBIN_CNTL(x) ((x)&037)
#define SHBINMAGIC_LEN 4
Expand Down Expand Up @@ -162,7 +163,7 @@ shbinexec(
int setid,
caddr_t exec_file,
struct cred *cred,
int brand_action)
int *brand_action)
{
_NOTE(ARGUNUSED(brand_action))
vnode_t *nvp;
Expand Down
2 changes: 1 addition & 1 deletion usr/src/uts/common/os/brand.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ restoreexecenv(struct execenv *ep, stack_t *sp)
int
brand_solaris_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args,
intpdata_t *idatap, int level, long *execsz, int setid, caddr_t exec_file,
cred_t *cred, int brand_action, struct brand *pbrand, char *bname,
cred_t *cred, int *brand_action, struct brand *pbrand, char *bname,
char *brandlib, char *brandlib32)
{

Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/os/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ exec_common(const char *fname, const char **argp, const char **envp,
}

if ((error = gexec(&vp, &ua, &args, NULL, 0, &execsz,
exec_file, p->p_cred, brand_action)) != 0) {
exec_file, p->p_cred, &brand_action)) != 0) {
if (brandme) {
BROP(p)->b_freelwp(lwp);
brand_clearbrand(p);
Expand Down Expand Up @@ -565,7 +565,7 @@ gexec(
long *execsz,
caddr_t exec_file,
struct cred *cred,
int brand_action)
int *brand_action)
{
struct vnode *vp, *execvp = NULL;
proc_t *pp = ttoproc(curthread);
Expand Down
4 changes: 2 additions & 2 deletions usr/src/uts/common/sys/brand.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct brand_ops {
int (*b_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);
struct cred *cred, int *brand_action);
void (*b_sigset_native_to_brand)(sigset_t *);
void (*b_sigset_brand_to_native)(sigset_t *);
void (*b_psig_to_proc)(proc_t *, kthread_t *, int);
Expand Down Expand Up @@ -244,7 +244,7 @@ extern int brand_solaris_cmd(int, uintptr_t, uintptr_t, uintptr_t,
extern void brand_solaris_copy_procdata(proc_t *, proc_t *,
struct brand *);
extern int brand_solaris_elfexec(vnode_t *, execa_t *, uarg_t *,
intpdata_t *, int, long *, int, caddr_t, cred_t *, int,
intpdata_t *, int, long *, int, caddr_t, cred_t *, int *,
struct brand *, char *, char *, char *);
extern void brand_solaris_exec(struct brand *);
extern int brand_solaris_fini(char **, struct modlinkage *,
Expand Down
10 changes: 5 additions & 5 deletions usr/src/uts/common/sys/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/* All Rights Reserved */

/*
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
* Copyright 2015, Joyent, Inc.
*/

#ifndef _SYS_EXEC_H
Expand Down Expand Up @@ -180,7 +180,7 @@ struct execsw {
int (*exec_func)(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);
struct cred *cred, int *brand_action);
int (*exec_core)(struct vnode *vp, struct proc *p,
struct cred *cred, rlim64_t rlimit, int sig,
core_content_t content);
Expand Down Expand Up @@ -218,7 +218,7 @@ extern int exec_common(const char *fname, const char **argp,
const char **envp, int brand_action);
extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args,
struct intpdata *idata, int level, long *execsz, caddr_t exec_file,
struct cred *cred, int brand_action);
struct cred *cred, int *brand_action);
extern struct execsw *allocate_execsw(char *name, char *magic,
size_t magic_size);
extern struct execsw *findexecsw(char *magic);
Expand All @@ -243,15 +243,15 @@ extern void exec_set_sp(size_t);
* when compiling the 32-bit compatability elf code in the elfexec module.
*/
extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);
extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *,
intptr_t *, caddr_t, char **, caddr_t *, caddr_t *, size_t *,
uintptr_t *, uintptr_t *);
#endif /* !_ELF32_COMPAT */

#if defined(_LP64)
extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
long *, int, caddr_t, cred_t *, int);
long *, int, caddr_t, cred_t *, int *);
extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *,
intptr_t *, caddr_t, char **, caddr_t *, caddr_t *, size_t *,
uintptr_t *, uintptr_t *);
Expand Down

0 comments on commit 94e5dec

Please sign in to comment.