]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/linux
kernel: patch CVE-2023-32233
[ipfire-2.x.git] / lfs / linux
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2023 IPFire Team <info@ipfire.org> #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 ###############################################################################
20
21 ###############################################################################
22 # Definitions
23 ###############################################################################
24
25 include Config
26
27 VER = 6.1.27
28
29 ARM_PATCHES = 6.1.y-ipfire2
30
31 THISAPP = linux-$(VER)
32 DL_FILE = linux-$(VER).tar.xz
33 DL_FROM = $(URL_IPFIRE)
34 DIR_APP = $(DIR_SRC)/$(THISAPP)
35 CFLAGS =
36 CXXFLAGS =
37
38 HEADERS_ARCH = $(BUILD_PLATFORM)
39 KERNEL_ARCH = $(BUILD_ARCH)
40 KERNEL_TARGET = bzImage
41
42 ifeq "$(BUILD_ARCH)" "aarch64"
43 HEADERS_ARCH = arm64
44 KERNEL_ARCH = arm64
45 KERNEL_TARGET = Image
46 endif
47
48 ifeq "$(BUILD_ARCH)" "riscv64"
49 KERNEL_ARCH = riscv
50 KERNEL_TARGET = Image.gz
51 endif
52
53 VERSUFIX=ipfire$(KCFG)
54
55 ifeq "$(TOOLCHAIN)" "1"
56 TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)-tools
57 HEADERS_PREFIX = $(TOOLS_DIR)
58 EXTRAMAKE = CROSS_COMPILE=$(CROSSTARGET)-
59 else
60 TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)
61 HEADERS_PREFIX = /usr
62 endif
63
64 ifeq "$(KCFG)" ""
65 LASTKERNEL=1
66 endif
67
68 ###############################################################################
69 # Top-level Rules
70 ###############################################################################
71
72 objects = \
73 $(DL_FILE) \
74 arm-multi-patches-$(ARM_PATCHES).patch.xz
75
76 $(DL_FILE) = $(URL_IPFIRE)/$(DL_FILE)
77 arm-multi-patches-$(ARM_PATCHES).patch.xz = $(URL_IPFIRE)/arm-multi-patches-$(ARM_PATCHES).patch.xz
78
79 $(DL_FILE)_BLAKE2 = 5d7ec9a6a2652abbe4afb70174a63f58d495291d522087f9adb33864063ce54e219fd6e426793077a346338ccb4d9d753a60cb76b448146fb592ff17c2618792
80 arm-multi-patches-$(ARM_PATCHES).patch.xz_BLAKE2 = 7afc460562fb24bcd75784fc79de768f9b60780aedd88d1a847927169e31920bbb475b1ac1466c4a224a7876d16bd8d465b96202de12b74f6e2ccbfcec731ad3
81
82 install : $(TARGET)
83
84 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
85
86 download :$(patsubst %,$(DIR_DL)/%,$(objects))
87
88 b2 : $(subst %,%_BLAKE2,$(objects))
89
90 dist:
91 @$(PAK)
92
93 ###############################################################################
94 # Downloading, checking, b2sum
95 ###############################################################################
96
97 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
98 @$(CHECK)
99
100 $(patsubst %,$(DIR_DL)/%,$(objects)) :
101 @$(LOAD)
102
103 $(subst %,%_BLAKE2,$(objects)) :
104 @$(B2SUM)
105
106 ###############################################################################
107 # Installation Details
108 ###############################################################################
109
110 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
111 @$(PREBUILD)
112 @rm -rf $(DIR_APP) $(DIR_SRC)/linux && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
113
114 ln -svf linux-$(VER) $(DIR_SRC)/linux
115
116 # Layer7-patch
117 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.1.27-layer7.patch
118
119 # DVB Patches
120 cd $(DIR_APP) && patch -Np2 < $(DIR_SRC)/src/patches/v4l-dvb_fix_tua6034_pll.patch
121
122 # Wlan Patches
123 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14_ath_user_regd.patch
124 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-iwlwifi-noibss_only_on_radar_chan.patch
125
126 # Fix igb and e1000e crash
127 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14.1-igb-e1000e_fix_lock_at_update_stats.patch
128
129 # cs5535audio spams syslog if no ac97 was present (geos router)
130 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8_cs5535audio_fix_logspam_on_geos.patch
131
132 # Fix uevent PHYSDEVDRIVER
133 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-2.6.32.27_mcs7830-fix-driver-name.patch
134
135 # fix Boot with enabled usercopy hardening
136 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-5.9-crypto_testmgr_allocate_buffers_with____GFP_COMP.patch
137
138 # Patch performance monitoring restrictions to allow further hardening
139 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-5.15.17-security-perf-allow-further-restriction-of-perf_event_open.patch
140
141 # https://bugzilla.ipfire.org/show_bug.cgi?id=12760
142 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-5.15-NFQUEUE-Hold-RCU-read-lock-while-calling-nf_reinject.patch
143
144 # Fix external module compile
145 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.0-fix_external_module_build.patch
146
147 # Fix pmc compile dependency errors
148 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.0.7-platform-x86-amd-Fix-pmc-compile-dependency-errors.patch
149
150 # Patch netfilter CVE-2023-32233
151 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.3-netfilter_nftables_deactivate_anonymus_set.patch
152
153 ifeq "$(BUILD_ARCH)" "aarch64"
154 # Apply Arm-multiarch kernel patches.
155 cd $(DIR_APP) && xzcat $(DIR_DL)/arm-multi-patches-$(ARM_PATCHES).patch.xz | patch -Np1
156 endif
157 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-3.14.79-amba-fix.patch
158
159 ifeq "$(KCFG)" "-headers"
160 # Install the header files
161 cd $(DIR_APP) && make ARCH=$(HEADERS_ARCH) $(EXTRAMAKE) headers
162 -mkdir -pv $(BUILDROOT)/$(HEADERS_PREFIX)/include
163 cd $(DIR_APP) && find usr/include -name '.*' -delete
164 cd $(DIR_APP) && rm usr/include/Makefile
165 cd $(DIR_APP) && cp -rv usr/include/* $(BUILDROOT)/$(HEADERS_PREFIX)/include
166 else
167
168 # Install ipfire logo
169 cd $(DIR_APP) && cp -vf $(DIR_SRC)/config/kernel/ipfire_logo.ppm \
170 drivers/video/logo/logo_linux_clut224.ppm
171
172 # Cleanup kernel source
173 cp $(DIR_SRC)/config/kernel/kernel.config.$(BUILD_ARCH)-$(VERSUFIX) $(DIR_APP)/.config
174 cd $(DIR_APP) && make oldconfig
175 cd $(DIR_APP) && make clean
176 cd $(DIR_APP) && sed -i -e 's/EXTRAVERSION\ =.*/EXTRAVERSION\ =\ -$(VERSUFIX)/' Makefile
177
178 # Copy Module signing key configuration
179 cp -f $(DIR_SRC)/config/kernel/x509.genkey $(DIR_APP)/certs/x509.genkey
180
181 # Remove modules folder if exists
182 rm -rf /lib/modules/$(VER)-$(VERSUFIX)
183
184 # Build the kernel
185 cd $(DIR_APP) && make $(MAKETUNING) $(KERNEL_TARGET) modules
186
187 # Install the kernel
188 cd $(DIR_APP) && cp -v arch/$(KERNEL_ARCH)/boot/$(KERNEL_TARGET) /boot/vmlinuz-$(VER)-$(VERSUFIX)
189 cd $(DIR_APP) && cp -v System.map /boot/System.map-$(VER)-$(VERSUFIX)
190 cd $(DIR_APP) && cp -v .config /boot/config-$(VER)-$(VERSUFIX)
191 cd $(DIR_APP) && make $(MAKETUNING) modules_install
192
193 ifeq "$(BUILD_PLATFORM)" "arm"
194 cd $(DIR_APP) && make $(MAKETUNING) dtbs
195 mkdir -p /boot/dtb-$(VER)-$(VERSUFIX)
196 cd $(DIR_APP)/arch/$(KERNEL_ARCH)/boot/dts && for f in $$(find -name "*.dtb"); do \
197 cp -v --parents $$f /boot/dtb-$(VER)-$(VERSUFIX)/ ; \
198 chmod 644 /boot/dtb-$(VER)-$(VERSUFIX)/$$f ; \
199 done
200 endif
201
202 # Recreate source and build links
203 rm -rf /lib/modules/$(VER)-$(VERSUFIX)/{build,source}
204 mkdir -p /lib/modules/$(VER)-$(VERSUFIX)/build
205 ln -sf build /lib/modules/$(VER)-$(VERSUFIX)/source
206
207 # Create dirs for extra modules
208 mkdir -p /lib/modules/$(VER)-$(VERSUFIX)/extra
209
210 cd $(DIR_APP) && cp --parents $$(find -type f -name "Makefile*" -o -name "Kconfig*") \
211 /lib/modules/$(VER)-$(VERSUFIX)/build
212 cd $(DIR_APP) && cp Module.symvers System.map /lib/modules/$(VER)-$(VERSUFIX)/build
213 rm -rf /lib/modules/$(VER)-$(VERSUFIX)/build/{Documentation,scripts,include}
214
215 cd $(DIR_APP) && cp .config /lib/modules/$(VER)-$(VERSUFIX)/build
216 cd $(DIR_APP) && cp -a scripts /lib/modules/$(VER)-$(VERSUFIX)/build
217 find /lib/modules/$(VER)-$(VERSUFIX)/build/scripts -name "*.o" -exec rm -vf {} \;
218
219 cd $(DIR_APP) && cp -a --parents arch/$(HEADERS_ARCH)/include /lib/modules/$(VER)-$(VERSUFIX)/build
220 cd $(DIR_APP) && cp -a include /lib/modules/$(VER)-$(VERSUFIX)/build/include
221
222 # Copy module signing key for off tree modules
223 cd $(DIR_APP) && cp -f certs/signing_key.* /lib/modules/$(VER)-$(VERSUFIX)/build/certs/
224
225 # Install objtool
226 cd $(DIR_APP) && cp -a tools/objtool/objtool \
227 /lib/modules/$(VER)-$(VERSUFIX)/build/tools/objtool/ || :
228 cd $(DIR_APP) && cp -a --parents tools/build/{Build,Build.include,fixdep.c} \
229 tools/scripts/utilities.mak /lib/modules/$(VER)-$(VERSUFIX)/build
230
231 # Make sure we can build external modules
232 touch -r /lib/modules/$(VER)-$(VERSUFIX)/build/Makefile \
233 /lib/modules/$(VER)-$(VERSUFIX)/build/include/generated/uapi/linux/version.h
234 touch -r /lib/modules/$(VER)-$(VERSUFIX)/build/.config \
235 /lib/modules/$(VER)-$(VERSUFIX)/build/autoconf.h
236 cp /lib/modules/$(VER)-$(VERSUFIX)/build/.config \
237 /lib/modules/$(VER)-$(VERSUFIX)/build/include/config/auto.conf
238
239 # Fix permissions
240 find /lib/modules/$(VER)-$(VERSUFIX) -name "modules.order" \
241 -exec chmod 644 {} \;
242
243 find /lib/modules/$(VER)-$(VERSUFIX) -name ".*.cmd" -exec rm -f {} \;
244
245 ifeq "$(LASTKERNEL)" "1"
246 # Only do this once
247 cd $(DIR_APP) && install -m 755 usr/gen_init_cpio /sbin/
248
249 # disable drm by install drm to /bin/false because i915 ignore blacklisting
250 echo install drm /bin/false > /etc/modprobe.d/framebuffer.conf
251
252 # Blacklist old framebuffer modules
253 for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/video/fbdev/ -name *.ko.xz); do \
254 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
255 done
256 # Blacklist new drm framebuffer modules
257 for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/gpu/drm -name *.ko.xz); do \
258 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
259 done
260 sed -i -e "s|.ko.xz||g" /etc/modprobe.d/framebuffer.conf
261
262 # Disable ipv6 at runtime
263 echo "options ipv6 disable_ipv6=1" > /etc/modprobe.d/ipv6.conf
264 endif
265 endif
266
267 #force new build of external modules and initrd if the kernel was rebuild
268 -rm -f /usr/src/log/*-kmod-$(VER)-$(VERSUFIX)
269 -rm -f /usr/src/log/linux-initrd-$(VER)-$(VERSUFIX)
270
271 @rm -rf $(DIR_APP) $(DIR_SRC)/linux
272 @$(POSTBUILD)