lkml.org 
[lkml]   [2012]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] c/r: prctl: Add ability to set new mm_struct::exe_file v3
On 03/09, Cyrill Gorcunov wrote:
>
> +static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
> +{
> + struct file *exe_file;
> + struct dentry *dentry;
> + int err;
> +
> + exe_file = fget(fd);
> + if (!exe_file)
> + return -EBADF;
> +
> + dentry = exe_file->f_path.dentry;
> +
> + /*
> + * Because the original mm->exe_file
> + * points to executable file, make sure
> + * this one is executable as well to not
> + * break an overall picture.
> + */
> + err = -EACCES;
> + if (!S_ISREG(dentry->d_inode->i_mode) ||
> + exe_file->f_path.mnt->mnt_flags & MNT_NOEXEC)
> + goto exit;
> +
> + err = inode_permission(dentry->d_inode, MAY_EXEC);
> + if (err)
> + goto exit;
> +
> + /*
> + * Setting new mm::exe_file is only allowed
> + * when no executable VMAs left. This is
^^^^^^^^^^
Perhaps this is just me, but imho "executable" is not clear enough.
I'd suggest VM_EXECUTABLE to avoid the confusion with VM_EXEC.

> + * special C/R case when a restored program
> + * need to change own /proc/$pid/exe symlink.
> + * After this call mm::num_exe_file_vmas become
> + * meaningless.
> + */
> + down_write(&mm->mmap_sem);
> + if (mm->num_exe_file_vmas == 0) {

You can check this at the very start lockless and simplify the code.
Once it is zero, it can never grow (or we have a bug anyway).

> + set_mm_exe_file(mm, exe_file);
> + exe_file = NULL;
> + } else
> + err = -EBUSY;
> + up_write(&mm->mmap_sem);
> +
> +exit:
> + if (exe_file)
> + fput(exe_file);

This doesn't look correct, you need fput() in any case.
set_mm_exe_file() does another get_file().

Oleg.



\
 
 \ /
  Last update: 2012-03-09 13:57    [W:0.121 / U:0.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site