Building GuestAdditions failed on guest RHEL9 due to read-only member ‘vm_flags’

We have a system of:

  • VirtualBox hypervisor v7.0.18 running on Windows 10, with a
  • guest OS of RHEL9, and “uname -r” says its kernel release is “5.14.0-503.14.1.el9_5.x86_64”.

After upgrading to the above kernel version by “dnf update”, we are trying to rebuild the VirtualBox GuestAdditions and got the following error in the log file saying /tmp/vbox.0/r0drv/linux/memobj-r0drv-linux.c:1447:39: error: assignment of read-only member ‘vm_flags’.

More details of the interesting parts in the log file:

Building the main Guest Additions 7.0.18 module for kernel 5.14.0-503.14.1.el9_5.x86_64.
Error building the module.  Build output follows.
make V=1 CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL= -C /lib/modules/5.14.0-503.14.1.el9_5.x86_64/build M=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j1 modules
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (                
echo >&2;                                                       
echo >&2 "  ERROR: Kernel configuration is invalid.";           
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";      
echo >&2 ;                                                      
/bin/false)

...

In file included from /tmp/vbox.0/combined-os-specific.c:43:
/tmp/vbox.0/r0drv/linux/memobj-r0drv-linux.c: In function ‘rtR0MemObjNativeLockUser’:
/tmp/vbox.0/r0drv/linux/memobj-r0drv-linux.c:1447:39: error: assignment of read-only member ‘vm_flags’
 1447 |                 papVMAs[rc]->vm_flags |= VM_DONTCOPY | VM_LOCKED;
      |                                       ^~
/tmp/vbox.0/r0drv/linux/memobj-r0drv-linux.c: In function ‘rtR0MemObjNativeMapUser’:
/tmp/vbox.0/r0drv/linux/memobj-r0drv-linux.c:1929:35: error: assignment of read-only member ‘vm_flags’
 1929 |                     vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
      |                                   ^~
make[2]: *** [scripts/Makefile.build:249: /tmp/vbox.0/combined-os-specific.o] Error 1
make[1]: *** [Makefile:1944: /tmp/vbox.0] Error 2
make: *** [/tmp/vbox.0/Makefile-footer.gmk:133: vboxguest] Error 2
Could not find the X.Org or XFree86 Window System, skipping.
kernel modules and services were not reloaded