Skip to content

Commit

Permalink
Add a link to the Elf_Brandinfo into the struc proc.
Browse files Browse the repository at this point in the history
To allow the ABI to make a dicision based on the Brandinfo add a link
to the Elf_Brandinfo into the struct proc. Add a note that the high 8 bits
of Elf_Brandinfo flags is private to the ABI.

Note to MFC: it breaks KBI.

Reviewed by:		kib, markj
Differential Revision:	https://reviews.freebsd.org/D30918
MFC after:		2 weeks
  • Loading branch information
lemul committed Jun 29, 2021
1 parent f77697d commit 615f22b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions sys/kern/imgact_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp)
map = &vmspace->vm_map;

imgp->proc->p_sysent = sv;
imgp->proc->p_elf_brandinfo = brand_info;

maxv = vm_map_max(map) - lim_max(td, RLIMIT_STACK);
if (et_dyn_addr == ET_DYN_ADDR_RAND) {
Expand Down
4 changes: 4 additions & 0 deletions sys/kern/kern_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p,
#endif
int error, i, orig_osrel;
uint32_t orig_fctl0;
Elf_Brandinfo *orig_brandinfo;
static const char fexecv_proc_title[] = "(fexecv)";

imgp = &image_params;
Expand Down Expand Up @@ -427,6 +428,7 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p,
oldcred = p->p_ucred;
orig_osrel = p->p_osrel;
orig_fctl0 = p->p_fctl0;
orig_brandinfo = p->p_elf_brandinfo;

#ifdef MAC
error = mac_execve_enter(imgp, mac_p);
Expand Down Expand Up @@ -499,6 +501,7 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p,

imgp->proc->p_osrel = 0;
imgp->proc->p_fctl0 = 0;
imgp->proc->p_elf_brandinfo = NULL;

/*
* Implement image setuid/setgid.
Expand Down Expand Up @@ -894,6 +897,7 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p,
if (error != 0) {
p->p_osrel = orig_osrel;
p->p_fctl0 = orig_fctl0;
p->p_elf_brandinfo = orig_brandinfo;
}

if (imgp->firstpage != NULL)
Expand Down
4 changes: 2 additions & 2 deletions sys/kern/kern_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ _Static_assert(offsetof(struct proc, p_filemon) == 0x3b8,
"struct proc KBI p_filemon");
_Static_assert(offsetof(struct proc, p_comm) == 0x3d0,
"struct proc KBI p_comm");
_Static_assert(offsetof(struct proc, p_emuldata) == 0x4b0,
_Static_assert(offsetof(struct proc, p_emuldata) == 0x4b8,
"struct proc KBI p_emuldata");
#endif
#ifdef __i386__
Expand All @@ -120,7 +120,7 @@ _Static_assert(offsetof(struct proc, p_filemon) == 0x268,
"struct proc KBI p_filemon");
_Static_assert(offsetof(struct proc, p_comm) == 0x27c,
"struct proc KBI p_comm");
_Static_assert(offsetof(struct proc, p_emuldata) == 0x308,
_Static_assert(offsetof(struct proc, p_emuldata) == 0x30c,
"struct proc KBI p_emuldata");
#endif

Expand Down
1 change: 1 addition & 0 deletions sys/sys/imgact_elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct {
Elf_Brandnote *brand_note;
boolean_t (*header_supported)(struct image_params *,
int32_t *, uint32_t *);
/* High 8 bits of flags is private to the ABI */
#define BI_CAN_EXEC_DYN 0x0001
#define BI_BRAND_NOTE 0x0002 /* May have note.ABI-tag section. */
#define BI_BRAND_NOTE_MANDATORY 0x0004 /* Must have note.ABI-tag section. */
Expand Down
2 changes: 2 additions & 0 deletions sys/sys/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ struct proc {
our subtree. */
uint16_t p_elf_machine; /* (x) ELF machine type */
uint64_t p_elf_flags; /* (x) ELF flags */
void *p_elf_brandinfo; /* (x) Elf_Brandinfo, NULL for
non ELF binaries. */
/* End area that is copied on creation. */
#define p_endcopy p_xexit

Expand Down

0 comments on commit 615f22b

Please sign in to comment.