Received: by 10.192.165.148 with SMTP id m20csp201880imm; Thu, 19 Apr 2018 19:39:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/znxPYVt0giRQP6sAYvdw5XHQ8P5TTRqg+ItaeZjNdMHioMYiM4akPirBQGREOJMm4kyAM X-Received: by 10.101.82.197 with SMTP id z5mr7085469pgp.45.1524191975106; Thu, 19 Apr 2018 19:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524191975; cv=none; d=google.com; s=arc-20160816; b=KZYW+kK1TO88tMBpsEjQzRE1wZoDx+xvPMIopgGey4rW1/luC1C5ekWm7vpGCvkSsq x0oCUfkS/YaWIJ6N7Vsa9UATnv31Jl8sANk830yg53fdwOQKUMABGnMLrsvME7zZT5wv DaquZJRwrWOWvGJPaQlKv82CA2Pf1ySOQVVgMw+HyCRlLI30anWZObdTnecv3qupgPGy XhylMOXP41OYzD9vaIJnUmpzcPWQBZli5AdM1Clp9HkCMYxO65JlbOQOflifSh/1RYr/ F9SESDxceMj8G1CjjsDJHNCc/Zgr8otBcOIbTtzGEL3t1R7/Zoqa4uGCcDqBt11ONmkp PsWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=ZSkBP6gIV6pKN9pLwBVED/oT3+EupgpGD+3DRGhDcx8=; b=X2/q9r7AhH0isRnltUO6u5YDyPNzvCdxN7z960pQW3zHWaBUUOPhSNJZU+4TLEMjEQ hO6Vdu8q1u9z+ZnSVhIK5Nh4zJkvQFw4zNPQ9cBCJE39Sc6q8mW4EwKNs0plqvCkMNt+ 1drfByec9Gf7h/F+S7demEl9Rhi4dDhOOh1qimT3F3NteaICZ4YPO5Nt9fCjrsPsLRx1 sYi3QPChtDeqvP/f4JzPHJumoWHBGIwxwvuNQRP9MZsxwYBH0DMvoto3K75t3KyPkbJL iTq5LMpTuwVdQm5k0Rt48Co4uoV0jT5IF+taO78LVAlkNAuKTNywmPIqR2JZD4IJSsCx DDfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eYPBIUiO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91-v6si4589102plf.78.2018.04.19.19.39.20; Thu, 19 Apr 2018 19:39:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eYPBIUiO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754108AbeDTCiQ (ORCPT + 99 others); Thu, 19 Apr 2018 22:38:16 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:42676 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753954AbeDTCiO (ORCPT ); Thu, 19 Apr 2018 22:38:14 -0400 Received: by mail-pg0-f68.google.com with SMTP id e12so3378030pgn.9 for ; Thu, 19 Apr 2018 19:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZSkBP6gIV6pKN9pLwBVED/oT3+EupgpGD+3DRGhDcx8=; b=eYPBIUiObW1CO8f3bW6/C3K/A6H1CiitPexQwmjKsMw2vFHcUtBtACVEEc8R5M7trW cNdeGl+16zfsHnBHbMoGt2NevzCg9fSPdxqSzhiR6kvl0Heb6r1di9Wc2xB5V7jsn7LF uhutd4Xf/AGhY373V3EdrJlGhRXoJoDvSjmVFECP1joKyyZjIjygFeid8VBWYUr6B/uj 41K4yeTb22l4pOU1DIhdkTf9Uu2x3+2jtwzCJHCr+OlMc3EGAF3G9a608AgblL0nMHP4 m/Axu8sVKBV3DJ6eYtJHjsfbnHnNfMkZsqHJln9hbfM4og2AhzLzha2VLjdh+RoJzauX Rclw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZSkBP6gIV6pKN9pLwBVED/oT3+EupgpGD+3DRGhDcx8=; b=UcIGmRW9R+JfUD0wt5eTbUycoy4q7SfLWoln0mg4rPUAW58KcNIFTjnTDXyqk3lci8 FyT2SijB5q9uLAwgyrY7Hz6Z+xKwtwBRx/CyWk9bwPb79IXPn42PUqjL4ILr1UiAEwvw dWcgigMl8XSSRykcpC5g702lREXocqCGX4SejTMLmxWdqXfIg3nICNE1oFyiSZbocT8N 3H92d77e4LYn3uy+WVel1njxtfNp0BKo5G7T5ypQdKu9amYdRgA4YqdKBD7iWBFve6jW Kz2riGAP7CGvx1wFYC2vH7lSdvN6HjeiTG3GhURPFeL/LMuroFpRaEVmB0O7+CvircqF Jc7w== X-Gm-Message-State: ALQs6tCQRIBXnIFSODsks3xfRFlV4Fps0fQoJHsMS4K/GX3r2TpXYH6R IliHgbKuUe/EiUkrF73iiY0= X-Received: by 10.101.81.131 with SMTP id h3mr7014614pgq.110.1524191894026; Thu, 19 Apr 2018 19:38:14 -0700 (PDT) Received: from localhost ([39.7.53.105]) by smtp.gmail.com with ESMTPSA id i186sm8240304pfg.53.2018.04.19.19.38.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Apr 2018 19:38:12 -0700 (PDT) Date: Fri, 20 Apr 2018 11:38:09 +0900 From: Sergey Senozhatsky To: Cyrill Gorcunov Cc: LKML , Michal Hocko , Randy Dunlap , Andrey Vagin , Andrew Morton , Pavel Emelyanov , Michael Kerrisk , Yang Shi Subject: Re: [v2] prctl: Deprecate non PR_SET_MM_MAP operations Message-ID: <20180420023809.GD6397@jagdpanzerIV> References: <20180405182651.GM15783@uranus.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180405182651.GM15783@uranus.lan> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (04/05/18 21:26), Cyrill Gorcunov wrote: [..] > - > #ifdef CONFIG_CHECKPOINT_RESTORE > if (opt == PR_SET_MM_MAP || opt == PR_SET_MM_MAP_SIZE) > return prctl_set_mm_map(opt, (const void __user *)addr, arg4); > #endif > > - if (!capable(CAP_SYS_RESOURCE)) > - return -EPERM; > - > - if (opt == PR_SET_MM_EXE_FILE) > - return prctl_set_mm_exe_file(mm, (unsigned int)addr); > - > - if (opt == PR_SET_MM_AUXV) > - return prctl_set_auxv(mm, addr, arg4); Then validate_prctl_map() and prctl_set_mm_exe_file() can be moved under CONFIG_CHECKPOINT_RESTORE ifdef. --- kernel/sys.c | 126 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/kernel/sys.c b/kernel/sys.c index 6bdffe264303..86e5ef1a5612 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1815,68 +1815,7 @@ SYSCALL_DEFINE1(umask, int, mask) return mask; } -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); - } - - err = 0; - /* set the new file, lockless */ - get_file(exe.file); - old_exe = xchg(&mm->exe_file, exe.file); - if (old_exe) - fput(old_exe); -exit: - fdput(exe); - return err; -exit_err: - up_read(&mm->mmap_sem); - fput(exe_file); - goto exit; -} - +#ifdef CONFIG_CHECKPOINT_RESTORE /* * WARNING: we don't require any capability here so be very careful * in what is allowed for modification from userspace. @@ -1968,7 +1907,68 @@ static int validate_prctl_map(struct prctl_mm_map *prctl_map) return error; } -#ifdef CONFIG_CHECKPOINT_RESTORE +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); + } + + err = 0; + /* set the new file, lockless */ + get_file(exe.file); + old_exe = xchg(&mm->exe_file, exe.file); + if (old_exe) + fput(old_exe); +exit: + fdput(exe); + return err; +exit_err: + up_read(&mm->mmap_sem); + fput(exe_file); + goto exit; +} + static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data_size) { struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, };