Changeset 96680 in vbox
- Timestamp:
- Sep 9, 2022 2:20:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/installer/vboxadd.sh
r96407 r96680 289 289 } 290 290 291 # Secure boot state. 292 case "`mokutil --sb-state 2>/dev/null`" in 293 *"disabled in shim"*) unset HAVE_SEC_BOOT;; 294 *"SecureBoot enabled"*) HAVE_SEC_BOOT=true;; 295 *) unset HAVE_SEC_BOOT;; 296 esac 297 # So far we can only sign modules on Ubuntu and on Debian 10 and later. 298 DEB_PUB_KEY=/var/lib/shim-signed/mok/MOK.der 299 DEB_PRIV_KEY=/var/lib/shim-signed/mok/MOK.priv 300 # Check if key already enrolled. 301 unset HAVE_DEB_KEY 302 case "`mokutil --test-key "$DEB_PUB_KEY" 2>/dev/null`" in 303 *"is already"*) DEB_KEY_ENROLLED=true;; 304 *) unset DEB_KEY_ENROLLED;; 305 esac 306 307 # Try to find a tool for modules signing. 308 SIGN_TOOL=$(which kmodsign 2>/dev/null) 309 # Attempt to use in-kernel signing tool if kmodsign not found. 310 if test -z "$SIGN_TOOL"; then 311 if test -x "/lib/modules/$KERN_VER/build/scripts/sign-file"; then 312 SIGN_TOOL="/lib/modules/$KERN_VER/build/scripts/sign-file" 313 fi 314 fi 315 316 if type update-secureboot-policy >/dev/null 2>&1; then 317 HAVE_UPDATE_SECUREBOOT_POLICY_TOOL=true 318 fi 319 320 # Reads CONFIG_MODULE_SIG_HASH from kernel config. 321 kernel_module_sig_hash() 322 { 323 /lib/modules/"$KERN_VER"/build/scripts/config \ 324 --file /lib/modules/"$KERN_VER"/build/.config \ 325 --state CONFIG_MODULE_SIG_HASH 2>/dev/null 326 } 327 328 # Returns "1" if kernel module signature hash algorithm 329 # is supported by us. Or empty string otherwise. 330 module_sig_hash_supported() 331 { 332 sig_hashalgo="$1" 333 [ -n "$sig_hashalgo" ] || return 334 335 # Go through supported list. 336 [ "$sig_hashalgo" = "sha1" \ 337 -o "$sig_hashalgo" = "sha224" \ 338 -o "$sig_hashalgo" = "sha256" \ 339 -o "$sig_hashalgo" = "sha384" \ 340 -o "$sig_hashalgo" = "sha512" ] || return 341 342 echo "1" 343 } 344 345 sign_modules() 346 { 347 KERN_VER="$1" 348 test -n "$KERN_VER" || return 1 349 350 # Make list of mudules to sign. 351 MODULE_LIST="vboxguest vboxsf" 352 # vboxvideo might not present on for older kernels. 353 [ -f "/lib/modules/"$KERN_VER"/misc/vboxvideo.ko" ] && MODULE_LIST="$MODULE_LIST vboxvideo" 354 355 # Secure boot on Ubuntu, Debian and Oracle Linux. 356 if test -n "$HAVE_SEC_BOOT"; then 357 begin "Signing VirtualBox Guest Additions kernel modules" 358 359 # Generate new signing key if needed. 360 [ -n "$HAVE_UPDATE_SECUREBOOT_POLICY_TOOL" ] && SHIM_NOTRIGGER=y update-secureboot-policy --new-key 361 362 # Check if signing keys are in place. 363 if test ! -f "$DEB_PUB_KEY" || ! test -f "$DEB_PRIV_KEY"; then 364 # update-secureboot-policy tool present in the system, but keys were not generated. 365 [ -n "$HAVE_UPDATE_SECUREBOOT_POLICY_TOOL" ] && failure "Unable to find signing keys, aborting" 366 # update-secureboot-policy not present in the system, recommend generate keys manually. 367 fail " 368 369 System is running in Secure Boot mode, however your distribution 370 does not provide tools for automatic generation of keys needed for 371 modules signing. Please consider to generate and enroll them manually: 372 373 sudo mkdir -p /var/lib/shim-signed/mok 374 sudo openssl req -nodes -new -x509 -newkey rsa:2048 -outform DER -keyout $DEB_PRIV_KEY -out $DEB_PUB_KEY 375 sudo sudo mokutil --import $DEB_PUB_KEY 376 sudo reboot 377 378 Restart \"rcvboxadd setup\" after system is rebooted. 379 " 380 fi 381 382 # Check if signing tool is available. 383 [ -n "$SIGN_TOOL" ] || fail "Unable to find signing tool" 384 385 # Get kernel signature hash algorithm from kernel config and validate it. 386 sig_hashalgo=$(kernel_module_sig_hash) 387 [ "$(module_sig_hash_supported $sig_hashalgo)" = "1" ] \ 388 || failure "Unsupported kernel signature hash algorithm $sig_hashalgo" 389 390 # Sign modules. 391 for i in $MODULE_LIST; do 392 "$SIGN_TOOL" "$sig_hashalgo" "$DEB_PRIV_KEY" "$DEB_PUB_KEY" \ 393 /lib/modules/"$KERN_VER"/misc/"$i".ko || fail "Unable to sign $i.ko" 394 done 395 # Enroll signing key if needed. 396 if test -n "$HAVE_UPDATE_SECUREBOOT_POLICY_TOOL"; then 397 # update-secureboot-policy "expects" DKMS modules. 398 # Work around this and talk to the authors as soon 399 # as possible to fix it. 400 mkdir -p /var/lib/dkms/vbox-temp 401 update-secureboot-policy --enroll-key 2>/dev/null || 402 fail "Failed to enroll secure boot key." 403 rmdir -p /var/lib/dkms/vbox-temp 2>/dev/null 404 405 # Indicate that key has been enrolled and reboot is needed. 406 HAVE_DEB_KEY=true 407 fi 408 fi 409 } 410 291 411 # Build and install the VirtualBox guest kernel modules 292 412 setup_modules() … … 296 416 # Match (at least): vboxguest.o; vboxguest.ko; vboxguest.ko.xz 297 417 set /lib/modules/"$KERN_VER"/misc/vboxguest.*o* 298 test ! -f "$1" || return 0418 #test ! -f "$1" || return 0 299 419 test -d /lib/modules/"$KERN_VER"/build || return 0 300 420 export KERN_VER … … 343 463 echo "override vboxsf * misc" >> /etc/depmod.d/vboxvideo-upstream.conf 344 464 echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf 465 466 sign_modules "${KERN_VER}" 467 345 468 update_initramfs "${KERN_VER}" 346 469 return 0 … … 458 581 } 459 582 583 584 # Returns "1" if module is signed and signature can be verified 585 # with public key provided in DEB_PUB_KEY. Or empty string otherwise. 586 module_signed() 587 { 588 mod="$1" 589 [ -n "$mod" ] || return 590 591 extraction_tool=/lib/modules/"$(uname -r)"/build/scripts/extract-module-sig.pl 592 mod_path=$(module_path "$mod" 2>/dev/null) 593 openssl_tool=$(which openssl 2>/dev/null) 594 # Do not use built-in printf! 595 printf_tool=$(which printf 2>/dev/null) 596 597 # Make sure all the tools required for signature validation are available. 598 [ -x "$extraction_tool" ] || return 599 [ -n "$mod_path" ] || return 600 [ -n "$openssl_tool" ] || return 601 [ -n "$printf_tool" ] || return 602 603 # Make sure openssl can handle hash algorithm. 604 sig_hashalgo=$(modinfo -F sig_hashalgo vboxdrv 2>/dev/null) 605 [ "$(module_sig_hash_supported $sig_hashalgo)" = "1" ] || return 606 607 # Generate file names for temporary stuff. 608 mod_pub_key=$(mktemp -u) 609 mod_signature=$(mktemp -u) 610 mod_unsigned=$(mktemp -u) 611 612 # Convert public key in DER format into X509 certificate form. 613 "$openssl_tool" x509 -pubkey -inform DER -in "$DEB_PUB_KEY" -out "$mod_pub_key" 2>/dev/null 614 # Extract raw module signature and convert it into binary format. 615 "$printf_tool" \\x$(modinfo -F signature "$mod" | sed -z 's/[ \t\n]//g' | sed -e "s/:/\\\x/g") 2>/dev/null > "$mod_signature" 616 # Extract unsigned module for further digest calculation. 617 "$extraction_tool" -0 "$mod_path" 2>/dev/null > "$mod_unsigned" 618 619 # Verify signature. 620 rc="" 621 "$openssl_tool" dgst "-$sig_hashalgo" -binary -verify "$mod_pub_key" -signature "$mod_signature" "$mod_unsigned" 2>&1 >/dev/null && rc="1" 622 # Clean up. 623 rm -f $mod_pub_key $mod_signature $mod_unsigned 624 625 # Check result. 626 [ "$rc" = "1" ] || return 627 628 echo "1" 629 } 630 460 631 # Returns "1" if externally built module is available in the system and its 461 632 # version and revision number do match to current VirtualBox installation. … … 487 658 [ "$mod_dir" = "misc" ] || return 488 659 660 # In case if system is running in Secure Boot mode, check if module is signed. 661 if test -n "$HAVE_SEC_BOOT"; then 662 [ "$(module_signed "$mod")" = "1" ] || return 663 fi 664 489 665 echo "1" 490 666 } … … 503 679 setup() 504 680 { 681 info "Setting up modules" 682 505 683 # chcon is needed on old Fedora/Redhat systems. No one remembers which. 506 684 test ! -e /etc/selinux/config || … … 511 689 # Prevent unnecessary rebuilding in order to speed up booting process. 512 690 if test "$(setup_complete)" = "1"; then 513 info "VirtualBox Guest Additions kernel modules $VBOX_VERSION $VBOX_REVISION are "514 info "already available for kernel $TARGET_VER and do not require to be rebuilt."691 info "VirtualBox Guest Additions kernel modules $VBOX_VERSION $VBOX_REVISION are \ 692 already available for kernel $TARGET_VER and do not require to be rebuilt." 515 693 else 516 694 info "Building the VirtualBox Guest Additions kernel modules. This may take a while." … … 590 768 fi 591 769 setup 770 771 # Warn if Secure Boot setup not yet complete. 772 if test -n "$HAVE_SEC_BOOT" && test -z "$DEB_KEY_ENROLLED"; then 773 if test -n "$HAVE_DEB_KEY"; then 774 info "You must re-start your system to finish secure boot set-up." 775 else 776 info "You must sign vboxguest, vboxsf and 777 vboxvideo (if present) kernel modules before using 778 VirtualBox Guest Additions. See the documentation 779 for your Linux distribution." 780 fi 781 fi 782 592 783 if test -z "${INSTALL_NO_MODULE_BUILDS}"; then 593 784 test -d /sys &&
Note:
See TracChangeset
for help on using the changeset viewer.