##// END OF EJS Templates
Enable ASLR if KERNEL_SECURITY is enabled
Unknown -
r537:faa69f13fe5c
parent child
Show More
@@ -0,0 +1,2
1 # ASLR
2 kernel.randomize_va_space = 2 No newline at end of file
@@ -1,284 +1,289
1 1 #
2 2 # Setup RPi2/3 config and cmdline
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 if [ -n "$RPI_FIRMWARE_DIR" ] && [ -d "$RPI_FIRMWARE_DIR" ] ; then
9 9 # Install boot binaries from local directory
10 10 cp "${RPI_FIRMWARE_DIR}"/boot/bootcode.bin "${BOOT_DIR}"/bootcode.bin
11 11 cp "${RPI_FIRMWARE_DIR}"/boot/fixup.dat "${BOOT_DIR}"/fixup.dat
12 12 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_cd.dat "${BOOT_DIR}"/fixup_cd.dat
13 13 cp "${RPI_FIRMWARE_DIR}"/boot/fixup_x.dat "${BOOT_DIR}"/fixup_x.dat
14 14 cp "${RPI_FIRMWARE_DIR}"/boot/start.elf "${BOOT_DIR}"/start.elf
15 15 cp "${RPI_FIRMWARE_DIR}"/boot/start_cd.elf "${BOOT_DIR}"/start_cd.elf
16 16 cp "${RPI_FIRMWARE_DIR}"/boot/start_x.elf "${BOOT_DIR}"/start_x.elf
17 17 else
18 18 # Create temporary directory for boot binaries
19 19 temp_dir=$(as_nobody mktemp -d)
20 20
21 21 # Install latest boot binaries from raspberry/firmware github
22 22 as_nobody wget -q -O "${temp_dir}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin"
23 23 as_nobody wget -q -O "${temp_dir}/fixup.dat" "${FIRMWARE_URL}/fixup.dat"
24 24 as_nobody wget -q -O "${temp_dir}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat"
25 25 as_nobody wget -q -O "${temp_dir}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat"
26 26 as_nobody wget -q -O "${temp_dir}/start.elf" "${FIRMWARE_URL}/start.elf"
27 27 as_nobody wget -q -O "${temp_dir}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf"
28 28 as_nobody wget -q -O "${temp_dir}/start_x.elf" "${FIRMWARE_URL}/start_x.elf"
29 29
30 30 # Move downloaded boot binaries
31 31 mv "${temp_dir}/"* "${BOOT_DIR}/"
32 32
33 33 # Remove temporary directory for boot binaries
34 34 rm -fr "${temp_dir}"
35 35
36 36 # Set permissions of the boot binaries
37 37 chown -R root:root "${BOOT_DIR}"
38 38 chmod -R 600 "${BOOT_DIR}"
39 39 fi
40 40
41 41 if [ "$ENABLE_KEYGEN" = true] ; then
42 42
43 43 # go to chroot/boot/
44 44 cd "${BOOT_DIR}/" || exit
45 45
46 46 # Make a copy of start.elf
47 47 cp start.elf start.elf_backup
48 48
49 49 # Remove codec licence checks - thx go to https://github.com/nucular/raspi-keygen - if ENABLE_VIDEOCORE is true, you can check codec status https://elinux.org/RPI_vcgencmd_usage
50 50 perl -pne 's/\x47\xE9362H\x3C\x18/\x47\xE9362H\x3C\x1F/g' < start.elf_backup > start.elf
51 51
52 52 # Back to base dir
53 53 cd "${WORKDIR}" || exit
54 54 fi
55 55
56 56 # Setup firmware boot cmdline
57 57 if [ "$ENABLE_UBOOTUSB" = true ] ; then
58 58 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait init=/bin/systemd"
59 59 else
60 60 if [ "$ENABLE_SPLITFS" = true ] ; then
61 61 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait init=/bin/systemd"
62 62 else
63 63 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait init=/bin/systemd"
64 64 fi
65 65 fi
66 66
67 67 # Add encrypted root partition to cmdline.txt
68 68 if [ "$ENABLE_CRYPTFS" = true ] ; then
69 69 if [ "$ENABLE_SPLITFS" = true ] ; then
70 70 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
71 71 else
72 72 if [ "$ENABLE_UBOOTUSB" = true ] ; then
73 73 CMDLINE=$(echo "${CMDLINE}" | sed "s/sda2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda2:${CRYPTFS_MAPPING}/")
74 74 else
75 75 CMDLINE=$(echo "${CMDLINE}" | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
76 76 fi
77 77 fi
78 78 fi
79 79
80 80 # Enable Kernel messages on standard output
81 81 if [ "$ENABLE_PRINTK" = true ] ; then
82 82 install_readonly files/sysctl.d/83-rpi-printk.conf "${ETC_DIR}/sysctl.d/83-rpi-printk.conf"
83 83 fi
84 84
85 # Enable Kernel messages on standard output
86 if [ "$KERNEL_SECURITY" = true ] ; then
87 install_readonly files/sysctl.d/84-rpi-ASLR.conf "${ETC_DIR}/sysctl.d/84-rpi-ASLR.conf"
88 fi
89
85 90 # Install udev rule for serial alias - serial0 = console serial1=bluetooth
86 91 install_readonly files/etc/99-com.rules "${LIB_DIR}/udev/rules.d/99-com.rules"
87 92
88 93 # Remove IPv6 networking support
89 94 if [ "$ENABLE_IPV6" = false ] ; then
90 95 CMDLINE="${CMDLINE} ipv6.disable=1"
91 96 fi
92 97
93 98 # Automatically assign predictable network interface names
94 99 if [ "$ENABLE_IFNAMES" = false ] ; then
95 100 CMDLINE="${CMDLINE} net.ifnames=0"
96 101 else
97 102 CMDLINE="${CMDLINE} net.ifnames=1"
98 103 fi
99 104
100 105 # Install firmware config
101 106 install_readonly files/boot/config.txt "${BOOT_DIR}/config.txt"
102 107
103 108 # Locks CPU frequency at maximum
104 109 if [ "$ENABLE_TURBO" = true ] ; then
105 110 echo "force_turbo=1" >> "${BOOT_DIR}/config.txt"
106 111 # helps to avoid sdcard corruption when force_turbo is enabled.
107 112 echo "boot_delay=1" >> "${BOOT_DIR}/config.txt"
108 113 fi
109 114
110 115 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
111 116
112 117 # Bluetooth enabled
113 118 if [ "$ENABLE_BLUETOOTH" = true ] ; then
114 119 # Create temporary directory for Bluetooth sources
115 120 temp_dir=$(as_nobody mktemp -d)
116 121
117 122 # Fetch Bluetooth sources
118 123 as_nobody git -C "${temp_dir}" clone "${BLUETOOTH_URL}"
119 124
120 125 # Copy downloaded sources
121 126 mv "${temp_dir}/pi-bluetooth" "${R}/tmp/"
122 127
123 128 # Bluetooth firmware from arch aur https://aur.archlinux.org/packages/pi-bluetooth/
124 129 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" https://aur.archlinux.org/cgit/aur.git/plain/LICENCE.broadcom_bcm43xx?h=pi-bluetooth
125 130 as_nobody wget -q -O "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" https://aur.archlinux.org/cgit/aur.git/plain/BCM43430A1.hcd?h=pi-bluetooth
126 131
127 132 # Set permissions
128 133 chown -R root:root "${R}/tmp/pi-bluetooth"
129 134
130 135 # Install tools
131 136 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/btuart" "${R}/usr/bin/btuart"
132 137 install_readonly "${R}/tmp/pi-bluetooth/usr/bin/bthelper" "${R}/usr/bin/bthelper"
133 138
134 139 # make scripts executable
135 140 chmod +x "${R}/usr/bin/bthelper"
136 141 chmod +x "${R}/usr/bin/btuart"
137 142
138 143 # Install bluetooth udev rule
139 144 install_readonly "${R}/tmp/pi-bluetooth/lib/udev/rules.d/90-pi-bluetooth.rules" "${LIB_DIR}/udev/rules.d/90-pi-bluetooth.rules"
140 145
141 146 # Install Firmware Flash file and apropiate licence
142 147 mkdir -p "$BLUETOOTH_FIRMWARE_DIR"
143 148 install_readonly "${R}/tmp/pi-bluetooth/LICENCE.broadcom_bcm43xx" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
144 149 install_readonly "${R}/tmp/pi-bluetooth/BCM43430A1.hcd" "${BLUETOOTH_FIRMWARE_DIR}/LICENCE.broadcom_bcm43xx"
145 150 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.bthelper@.service" "${ETC_DIR}/systemd/system/pi-bluetooth.bthelper@.service"
146 151 install_readonly "${R}/tmp/pi-bluetooth/debian/pi-bluetooth.hciuart.service" "${ETC_DIR}/systemd/system/pi-bluetooth.hciuart.service"
147 152
148 153 # Remove temporary directories
149 154 rm -fr "${temp_dir}"
150 155 rm -fr "${R}"/tmp/pi-bluetooth
151 156
152 157 # Switch Pi3 Bluetooth function to use the mini-UART (ttyS0) and restore UART0/ttyAMA0 over GPIOs 14 & 15. Slow Bluetooth and slow cpu. Use /dev/ttyS0 instead of /dev/ttyAMA0
153 158 if [ "$ENABLE_MINIUART_OVERLAY" = true ] ; then
154 159
155 160 # set overlay to swap ttyAMA0 and ttyS0
156 161 echo "dtoverlay=pi3-miniuart-bt" >> "${BOOT_DIR}/config.txt"
157 162
158 163 # if force_turbo didn't lock cpu at high speed, lock it at low speed (XOR logic) or miniuart will be broken
159 164 if [ "$ENABLE_TURBO" = false ] ; then
160 165 echo "core_freq=250" >> "${BOOT_DIR}/config.txt"
161 166 fi
162 167 fi
163 168
164 169 # Activate services
165 170 chroot_exec systemctl enable pi-bluetooth.hciuart.service
166 171
167 172 else # if ENABLE_BLUETOOTH = false
168 173 # set overlay to disable bluetooth
169 174 echo "dtoverlay=pi3-disable-bt" >> "${BOOT_DIR}/config.txt"
170 175 fi # ENABLE_BLUETOOTH end
171 176 fi
172 177
173 178 # may need sudo systemctl disable hciuart
174 179 if [ "$ENABLE_CONSOLE" = true ] ; then
175 180 echo "enable_uart=1" >> "${BOOT_DIR}/config.txt"
176 181 # add string to cmdline
177 182 CMDLINE="${CMDLINE} console=serial0,115200"
178 183
179 184 # Enable serial console systemd style
180 185 chroot_exec systemctl enable serial-getty\@serial0.service
181 186 else
182 187 echo "enable_uart=0" >> "${BOOT_DIR}/config.txt"
183 188 fi
184 189
185 190 if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then
186 191 # Create temporary directory for systemd-swap sources
187 192 temp_dir=$(as_nobody mktemp -d)
188 193
189 194 # Fetch systemd-swap sources
190 195 as_nobody git -C "${temp_dir}" clone "${SYSTEMDSWAP_URL}"
191 196
192 197 # Copy downloaded systemd-swap sources
193 198 mv "${temp_dir}/systemd-swap" "${R}/tmp/"
194 199
195 200 # Change into downloaded src dir
196 201 cd "${R}/tmp/systemd-swap" || exit
197 202
198 203 # Build package
199 204 bash ./package.sh debian
200 205
201 206 # Change back into script root dir
202 207 cd "${WORKDIR}" || exit
203 208
204 209 # Set permissions of the systemd-swap sources
205 210 chown -R root:root "${R}/tmp/systemd-swap"
206 211
207 212 # Install package - IMPROVE AND MAKE IT POSSIBLE WITHOUT VERSION NR.
208 213 chroot_exec dpkg -i /tmp/systemd-swap/systemd-swap_4.0.1_any.deb
209 214
210 215 # Enable service
211 216 chroot_exec systemctl enable systemd-swap
212 217
213 218 # Remove temporary directory for systemd-swap sources
214 219 rm -fr "${temp_dir}"
215 220 else
216 221 # Enable ZSWAP in cmdline if systemd-swap is not used
217 222 if [ "$KERNEL_ZSWAP" = true ] ; then
218 223 CMDLINE="${CMDLINE} zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
219 224 fi
220 225 fi
221 226 if [ "$KERNEL_SECURITY" = true ] ; then
222 227 CMDLINE="${CMDLINE} apparmor=1 security=apparmor"
223 228 fi
224 229
225 230 # Install firmware boot cmdline
226 231 echo "${CMDLINE}" > "${BOOT_DIR}/cmdline.txt"
227 232
228 233 # Setup minimal GPU memory allocation size: 16MB (no X)
229 234 if [ "$ENABLE_MINGPU" = true ] ; then
230 235 echo "gpu_mem=16" >> "${BOOT_DIR}/config.txt"
231 236 fi
232 237
233 238 # Setup boot with initramfs
234 239 if [ "$ENABLE_INITRAMFS" = true ] ; then
235 240 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOT_DIR}/config.txt"
236 241 fi
237 242
238 243 # Create firmware configuration and cmdline symlinks
239 244 ln -sf firmware/config.txt "${R}/boot/config.txt"
240 245 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
241 246
242 247 # Install and setup kernel modules to load at boot
243 248 mkdir -p "${LIB_DIR}/modules-load.d/"
244 249 install_readonly files/modules/rpi2.conf "${LIB_DIR}/modules-load.d/rpi2.conf"
245 250
246 251 # Load hardware random module at boot
247 252 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
248 253 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${LIB_DIR}/modules-load.d/rpi2.conf"
249 254 fi
250 255
251 256 # Load sound module at boot
252 257 if [ "$ENABLE_SOUND" = true ] ; then
253 258 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
254 259 else
255 260 echo "dtparam=audio=off" >> "${BOOT_DIR}/config.txt"
256 261 fi
257 262
258 263 # Enable I2C interface
259 264 if [ "$ENABLE_I2C" = true ] ; then
260 265 echo "dtparam=i2c_arm=on" >> "${BOOT_DIR}/config.txt"
261 266 sed -i "s/^# i2c-bcm2708/i2c-bcm2708/" "${LIB_DIR}/modules-load.d/rpi2.conf"
262 267 sed -i "s/^# i2c-dev/i2c-dev/" "${LIB_DIR}/modules-load.d/rpi2.conf"
263 268 fi
264 269
265 270 # Enable SPI interface
266 271 if [ "$ENABLE_SPI" = true ] ; then
267 272 echo "dtparam=spi=on" >> "${BOOT_DIR}/config.txt"
268 273 echo "spi-bcm2708" >> "${LIB_DIR}/modules-load.d/rpi2.conf"
269 274 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ]; then
270 275 sed -i "s/spi-bcm2708/spi-bcm2835/" "${LIB_DIR}/modules-load.d/rpi2.conf"
271 276 fi
272 277 fi
273 278
274 279 # Disable RPi2/3 under-voltage warnings
275 280 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
276 281 echo "avoid_warnings=${DISABLE_UNDERVOLT_WARNINGS}" >> "${BOOT_DIR}/config.txt"
277 282 fi
278 283
279 284 # Install kernel modules blacklist
280 285 mkdir -p "${ETC_DIR}/modprobe.d/"
281 286 install_readonly files/modules/raspi-blacklist.conf "${ETC_DIR}/modprobe.d/raspi-blacklist.conf"
282 287
283 288 # Install sysctl.d configuration files
284 289 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETC_DIR}/sysctl.d/81-rpi-vm.conf"
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant