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