Skip to content

Commit 0bb437a

Browse files
auREAXgraydon
authored andcommitted
Add GRSecurity compatibility with --enable-pax-marks configure flag; add GRSecurity autodetection code to configure.
1 parent 5585514 commit 0bb437a

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

configure

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ opt manage-submodules 1 "let the build manage the git submodules"
295295
opt mingw-cross 0 "cross-compile for win32 using mingw"
296296
opt clang 0 "prefer clang to gcc for building the runtime"
297297
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
298+
opt pax-marks 0 "apply PaX markings to rustc binaries (required for GRSecurity/PaX-patched kernels)"
298299
valopt prefix "/usr/local" "set installation prefix"
299300
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
300301
valopt llvm-root "" "set LLVM root"
@@ -343,6 +344,8 @@ probe CFG_PDFLATEX pdflatex
343344
probe CFG_XETEX xetex
344345
probe CFG_LUATEX luatex
345346
probe CFG_NODE nodejs node
347+
probe CFG_PAXCTL paxctl /sbin/paxctl
348+
probe CFG_ZCAT zcat
346349

347350
if [ ! -z "$CFG_PANDOC" ]
348351
then
@@ -354,6 +357,52 @@ then
354357
fi
355358
fi
356359

360+
if [ "$CFG_OSTYPE" = "unknown-linux-gnu" ]
361+
then
362+
if [ ! -z "$CFG_ENABLE_PAX_MARKS" -a -z "$CFG_PAXCTL" ]
363+
then
364+
err "enabled PaX markings but no paxctl binary found"
365+
fi
366+
367+
if [ -z "$CFG_DISABLE_PAX_MARKS" ]
368+
then
369+
# GRSecurity/PaX detection. This can be very flaky.
370+
GRSEC_DETECTED=
371+
372+
# /dev/grsec only exists if CONFIG_GRKERNSEC_NO_RBAC is not set.
373+
# /proc is normally only available to root and users in the CONFIG_GRKERNSEC_PROC_GID group,
374+
# and /proc/sys/kernel/grsecurity is not available if ÇONFIG_GRKERNSEC_SYSCTL is not set.
375+
if [ -e /dev/grsec -o -d /proc/sys/kernel/grsecurity ]
376+
then
377+
GRSEC_DETECTED=1
378+
# /proc/config.gz is normally only available to root, and only if CONFIG_IKCONFIG_PROC has been set.
379+
elif [ -r /proc/config.gz -a ! -z "$CFG_ZCAT" ]
380+
then
381+
if "$CFG_ZCAT" /proc/config.gz | grep --quiet "CONFIG_GRKERNSEC=y"
382+
then
383+
GRSEC_DETECTED=1
384+
fi
385+
# Flaky.
386+
elif grep --quiet grsec /proc/version
387+
then
388+
GRSEC_DETECTED=1
389+
fi
390+
391+
if [ ! -z "$GRSEC_DETECTED" ]
392+
then
393+
step_msg "GRSecurity: yes"
394+
if [ ! -z "$CFG_PAXCTL" ]
395+
then
396+
CFG_ENABLE_PAX_MARKS=1
397+
else
398+
warn "GRSecurity kernel detected but no paxctl binary found: not setting CFG_ENABLE_PAX_MARKS"
399+
fi
400+
else
401+
step_msg "GRSecurity: no"
402+
fi
403+
fi
404+
fi
405+
357406
if [ ! -z "$CFG_ENABLE_LOCAL_RUST" ]
358407
then
359408
if [ ! -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc ]
@@ -699,6 +748,12 @@ putvar CFG_C_COMPILER
699748
putvar CFG_LIBDIR
700749
putvar CFG_DISABLE_MANAGE_SUBMODULES
701750

751+
if [ ! -z "$CFG_ENABLE_PAX_MARKS" ]
752+
then
753+
putvar CFG_ENABLE_PAX_MARKS
754+
putvar CFG_PAXCTL
755+
fi
756+
702757
if [ ! -z $BAD_PANDOC ]
703758
then
704759
CFG_PANDOC=

mk/stage0.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ifdef CFG_ENABLE_LOCAL_RUST
1212
$(Q)$(S)src/etc/local_stage0.sh $(CFG_HOST_TRIPLE) $(CFG_LOCAL_RUST_ROOT)
1313
else
1414
$(Q)$(S)src/etc/get-snapshot.py $(CFG_HOST_TRIPLE) $(SNAPSHOT_FILE)
15+
ifdef CFG_ENABLE_PAX_MARKS
16+
@$(call E, apply PaX markings: $@)
17+
@"$(CFG_PAXCTL)" -cm "$@"
18+
endif
1519
endif
1620
$(Q)touch $@
1721

mk/target.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \
2929
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
3030
@$$(call E, compile_and_link: $$@)
3131
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$<
32+
ifdef CFG_ENABLE_PAX_MARKS
33+
@$$(call E, apply PaX markings: $$@)
34+
@"$(CFG_PAXCTL)" -cm "$$@"
35+
endif
3236

3337
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
3438
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \

0 commit comments

Comments
 (0)