Linux Kernel 5.0.0-37
I'm writing a function to manage permissions to be provided as a function pointer to the struct inode_operations
. Here is a simplified stub implementation:
#include <linux/cred.h>
int pfsw_permission(struct inode *ino, int op){
if(uid_eq(INIT_USER->uid, get_current_user()->uid)){
printk(KERN_INFO "Current user is root\n");
} else {
printk(KERN_INFO "Current user is not root\n");
}
if(op & (MAY_READ | MAY_WRITE)){
return 0;
}
return -EACCES;
}
when compiling a kernel module containing this function and trying to load it dmesg
shows the following error:
Unknown symbol root_user (err -2)
This I think is due to INIT_USER
macro coming from include/linux/sched/user.h which is defined as
extern struct user_struct root_user;
#define INIT_USER (&root_user)
QUESTION: Why is the symbol root_user
declared, but not defined? How to use INIT_USER
correctly?