Skip to content

Commit cd174aa

Browse files
committed
Merge pull request #48 from a-tom/stack_protection
Stack protection via randomize_va_space
2 parents f758209 + b87be26 commit cd174aa

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ This module provides secure configuration of your base OS with hardening.
4848
load this modules via initramfs if enable_module_loading is false
4949
* `enable_sysrq = false`
5050
* `enable_core_dump = false`
51+
* `enable_stack_protection = true`
52+
for Address Space Layout Randomization. ASLR can help defeat certain types of buffer overflow attacks. ASLR can locate the base, libraries, heap, and stack at random positions in a process's address space, which makes it difficult for an attacking program to predict the memory address of the next instruction.
5153
* `cpu_vendor = 'intel'`
5254
only required if `enable_module_loading = false`: set the CPU vendor for modules to load
5355
* `root_ttys = ["console","tty1","tty2","tty3","tty4","tty5","tty6"]`

manifests/init.pp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
$arp_restricted = true,
4848
$enable_sysrq = false,
4949
$enable_core_dump = false,
50+
$enable_stack_protection = true,
5051
) {
5152
# Prepare
5253
# -------
@@ -100,16 +101,17 @@
100101

101102
if $configure_sysctl {
102103
class {'os_hardening::sysctl':
103-
enable_module_loading => $enable_module_loading,
104-
load_modules => $load_modules,
105-
cpu_vendor => $cpu_vendor,
106-
desktop_enabled => $desktop_enabled,
107-
enable_ipv4_forwarding => $enable_ipv4_forwarding,
108-
enable_ipv6 => $enable_ipv6,
109-
enable_ipv6_forwarding => $enable_ipv6_forwarding,
110-
arp_restricted => $arp_restricted,
111-
enable_sysrq => $enable_sysrq,
112-
enable_core_dump => $enable_core_dump,
104+
enable_module_loading => $enable_module_loading,
105+
load_modules => $load_modules,
106+
cpu_vendor => $cpu_vendor,
107+
desktop_enabled => $desktop_enabled,
108+
enable_ipv4_forwarding => $enable_ipv4_forwarding,
109+
enable_ipv6 => $enable_ipv6,
110+
enable_ipv6_forwarding => $enable_ipv6_forwarding,
111+
arp_restricted => $arp_restricted,
112+
enable_sysrq => $enable_sysrq,
113+
enable_core_dump => $enable_core_dump,
114+
enable_stack_protection => $enable_stack_protection,
113115
}
114116
}
115117
}

manifests/sysctl.pp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
# Configures PAM
1111
#
1212
class os_hardening::sysctl (
13-
$enable_module_loading = true,
14-
$load_modules = [],
15-
$cpu_vendor = 'intel',
16-
$desktop_enabled = false,
17-
$enable_ipv4_forwarding = false,
18-
$enable_ipv6 = false,
19-
$enable_ipv6_forwarding = false,
20-
$arp_restricted = true,
21-
$enable_sysrq = false,
22-
$enable_core_dump = false,
13+
$enable_module_loading = true,
14+
$load_modules = [],
15+
$cpu_vendor = 'intel',
16+
$desktop_enabled = false,
17+
$enable_ipv4_forwarding = false,
18+
$enable_ipv6 = false,
19+
$enable_ipv6_forwarding = false,
20+
$arp_restricted = true,
21+
$enable_sysrq = false,
22+
$enable_core_dump = false,
23+
$enable_stack_protection = true,
2324
){
2425

2526
# set variables
@@ -172,6 +173,13 @@
172173
sysctl { 'kernel.sysrq': value => '0' }
173174
}
174175

176+
# Enable stack protection by randomizing kernel va space
177+
if $enable_stack_protection {
178+
sysctl { 'kernel.randomize_va_space': value => '2' }
179+
} else {
180+
sysctl { 'kernel.randomize_va_space': value => '0' }
181+
}
182+
175183
# Prevent core dumps with SUID. These are usually only needed by developers and may contain sensitive information.
176184
if $enable_core_dump {
177185
sysctl { 'fs.suid_dumpable': value => '1' }

spec/classes/sysctl_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@
115115
end
116116
end
117117

118+
context 'with enable_stack_protection => true' do
119+
let(:params) { { :enable_stack_protection => true } }
120+
it do
121+
should contain_sysctl('kernel.randomize_va_space').with_value('2')
122+
end
123+
end
124+
125+
context 'with enable_stack_protection => false' do
126+
let(:params) { { :enable_stack_protection => false } }
127+
it do
128+
should contain_sysctl('kernel.randomize_va_space').with_value('0')
129+
end
130+
end
131+
118132
context 'with enable_core_dump => true' do
119133
let(:params) { { :enable_core_dump => true } }
120134
it do

0 commit comments

Comments
 (0)