Skip to content

Commit

Permalink
c18n: Add ELF note controls for compartmentalisation
Browse files Browse the repository at this point in the history
And teach readelf about it.
  • Loading branch information
dpgao committed Mar 21, 2024
1 parent a7d415a commit e7ddc4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contrib/elftoolchain/readelf/readelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3814,6 +3814,8 @@ static struct flag_desc note_feature_ctl_flags[] = {
{ NT_FREEBSD_FCTL_LA48, "LA48" },
{ NT_FREEBSD_FCTL_CHERI_REVOKE_DISABLE, "CHERI_REVOKE_DISABLE" },
{ NT_FREEBSD_FCTL_CHERI_REVOKE_ENABLE, "CHERI_REVOKE_ENABLE" },
{ NT_FREEBSD_FCTL_CHERI_C18N_DISABLE, "CHERI_C18N_DISABLE" },
{ NT_FREEBSD_FCTL_CHERI_C18N_ENABLE, "CHERI_C18N_ENABLE" },
{ 0, NULL }
};

Expand Down
6 changes: 6 additions & 0 deletions sys/kern/imgact_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,11 +1849,17 @@ __elfN(freebsd_copyout_auxargs)(struct image_params *imgp, uintcap_t base)
* ELF_BSDF_CHERI_C18N tells the runtime linker to enable library-based
* compartmentalisation.
*
* Precedence: procctl, ELF note.
* In case of conflicting flags, disable wins.
*/
if ((imgp->proc->p_flag2 & P2_CHERI_C18N_MASK) != 0) {
if ((imgp->proc->p_flag2 & P2_CHERI_C18N_DISABLE) == 0)
bsdflags |= ELF_BSDF_CHERI_C18N;
} else if ((imgp->proc->p_fctl0 &
NT_FREEBSD_FCTL_CHERI_C18N_MASK) != 0) {
if ((imgp->proc->p_fctl0 &
NT_FREEBSD_FCTL_CHERI_C18N_DISABLE) == 0)
bsdflags |= ELF_BSDF_CHERI_C18N;
}
#endif
#if defined(__ELF_CHERI) && defined(CHERI_CAPREVOKE)
Expand Down
4 changes: 4 additions & 0 deletions sys/sys/elf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,14 @@ typedef struct {
#define NT_FREEBSD_FCTL_WXNEEDED 0x00000008
#define NT_FREEBSD_FCTL_LA48 0x00000010
#define NT_FREEBSD_FCTL_CHERI_REVOKE_DISABLE 0x00000020 /* was ASG_DISABLE */
#define NT_FREEBSD_FCTL_CHERI_C18N_DISABLE 0x20000000
#define NT_FREEBSD_FCTL_CHERI_C18N_ENABLE 0x40000000
#define NT_FREEBSD_FCTL_CHERI_REVOKE_ENABLE 0x80000000

#define NT_FREEBSD_FCTL_CHERI_REVOKE_MASK \
(NT_FREEBSD_FCTL_CHERI_REVOKE_DISABLE | NT_FREEBSD_FCTL_CHERI_REVOKE_ENABLE)
#define NT_FREEBSD_FCTL_CHERI_C18N_MASK \
(NT_FREEBSD_FCTL_CHERI_C18N_DISABLE | NT_FREEBSD_FCTL_CHERI_C18N_ENABLE)

/* Values for n_type. Used in core files. */
#define NT_PRSTATUS 1 /* Process status. */
Expand Down
4 changes: 4 additions & 0 deletions usr.bin/elfctl/elfctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ static struct ControlFeatures featurelist[] = {
"Force Enable CHERI revocation" },
{ "nocherirevoke", NT_FREEBSD_FCTL_CHERI_REVOKE_DISABLE,
"Force Disable CHERI revocation" },
{ "cheric18n", NT_FREEBSD_FCTL_CHERI_C18N_ENABLE,
"Force Enable CHERI library-based compartmentalisation" },
{ "nocheric18n", NT_FREEBSD_FCTL_CHERI_C18N_DISABLE,
"Force Disable CHERI library-based compartmentalisation" },
};

static struct option long_opts[] = {
Expand Down

0 comments on commit e7ddc4a

Please sign in to comment.