mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-17 08:11:32 +00:00
chore(falco_scripts): Update falco-driver-loader
cleaning phase
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
This commit is contained in:
parent
7aed3b6d01
commit
a11d513bff
@ -17,13 +17,8 @@
|
|||||||
#
|
#
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
DKMS_PACKAGE_NAME="@PACKAGE_NAME@"
|
|
||||||
DKMS_VERSION="@DRIVER_VERSION@"
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
remove|upgrade|deconfigure)
|
remove|upgrade|deconfigure)
|
||||||
if [ "$(dkms status -m $DKMS_PACKAGE_NAME -v $DKMS_VERSION)" ]; then
|
/usr/bin/falco-driver-loader --clean
|
||||||
dkms remove -m $DKMS_PACKAGE_NAME -v $DKMS_VERSION --all
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -219,43 +219,93 @@ load_kernel_module_download() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
load_kernel_module() {
|
clean_kernel_module() {
|
||||||
if ! hash lsmod > /dev/null 2>&1; then
|
echo
|
||||||
>&2 echo "This program requires lsmod"
|
echo "================ Cleaning phase ================"
|
||||||
exit 1
|
echo
|
||||||
fi
|
|
||||||
|
|
||||||
if ! hash modprobe > /dev/null 2>&1; then
|
if ! hash lsmod > /dev/null 2>&1; then
|
||||||
>&2 echo "This program requires modprobe"
|
>&2 echo "* Error: This program requires lsmod."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! hash rmmod > /dev/null 2>&1; then
|
if ! hash rmmod > /dev/null 2>&1; then
|
||||||
>&2 echo "This program requires rmmod"
|
>&2 echo "* Error: This program requires rmmod."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "* Unloading ${DRIVER_NAME} module, if present"
|
|
||||||
rmmod "${DRIVER_NAME}" 2>/dev/null
|
|
||||||
WAIT_TIME=0
|
|
||||||
KMOD_NAME=$(echo "${DRIVER_NAME}" | tr "-" "_")
|
KMOD_NAME=$(echo "${DRIVER_NAME}" | tr "-" "_")
|
||||||
while lsmod | cut -d' ' -f1 | grep -qx "${KMOD_NAME}" && [ $WAIT_TIME -lt "${MAX_RMMOD_WAIT}" ]; do
|
echo "* 1. Check if kernel module '${KMOD_NAME}' is still loaded:"
|
||||||
if rmmod "${DRIVER_NAME}" 2>/dev/null; then
|
|
||||||
echo "* Unloading ${DRIVER_NAME} module succeeded after ${WAIT_TIME}s"
|
if ! lsmod | cut -d' ' -f1 | grep -qx "${KMOD_NAME}"; then
|
||||||
break
|
echo "- OK! There is no '${KMOD_NAME}' module loaded."
|
||||||
|
echo
|
||||||
fi
|
fi
|
||||||
((++WAIT_TIME))
|
|
||||||
if (( WAIT_TIME % 5 == 0 )); then
|
# Wait 50s = MAX_RMMOD_WAIT * 5s
|
||||||
echo "* ${DRIVER_NAME} module still loaded, waited ${WAIT_TIME}s (max wait ${MAX_RMMOD_WAIT}s)"
|
MAX_RMMOD_WAIT=10
|
||||||
|
# Remove kernel module if is still loaded.
|
||||||
|
while lsmod | cut -d' ' -f1 | grep -qx "${KMOD_NAME}" && [ $MAX_RMMOD_WAIT -gt 0 ]; do
|
||||||
|
echo "- Kernel module '${KMOD_NAME}' is still loaded."
|
||||||
|
echo "- Trying to unload it with 'rmmod ${KMOD_NAME}'..."
|
||||||
|
if rmmod ${KMOD_NAME}; then
|
||||||
|
echo "- OK! Unloading '${KMOD_NAME}' module succeeded."
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
echo "- Nothing to do...'falco-driver-loader' will wait until you remove the kernel module to have a clean termination."
|
||||||
|
echo "- Checkout here what to do (link to documentation)."
|
||||||
|
echo "- Sleep 5 seconds..."
|
||||||
|
echo
|
||||||
|
((--MAX_RMMOD_WAIT))
|
||||||
|
sleep 5
|
||||||
fi
|
fi
|
||||||
sleep 1
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if lsmod | cut -d' ' -f1 | grep -qx "${KMOD_NAME}" > /dev/null 2>&1; then
|
if [ ${MAX_RMMOD_WAIT} -eq 0 ]; then
|
||||||
echo "* ${DRIVER_NAME} module seems to still be loaded, hoping the best"
|
echo "* [WARNING] '${KMOD_NAME}' module is still loaded, you could have incompatibility issues."
|
||||||
exit 0
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! hash dkms >/dev/null 2>&1; then
|
||||||
|
echo "* Skipping dkms remove (dkms not found)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "* 2. Check kernel module '${KMOD_NAME}' in dkms:"
|
||||||
|
|
||||||
|
# Remove all versions of this module from dkms.
|
||||||
|
DRIVER_VERSIONS=$(dkms status -m "${KMOD_NAME}" | cut -d',' -f2 | sed -e 's/^[[:space:]]*//')
|
||||||
|
if [ -z "${DRIVER_VERSIONS}" ]; then
|
||||||
|
echo "- OK! There is no '${KMOD_NAME}' module in dkms-"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
echo "- There are some verions of '${KMOD_NAME}' module in dkms."
|
||||||
|
echo
|
||||||
|
echo "* 3. Removing all the following versions of '${KMOD_NAME}' module from dkms:"
|
||||||
|
echo "- ${DRIVER_VERSIONS}"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
for CURRENT_VER in ${DRIVER_VERSIONS}; do
|
||||||
|
echo "- Removing ${CURRENT_VER}..."
|
||||||
|
if dkms remove -m ${KMOD_NAME} -v "${CURRENT_VER}" --all; then
|
||||||
|
echo
|
||||||
|
echo "- OK! Removing '${CURRENT_VER}' succeeded"
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
echo "- Removing '${KMOD_NAME}' version '${CURRENT_VER}' failed"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "* [SUCCESS] Cleaning phase correctly terminated."
|
||||||
|
echo
|
||||||
|
echo "================ Cleaning phase ================"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
load_kernel_module() {
|
||||||
|
clean_kernel_module
|
||||||
|
|
||||||
echo "* Looking for a ${DRIVER_NAME} module locally (kernel ${KERNEL_RELEASE})"
|
echo "* Looking for a ${DRIVER_NAME} module locally (kernel ${KERNEL_RELEASE})"
|
||||||
|
|
||||||
@ -290,48 +340,6 @@ load_kernel_module() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_kernel_module() {
|
|
||||||
if ! hash lsmod > /dev/null 2>&1; then
|
|
||||||
>&2 echo "This program requires lsmod"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! hash rmmod > /dev/null 2>&1; then
|
|
||||||
>&2 echo "This program requires rmmod"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
KMOD_NAME=$(echo "${DRIVER_NAME}" | tr "-" "_")
|
|
||||||
if lsmod | cut -d' ' -f1 | grep -qx "${KMOD_NAME}"; then
|
|
||||||
if rmmod "${DRIVER_NAME}" 2>/dev/null; then
|
|
||||||
echo "* Unloading ${DRIVER_NAME} module succeeded"
|
|
||||||
else
|
|
||||||
echo "* Unloading ${DRIVER_NAME} module failed"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "* There is no ${DRIVER_NAME} module loaded"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! hash dkms >/dev/null 2>&1; then
|
|
||||||
echo "* Skipping dkms remove (dkms not found)"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
DRIVER_VERSIONS=$(dkms status -m "${DRIVER_NAME}" | cut -d',' -f1 | sed -e 's/^[[:space:]]*//')
|
|
||||||
if [ -z "${DRIVER_VERSIONS}" ]; then
|
|
||||||
echo "* There is no ${DRIVER_NAME} module in dkms"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
for CURRENT_VER in ${DRIVER_VERSIONS}; do
|
|
||||||
if dkms remove "${CURRENT_VER}" --all 2>/dev/null; then
|
|
||||||
echo "* Removing ${CURRENT_VER} succeeded"
|
|
||||||
else
|
|
||||||
echo "* Removing ${CURRENT_VER} failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
load_bpf_probe_compile() {
|
load_bpf_probe_compile() {
|
||||||
local BPF_KERNEL_SOURCES_URL=""
|
local BPF_KERNEL_SOURCES_URL=""
|
||||||
local STRIP_COMPONENTS=1
|
local STRIP_COMPONENTS=1
|
||||||
|
@ -15,5 +15,4 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
mod_version="@DRIVER_VERSION@"
|
/usr/bin/falco-driver-loader --clean
|
||||||
dkms remove -m falco -v $mod_version --all --rpm_safe_upgrade
|
|
||||||
|
Loading…
Reference in New Issue
Block a user