Skip to contentSkip to conversation

kernel space realpath()

DISCUSSION Ramy M. Hassan 5 participants 5 messages Mar 23, 2003 – Mar 24, 2003 VFS

lore
Share & tools
lore
#0 lore raw

Hi,
I am new to kernel development. I am developing now a kernel module to create log of all file operations under a certain specified directory. I intercept the system calls that may do modifications to this directory contents and create the logfile. My problem is that a system call like sys_unlink takes a path that could be relative, and could contain ".." or ".". It might also contain components that are symlinks to other directories. So I want to get the real path of that file given its relative path name.
Is there anyway to do that ?

I appreciate your help.
Best regards

Ramy

#1 lore raw
Quoted 9 lines · Ramy M. Hassan

I am new to kernel development. I am developing now a kernel module to create log of all file operations under a certain specified directory. I intercept the system calls that may do modifications to this directory contents and create the logfile. My problem is that a system call like sys_unlink takes a path that could be relative, and could contain ".." or ".". It might also contain components that are symlinks to other directories. So I want to get the real path of that file given its relative path name.
Is there anyway to do that ?

Isn't this exactly what the LSM project does? See http://lsm.immunix.org/

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#2 lore raw
Quoted 11 lines · * Matthew Wilcox ([email protected]) wrote:
Quoted 9 lines · Ramy M. Hassan

I am new to kernel development. I am developing now a kernel module to create log of all file operations under a certain specified directory. I intercept the system calls that may do modifications to this directory contents and create the logfile. My problem is that a system call like sys_unlink takes a path that could be relative, and could contain ".." or ".". It might also contain components that are symlinks to other directories. So I want to get the real path of that file given its relative path name.
Is there anyway to do that ?

Quoted 1 line

Isn't this exactly what the LSM project does? See http://lsm.immunix.org/

Actually, LSM works with dentry/vfsmount pairs not raw pathnames, but yes, there are filesystem level hooks that allow one to do things like this.

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
#3 lore raw
In reply to Ramy M. Hassan
Quoted 10 lines · Ramy M. Hassan

Hi,
I am new to kernel development. I am developing now a kernel module to create log of all file operations under a certain specified directory. I intercept the system calls that may do modifications to this directory contents and create the logfile. My problem is that a system call like sys_unlink takes a path that could be relative, and could contain ".." or ".". It might also contain components that are symlinks to other directories. So I want to get the real path of that file given its relative path name.
Is there anyway to do that ?

You should take a look at some syscall, that returns path. Like sys_getcwd. It call d_path (resp. __d_path, because it already has all the locks).

-------------------------------------------------------------------------------
Jan 'Bulb' Hudec <[email protected]>