[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120309124811.GA610@redhat.com>
Date: Fri, 9 Mar 2012 13:48:11 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Cyrill Gorcunov <gorcunov@...nvz.org>
Cc: Matt Helsley <matthltc@...ibm.com>,
KOSAKI Motohiro <kosaki.motohiro@...fujitsu.com>,
Pavel Emelyanov <xemul@...allels.com>,
Kees Cook <keescook@...omium.org>, Tejun Heo <tj@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists