From 944cf37bb581e4e7c92823def2f0ebfa524d379f Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sun, 9 Feb 2020 12:10:37 +0000 Subject: [PATCH] Add AT_BSDFLAGS auxv entry. The intent is to provide bsd-specific flags relevant to interpreter and C runtime. I did not want to reuse AT_FLAGS which is common ELF auxv entry. Use bsdflags to report kernel support for sigfastblock(2). This allows rtld and libthr to safely infer the syscall presence without SIGSYS. The tunable kern.elf{32,64}.sigfastblock blocks reporting. Tested by: pho Disscussed with: cem, emaste, jilles Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D12773 --- sys/kern/imgact_elf.c | 7 +++++++ sys/sys/elf_common.h | 4 +++- usr.bin/procstat/procstat_auxv.c | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index b59f8c85ea1..4af4a5de96a 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -183,6 +183,11 @@ SYSCTL_INT(ASLR_NODE_OID, OID_AUTO, stack_gap, CTLFLAG_RW, __XSTRING(__CONCAT(ELF, __ELF_WORD_SIZE)) ": maximum percentage of main stack to waste on a random gap"); +static int __elfN(sigfastblock) = 1; +SYSCTL_INT(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, sigfastblock, + CTLFLAG_RWTUN, &__elfN(sigfastblock), 0, + "enable sigfastblock for new processes"); + static Elf_Brandinfo *elf_brand_list[MAX_BRANDS]; #define aligned(a, t) (rounddown2((u_long)(a), sizeof(t)) == (u_long)(a)) @@ -1366,6 +1371,8 @@ __elfN(freebsd_copyout_auxargs)(struct image_params *imgp, uintptr_t base) AUXARGS_ENTRY(pos, AT_HWCAP, *imgp->sysent->sv_hwcap); if (imgp->sysent->sv_hwcap2 != NULL) AUXARGS_ENTRY(pos, AT_HWCAP2, *imgp->sysent->sv_hwcap2); + AUXARGS_ENTRY(pos, AT_BSDFLAGS, __elfN(sigfastblock) ? + ELF_BSDF_SIGFASTBLK : 0); AUXARGS_ENTRY(pos, AT_NULL, 0); free(imgp->auxargs, M_TEMP); diff --git a/sys/sys/elf_common.h b/sys/sys/elf_common.h index daf961867e5..643ad61ac82 100644 --- a/sys/sys/elf_common.h +++ b/sys/sys/elf_common.h @@ -954,8 +954,9 @@ typedef struct { #define AT_EHDRFLAGS 24 /* e_flags field from elf hdr */ #define AT_HWCAP 25 /* CPU feature flags. */ #define AT_HWCAP2 26 /* CPU feature flags 2. */ +#define AT_BSDFLAGS 27 /* ELF BSD Flags. */ -#define AT_COUNT 27 /* Count of defined aux entry types. */ +#define AT_COUNT 28 /* Count of defined aux entry types. */ /* * Relocation types. @@ -1456,5 +1457,6 @@ typedef struct { #define R_X86_64_TLSDESC 36 #define R_X86_64_IRELATIVE 37 +#define ELF_BSDF_SIGFASTBLK 0x0001 /* Kernel supports fast sigblock */ #endif /* !_SYS_ELF_COMMON_H_ */ diff --git a/usr.bin/procstat/procstat_auxv.c b/usr.bin/procstat/procstat_auxv.c index 785896d0c6a..911132dc79e 100644 --- a/usr.bin/procstat/procstat_auxv.c +++ b/usr.bin/procstat/procstat_auxv.c @@ -196,6 +196,12 @@ procstat_auxv(struct procstat *procstat, struct kinfo_proc *kipp) xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_HWCAP2/%#lx}\n", prefix, "AT_HWCAP2", (u_long)auxv[i].a_un.a_val); break; +#endif +#ifdef AT_BSDFLAGS + case AT_BSDFLAGS: + xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_BSDFLAGS/%#lx}\n", + prefix, "AT_BSDFLAGS", (u_long)auxv[i].a_un.a_val); + break; #endif default: xo_emit("{dw:/%s}{Lw:/%16ld/%ld}{:UNKNOWN/%#lx}\n",