kern.elf{32,64}.pie_base sysctl: enforce page alignment.

Requested by:	rstone
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
This commit is contained in:
kib 2019-09-21 20:03:17 +00:00
parent 1629aaf0f7
commit 5fcd6fab09

View File

@ -136,8 +136,24 @@ SYSCTL_INT(_kern_elf32, OID_AUTO, read_exec, CTLFLAG_RW, &i386_read_exec, 0,
#endif
static u_long __elfN(pie_base) = ET_DYN_LOAD_ADDR;
SYSCTL_ULONG(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, pie_base,
CTLFLAG_RWTUN, &__elfN(pie_base), 0,
static int
sysctl_pie_base(SYSCTL_HANDLER_ARGS)
{
u_long val;
int error;
val = __elfN(pie_base);
error = sysctl_handle_long(oidp, &val, 0, req);
if (error != 0 || req->newptr == NULL)
return (error);
if ((val & PAGE_MASK) != 0)
return (EINVAL);
__elfN(pie_base) = val;
return (0);
}
SYSCTL_PROC(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, pie_base,
CTLTYPE_ULONG | CTLFLAG_MPSAFE | CTLFLAG_RW, NULL, 0,
sysctl_pie_base, "LU",
"PIE load base without randomization");
SYSCTL_NODE(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, aslr, CTLFLAG_RW, 0,