2020-04-14 21:53:23 +00:00
|
|
|
#! /bin/bash
|
2020-12-17 17:17:34 +00:00
|
|
|
# shellcheck disable=SC2164
|
2020-04-14 21:53:23 +00:00
|
|
|
|
2024-06-12 13:06:45 +00:00
|
|
|
rpm_buildroot="$1"
|
|
|
|
module_dir="$2"
|
|
|
|
module_list="$3"
|
|
|
|
|
|
|
|
blacklist_conf_files="$(mktemp)"
|
2020-04-14 21:53:23 +00:00
|
|
|
|
2021-07-06 17:22:56 +00:00
|
|
|
blacklist()
|
2020-04-14 21:53:23 +00:00
|
|
|
{
|
2024-06-12 13:06:45 +00:00
|
|
|
mkdir -p "$rpm_buildroot/etc/modprobe.d/"
|
|
|
|
cat > "$rpm_buildroot/etc/modprobe.d/$1-blacklist.conf" <<-__EOF__
|
2020-04-14 21:53:23 +00:00
|
|
|
# This kernel module can be automatically loaded by non-root users. To
|
2021-07-06 17:22:56 +00:00
|
|
|
# enhance system security, the module is blacklisted by default to ensure
|
2020-04-14 21:53:23 +00:00
|
|
|
# system administrators make the module available for use as needed.
|
|
|
|
# See https://access.redhat.com/articles/3760101 for more details.
|
|
|
|
#
|
2021-07-06 17:22:56 +00:00
|
|
|
# Remove the blacklist by adding a comment # at the start of the line.
|
2020-04-14 21:53:23 +00:00
|
|
|
blacklist $1
|
|
|
|
__EOF__
|
2024-06-12 13:06:45 +00:00
|
|
|
echo "%config(noreplace) /etc/modprobe.d/$1-blacklist.conf" >> "$blacklist_conf_files"
|
2020-04-14 21:53:23 +00:00
|
|
|
}
|
|
|
|
|
2021-07-06 17:22:56 +00:00
|
|
|
check_blacklist()
|
2020-04-14 21:53:23 +00:00
|
|
|
{
|
2024-06-12 13:06:45 +00:00
|
|
|
mod="$rpm_buildroot/$1"
|
2020-04-14 21:53:23 +00:00
|
|
|
[ ! "$mod" ] && return 0
|
2020-12-17 17:17:34 +00:00
|
|
|
if modinfo "$mod" | grep -q '^alias:\s\+net-'; then
|
2020-04-14 21:53:23 +00:00
|
|
|
mod="${1##*/}"
|
|
|
|
mod="${mod%.ko*}"
|
2021-07-06 17:22:56 +00:00
|
|
|
echo "$mod has an alias that allows auto-loading. Blacklisting."
|
|
|
|
blacklist "$mod"
|
2020-04-14 21:53:23 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
foreachp()
|
|
|
|
{
|
|
|
|
P=$(nproc)
|
|
|
|
bgcount=0
|
2020-12-17 17:17:34 +00:00
|
|
|
while read -r mod; do
|
2020-04-14 21:53:23 +00:00
|
|
|
$1 "$mod" &
|
|
|
|
|
|
|
|
bgcount=$((bgcount + 1))
|
2020-12-17 17:17:34 +00:00
|
|
|
if [ $bgcount -eq "$P" ]; then
|
2020-04-14 21:53:23 +00:00
|
|
|
wait -n
|
|
|
|
bgcount=$((bgcount - 1))
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
|
|
|
# Many BIOS-es export a PNP-id which causes the floppy driver to autoload
|
|
|
|
# even though most modern systems don't have a 3.5" floppy driver anymore
|
|
|
|
# this replaces the old die_floppy_die.patch which removed the PNP-id from
|
|
|
|
# the module
|
2020-12-17 17:17:34 +00:00
|
|
|
|
2024-06-12 13:06:45 +00:00
|
|
|
floppylist=("$rpm_buildroot"/"$module_dir"/kernel/drivers/block/floppy.ko*)
|
2020-12-17 17:17:34 +00:00
|
|
|
if [[ -n ${floppylist[0]} && -f ${floppylist[0]} ]]; then
|
2021-07-06 17:22:56 +00:00
|
|
|
blacklist "floppy"
|
2020-04-14 21:53:23 +00:00
|
|
|
fi
|
|
|
|
|
2024-06-12 13:06:45 +00:00
|
|
|
foreachp check_blacklist < "$module_list"
|
2020-04-14 21:53:23 +00:00
|
|
|
|
2024-06-12 13:06:45 +00:00
|
|
|
cat "$blacklist_conf_files" >> "$module_list"
|
|
|
|
rm -f "$blacklist_conf_files"
|