mod-extra-blacklist.sh 1.03 KB
Newer Older
Rocky Automation's avatar
Rocky Automation committed
1
2
#!/bin/bash

Rocky Automation's avatar
Rocky Automation committed
3
4
buildroot="$1"
kernel_base="$2"
Rocky Automation's avatar
Rocky Automation committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

blacklist()
{
	cat > "$buildroot/etc/modprobe.d/$1-blacklist.conf" <<-__EOF__
	# This kernel module can be automatically loaded by non-root users. To
	# enhance system security, the module is blacklisted by default to ensure
	# system administrators make the module available for use as needed.
	# See https://access.redhat.com/articles/3760101 for more details.
	#
	# Remove the blacklist by adding a comment # at the start of the line.
	blacklist $1
__EOF__
}

check_blacklist()
{
Rocky Automation's avatar
Rocky Automation committed
21
	if modinfo "$1" | grep -q '^alias:\s\+net-'; then
Rocky Automation's avatar
Rocky Automation committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
		mod="${1##*/}"
		mod="${mod%.ko*}"
		echo "$mod has an alias that allows auto-loading. Blacklisting."
		blacklist "$mod"
	fi
}

foreachp()
{
	P=$(nproc)
	bgcount=0
	while read mod; do
		$1 "$mod" &

		bgcount=$((bgcount + 1))
		if [ $bgcount -eq $P ]; then
			wait -n
			bgcount=$((bgcount - 1))
		fi
	done

	wait
}

[ -d "$buildroot/etc/modprobe.d/" ] || mkdir -p "$buildroot/etc/modprobe.d/"
Rocky Automation's avatar
Rocky Automation committed
47
48
find "$buildroot/$kernel_base/extra" -name "*.ko*" | \
	foreachp check_blacklist