Skip to content
Advertisement

C – Linux Kernel – Assistance with current_uid()

I have been working on part of an assignment which I am having trouble fixing. The requirement was to intercept the system call open and to replace it with a new system open call only for regular users and would print out the user id and filename in the system log. Otherwise it would just execute the standard system open call. Here is part of what I have that is troubling me:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/syscalls.h>

unsigned long **sys_call_table;

asmlinkage long (*ref_sys_open)(const char *filename, int flags, umode_t mode);
asmlinkage long (*ref_sys_close)(unsigned int fd);

asmlinkage long new_sys_open(const char *filename, int flags, umode_t mode) {

    if (current_uid() >= 1000) {

    printk(KERN_INFO "User %d is opening file: %sn", current_uid(), filename);

    } else {

    (*ref_sys_open)(filename, flags, mode);

    }

    return 0;
}

The problem I am getting is that the returning value of current_uid() is a struct with type kuid_t. I looked into it further and found that the struct looks like this:

typedef struct {
  uid_t val;
} kuid_t;

I was wondering how do I compare int 1000 to type uid_t val?

On a side note, did I call the old versions of the system call correctly?

Advertisement

Answer

from here, uid_t is just a typedef of __kernel_uid32_t, which is unsigned int according to here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement