From 2656202dff2e128a82113839ecb41bab03179d66 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sun, 25 Mar 2018 19:01:24 +0100 Subject: [PATCH] init: disable all userland processes started from init In order to make the system easier to understand. These include: * networking * klogd and syslogd. TODO what are those for? I could not see anything useful that they do. Also get rid of the useless S20random thing while we are at it. --- README.adoc | 36 +++++++++++++++++++--- rootfs_overlay/etc/init.d/S40network | 44 --------------------------- rootfs_overlay/rand_check_poweroff.sh | 8 ----- rootfs_post_build_script | 7 +++++ run | 3 -- run-usage.adoc | 2 +- 6 files changed, 39 insertions(+), 61 deletions(-) delete mode 100755 rootfs_overlay/etc/init.d/S40network diff --git a/README.adoc b/README.adoc index 5dc6af6..14216d0 100644 --- a/README.adoc +++ b/README.adoc @@ -846,7 +846,9 @@ But TODO I don't think you can see where you are in the kernel source code and l Step debug userland processes to understand how they are talking to the kernel. -In guest: +First ensure that <> is enabled. + +Then in guest: .... /gdbserver.sh /myinsmod.out /hello.ko @@ -1138,16 +1140,38 @@ Finally, the docs are lying, arguments with dots that come after `-` are still t ./run -e 'init=/init_env_poweroff.sh - /poweroff.out' .... -=== Disable networking +=== Networking -The default BusyBox init scripts enable networking, and there is a 15 second timeout in case your network is down or if your kernel / emulator setup does not support it. +We disable networking by default because it starts an userland process, and we want to keep the number of userland processes to a minimum to make the system more understandable. -We have hacked it up so that you can disable networking with: +To enable it run: .... -./run -f 'lkmc_nonet=y' +/sbin/ifup -a .... +To disable it, run: + +.... +/sbin/ifdown -a +.... + +To test it out, try: + +.... +wget google.com +.... + +BusyBox' `ping` does not work with hostnames even when networking is working fine: + +.... +ping google.com +.... + +TODO why: https://unix.stackexchange.com/questions/124283/busybox-ping-ip-works-but-hostname-nslookup-fails-with-bad-address + +To enable networking by default, use the methods documented at <> + == KVM You can make QEMU or gem5 <> by passing enabling KVM with: @@ -1864,6 +1888,8 @@ Even mor awesome than `chroot` be to `pivot_root`, but I couldn't get that worki === Guest host networking +First ensure that networking is enabled before trying out anything in this section: <> + ==== Host to guest networking Guest, BusyBox `nc` enabled with `CONFIG_NC=y`: diff --git a/rootfs_overlay/etc/init.d/S40network b/rootfs_overlay/etc/init.d/S40network deleted file mode 100755 index c440941..0000000 --- a/rootfs_overlay/etc/init.d/S40network +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -# Copied from: package/ifupdown-scripts/S40network at -# 8ce27bb9fee80a406a4199657ef90e3c315e7457 -# -# We then just added this line to turn it off at runtime. -# -# We also considered copying the file at build to / and then -# sourcing it from S98 to be a bit DRYer, but it wouldn't work -# very well if some S50 requires networking to work. -# -# This became necessary nitially when aarch64 qemu and gem5 -# started using the same Buildroot output directory. -[ -n "$lkmc_nonet" ] && exit 0 - -# -# Start the network.... -# - -# Debian ifupdown needs the /run/network lock directory -mkdir -p /run/network - -case "$1" in - start) - printf "Starting network: " - /sbin/ifup -a - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - stop) - printf "Stopping network: " - /sbin/ifdown -a - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - restart|reload) - "$0" stop - "$0" start - ;; - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac - -exit $? - diff --git a/rootfs_overlay/rand_check_poweroff.sh b/rootfs_overlay/rand_check_poweroff.sh index 78b2a63..d79fdef 100755 --- a/rootfs_overlay/rand_check_poweroff.sh +++ b/rootfs_overlay/rand_check_poweroff.sh @@ -3,16 +3,8 @@ set -ex /rand_check.out # Check if network is being replayed. -# -# TODO; requires internet to be up, which is done by inittab. -# We could do this with a /etc/init.d/SXX file, -# but how to both check that into git, and make it optional? -# # https://superuser.com/questions/635020/how-to-know-current-time-from-internet-from-command-line-in-linux -# Raw IP because was failing with hostname: -# https://unix.stackexchange.com/questions/124283/busybox-ping-ip-works-but-hostname-nslookup-fails-with-bad-address # https://tf.nist.gov/tf-cgi/servers.cgi -# #echo | nc 129.6.15.28 13 # busybox's poweroff panics, TODO why. Likely tries to kill shell. diff --git a/rootfs_post_build_script b/rootfs_post_build_script index 529a356..570fc37 100755 --- a/rootfs_post_build_script +++ b/rootfs_post_build_script @@ -9,3 +9,10 @@ mkdir -p \ "${target_dir}/mnt/9p" \ "${target_dir}/mnt/out" \ ; +# Maybe there is a cleaner way to get rid of those files, +# like disabling some Buildroot packages, but no patience. +rm -rf \ + "${target_dir}/etc/init.d/S01logging" \ + "${target_dir}/etc/init.d/S20urandom" \ + "${target_dir}/etc/init.d/S40network" \ +; diff --git a/run b/run index 770cf86..7b9364a 100755 --- a/run +++ b/run @@ -108,9 +108,6 @@ if "$nographic" && [ "$arch" = x86_64 ]; then extra_append="$extra_append console=ttyS0" extra_flags_qemu="$extra_flags_qemu -nographic" fi -if "$gem5"; then - extra_append_after_dash="${extra_append_after_dash} lkmc_nonet=y" -fi if [ -n "$extra_append_after_dash" ]; then extra_append="${extra_append} - ${extra_append_after_dash}" fi diff --git a/run-usage.adoc b/run-usage.adoc index 275650d..60c1c49 100644 --- a/run-usage.adoc +++ b/run-usage.adoc @@ -23,7 +23,7 @@ add a dash `-` separator, and place the options after the dash. Intended for custom options understood by our `init` scripts, most of which are prefixed by `lkmc_`, e.g.: - `./run -f 'lkmc_eval="wget google.com" lkmc_nonet=y'` + `./run -f 'lkmc_eval="wget google.com" lkmc_lala=y'` Mnenomic: comes after `-e`. |`-G` | | Pass extra options to the gem5 executable. Only useful if `-g` is given.