Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1517794

Re: [PATCH 1/2] kernel: Move prctl and helpers from kernel/sys.c to new kernel/prctl.c

From Cyrill Gorcunov <gorcunov@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] kernel: Move prctl and helpers from kernel/sys.c to new kernel/prctl.c
Date 2016-11-09 08:10 +0100
Message-ID <sBvbb-47b-3@gated-at.bofh.it> (permalink)
References <sBoMp-8k7-9@gated-at.bofh.it> <sBoMp-8k7-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Nov 08, 2016 at 04:18:13PM -0800, Josh Triplett wrote:
> This prepares for making prctl optional.
> 
> Signed-off-by: Josh Triplett <josh@joshtriplett.org>
> +
...
> +static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
> +{
> +	struct fd exe;
> +	struct file *old_exe, *exe_file;
> +	struct inode *inode;
> +	int err;
> +
> +	exe = fdget(fd);
> +	if (!exe.file)
> +		return -EBADF;
> +
> +	inode = file_inode(exe.file);
> +
> +	/*
> +	 * Because the original mm->exe_file points to executable file, make
> +	 * sure that this one is executable as well, to avoid breaking an
> +	 * overall picture.
> +	 */
> +	err = -EACCES;
> +	if (!S_ISREG(inode->i_mode) || path_noexec(&exe.file->f_path))
> +		goto exit;
> +
> +	err = inode_permission(inode, MAY_EXEC);
> +	if (err)
> +		goto exit;
> +
> +	/*
> +	 * Forbid mm->exe_file change if old file still mapped.
> +	 */
> +	exe_file = get_mm_exe_file(mm);
> +	err = -EBUSY;
> +	if (exe_file) {
> +		struct vm_area_struct *vma;
> +
> +		down_read(&mm->mmap_sem);
> +		for (vma = mm->mmap; vma; vma = vma->vm_next) {
> +			if (!vma->vm_file)
> +				continue;
> +			if (path_equal(&vma->vm_file->f_path,
> +				       &exe_file->f_path))
> +				goto exit_err;
> +		}
> +
> +		up_read(&mm->mmap_sem);
> +		fput(exe_file);
> +	}
> +
> +	/*
> +	 * The symlink can be changed only once, just to disallow arbitrary
> +	 * transitions malicious software might bring in. This means one
> +	 * could make a snapshot over all processes running and monitor
> +	 * /proc/pid/exe changes to notice unusual activity if needed.
> +	 */
> +	err = -EPERM;
> +	if (test_and_set_bit(MMF_EXE_FILE_CHANGED, &mm->flags))
> +		goto exit;

IIRC this snippet has been dropped in linux-next tree. Stas CC'ed.
The rest looks cool for me. Thanks!

Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] Support compiling out the prctl syscall Josh Triplett <josh@joshtriplett.org> - 2016-11-09 01:20 +0100
  [PATCH 1/2] kernel: Move prctl and helpers from kernel/sys.c to new  kernel/prctl.c Josh Triplett <josh@joshtriplett.org> - 2016-11-09 01:20 +0100
    Re: [PATCH 1/2] kernel: Move prctl and helpers from kernel/sys.c to  new kernel/prctl.c Andy Lutomirski <luto@amacapital.net> - 2016-11-09 01:30 +0100
    Re: [PATCH 1/2] kernel: Move prctl and helpers from kernel/sys.c to  new kernel/prctl.c Cyrill Gorcunov <gorcunov@gmail.com> - 2016-11-09 08:10 +0100
  Re: [PATCH 0/2] Support compiling out the prctl syscall Arnd Bergmann <arnd@arndb.de> - 2016-11-09 01:30 +0100
    Re: [PATCH 0/2] Support compiling out the prctl syscall Josh Triplett <josh@joshtriplett.org> - 2016-11-09 04:50 +0100
  Re: [PATCH 0/2] Support compiling out the prctl syscall Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-11-09 01:40 +0100

csiph-web