FROM linuxkit/alpine-build-kernel:cfdd576c36a52ed2dd62f237f79eeedc2dd3697b@sha256:3fe08db373a9373ba1616a485858f01ebd2d7a3cb364a099d0ed8b45fa419da2 ARG KERNEL_VERSION ARG DEBUG=0 ENV OKERNEL_SOURCE=https://github.com/linux-okernel/linux-okernel/archive/${KERNEL_VERSION}.tar.gz ENV USPACE_SOURCE=https://github.com/linux-okernel/linux-okernel-components/archive/master.tar.gz RUN apk --update add openssl openssl-dev RUN if [ -n $HTTP_PROXY ]; then \ curl -fsSL -x ${HTTP_PROXY} -o linux-${KERNEL_VERSION}.tar.gz ${OKERNEL_SOURCE}; \ else \ curl -fsSL -o linux-${KERNEL_VERSION}.tar.gz ${OKERNEL_SOURCE}; \ fi RUN cat linux-${KERNEL_VERSION}.tar.gz | tar --absolute-names -xz && mv /linux-okernel-${KERNEL_VERSION} /linux COPY kernel_config.okernel /linux/arch/x86/configs/x86_64_defconfig #COPY kernel_config.debug /linux/debug_config RUN if [ $DEBUG -ne "0" ]; then \ sed -i 's/CONFIG_PANIC_ON_OOPS=y/# CONFIG_PANIC_ON_OOPS is not set/' /linux/arch/x86/configs/x86_64_defconfig; \ cat /linux/debug_config >> /linux/arch/x86/configs/x86_64_defconfig; \ fi # Apply local patches # COPY patches-4.10 /patches #RUN cd /linux && \ # set -e && for patch in /patches/*.patch; do \ # echo "Applying $patch"; \ # patch -p1 < "$patch"; \ # done RUN cd /linux && \ make defconfig && \ make oldconfig && \ make -j "$(getconf _NPROCESSORS_ONLN)" KCFLAGS="-fno-pie" RUN cd /linux && \ make INSTALL_MOD_PATH=/tmp/kernel-modules modules_install && \ ( DVER=$(basename $(find /tmp/kernel-modules/lib/modules/ -mindepth 1 -maxdepth 1)) && \ cd /tmp/kernel-modules/lib/modules/$DVER && \ rm build source && \ ln -s /usr/src/linux-headers-$DVER build ) && \ mkdir -p /tmp/kernel-headers/usr && \ make INSTALL_HDR_PATH=/tmp/kernel-headers/usr headers_install && \ ( cd /tmp/kernel-headers && tar cf /kernel-headers.tar usr ) && \ ( cd /tmp/kernel-modules && tar cf /kernel-modules.tar lib ) && \ cp vmlinux arch/x86_64/boot/bzImage / RUN DVER=$(basename $(find /tmp/kernel-modules/lib/modules/ -mindepth 1 -maxdepth 1)) && \ dir=/tmp/usr/src/linux-headers-$DVER && \ mkdir -p $dir && \ cp /linux/.config $dir && \ cd /linux && \ cp -a include "$dir" && \ mkdir -p "$dir"/arch/x86 && cp -a arch/x86/include "$dir"/arch/x86/ && \ ( cd /tmp && tar cf /kernel-dev.tar usr/src ) RUN printf "KERNEL_SOURCE=${OKERNEL_SOURCE}\n" > /kernel-source-info # Build kernel module from linux-okernel-components RUN if [ -n $HTTP_PROXY ]; then \ curl -fsSL -x ${HTTP_PROXY} -o okernel-userspace.tar.gz ${USPACE_SOURCE}; \ else \ curl -fsSL -o okernel-userspace.tar.gz ${USPACE_SOURCE}; \ fi RUN cat okernel-userspace.tar.gz | tar --absolute-names -xz && mv /linux-okernel-components-master /ok_components WORKDIR /ok_components/test_mappings/kvmod RUN sed -i 's_~/linux-okernel_/linux_' Makefile && \ make && \ mkdir -p /tmp/root/kvmod && cp kernel_vuln.ko /tmp/root/kvmod && \ cd /tmp && \ tar cf /kernel_vuln.tar root WORKDIR /