dereferencing filenames from a vfs_write probe
Stone, Joshua I
joshua.i.stone@intel.com
Thu Mar 20 16:02:00 GMT 2008
Eugene Teo wrote:
> I have not tested it, but I have a piece of code I used in a script
> elsewhere that you can probably amend and reuse:
>
> function get_d_path_info:string (task:long, fd:long) %{
> struct task_struct *p = (struct task_struct *)((long)THIS->task);
> struct files_struct *files = kread(&p->files);
> char *page = (char *)__get_free_page(GFP_KERNEL);
> struct file *filp;
> struct dentry *dentry;
> struct vfsmount *vfsmnt;
>
> spin_lock(&files->file_lock);
> filp = fcheck_files(files, THIS->fd);
> dentry = kread(&filp->f_path.dentry);
> vfsmnt = kread(&filp->f_path.mnt);
> snprintf(THIS->__retvalue, MAXSTRINGLEN, " %s",
> d_path(dentry, vfsmnt, page, PAGE_SIZE));
> free_page((unsigned long)page);
> spin_unlock(&files->file_lock);
> CATCH_DEREF_FAULT();
> %}
You should careful - each kread() will jump to the CATCH_DEREF_FAULT()
block if there's an error. You may end up leaving this function with
the page not freed or the lock still held!
Josh
More information about the Systemtap
mailing list