How to fix this but for Fedora/CentOS
First make sure that your installed packages (especially kernel) are up to date:
$ sudo yum update
If it updates the kernel version, you will have to restart so uname -r
matches the directory name in /usr/src/kernels/
. Then
$ sudo yum install kernel-devel gcc
$ echo export KERN_DIR=/usr/src/kernels/`uname -r` >> ~/.bashrc
$ source ~/.bashrc # to set the variable in your current shell
$ sudo echo $KERN_DIR # verify the value is set
$ sudo ls $KERN_DIR # verify the directory exists
After this compiling VirtualBox kernel modules should works without any problems.
Sources: