Recently I was hit by a null pointer dereference bug in OpenWRT. It was part of the 5GHz Wi-Fi driver and interrupted my internet connection 3 or 4 times already in the last few months. The fix was merged to the driver more than one week ago, but OpenWRT has not yet updated the driver. To avoid random interruptions on my internet again, I decided to patch the kernel myself and record what I have done.
The first step is to check out the desired version of OpenWRT. I used the exact same version that is running on my router.
The second step is to create an OpenWRT build environment. I used an Ubuntu 20.04 docker and installed the packages as recommended by the documentation. Interestingly, I also had to additionally install
The third step is to patch OpenWRT. Initially I tried to bump the driver to the latest version, but the resulting code does not compile, most likely due to the fact that I used an old version of OpenWRT. Thus, I decided to only apply the fix itself, which can be done quite easily.
wget https://github.com/openwrt/mt76/commit/8044311f5de569dcfb6f8ef39bb68d073abad1bf.patch \ -O package/kernel/mt76/patches/002-mt76-mt7915-fix-potential-NPE-in-TXS-processing.patch
The next step is to create a
kmod package. This is done as follows.
wget https://downloads.openwrt.org/snapshots/targets/mediatek/mt7622/config.buildinfo \ -O .config make defconfig make target/linux/compile make package/kernel/mt76/compile
The package then appears as
bin/targets/mediatek/mt7622/packages/. The first line downloads the official build config so that the kernel
vermagic of the built package matches what is running on my router. The second line expands the config. Without this line, the next line will launch the config menu which creates a different
vermagic. I’m not too sure what the last two lines do. I tried to follow the instructions to build a single
make package/kernel/linux/install keeps failing.
make package/kernel/mt76/compile does succeed. It also invokes
make package/kernel/linux/compile so I don’t have to do it.
The last step was to install the package on the router and reboot. I tried to
rmmod mt7915e and then
modprobe mt7915e, but the router apparently does not like this idea. I had to reboot.
The router has been up and running for a while. Hopeful this fixes the bug for good.