Received: by 10.192.165.148 with SMTP id m20csp394119imm; Fri, 20 Apr 2018 00:39:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+C6zE3erO7g3v57Ez2pZU84O+WobfQQSjqhG3CNceEYZkcKK0/c+2BrvKE4F6gEwEz2FoS X-Received: by 10.98.160.68 with SMTP id r65mr8525495pfe.235.1524209991229; Fri, 20 Apr 2018 00:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524209991; cv=none; d=google.com; s=arc-20160816; b=Sycj6FSytWofQJAHipqCnE58Zvz2uK0McPGuw/hMZ3rEXM5GHrTwTRTDQHVjnHtJ59 beRhnOpxZ/FZLZcuRR4ZzPgoHNXxm1Uo06kwUgO9LbjcRWiJ9Z43hYeBrx8cXFHouILw Ow5k19LGBVeQijG//JmgF8jfLdhV2zjGxKcqToRfHeAjTWPMN7yTeEcH9/7UKebIKDnT O6NhHShWLw47ra7m+zQF2ES9ls7wkEE3mJ6IKysRPN2k9SGrxipb1GuXXtTXdDdNa52h bXC7DhFREYCM3B72F7nAPPXCDDaG4HIWrFi7iLq+CNNbtMB0vJ9paL7MBZAQn2OWB5FX IvLA== 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=49yU7vZwxvSoJneMyj28Z9s1Gy9jANj6dG38mDyBsJE=; b=kMN+xSjRzsp42FWvvZX+enI5oN81cyk/DG3ITCtgoIx9Xqc09jXWmhm0iGrJXdM6OK 7PV+VXOyfHdRuDBwM3UlMhEWas1TaezRDM4Vl10UDiBVmzM7D6x1+PbGzIET3Uq9/vD5 gyL1BVwCGwoYIDJ5QvToZAt4PWu/IfeFyChqjKkHqy1QyGf2UF0Pv+Bv60suS4VCZE9I qA5+UkyRpKI+Zd67nXa/OSchWFBDMSJxnBkoiVI4nh/XKOHoV56a7WwTlB50K7fFEc36 GCrHvyz8o2KsILw43yXAkUgq+olBB1BH+cOHTITA5+xF70oZIqYN/uirNvTSjqb95D+m 6iHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ixxtxBwV; 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 z12si4171916pgv.226.2018.04.20.00.39.36; Fri, 20 Apr 2018 00:39:51 -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=ixxtxBwV; 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 S1753984AbeDTH3K (ORCPT + 99 others); Fri, 20 Apr 2018 03:29:10 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34217 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753935AbeDTH3I (ORCPT ); Fri, 20 Apr 2018 03:29:08 -0400 Received: by mail-pf0-f194.google.com with SMTP id q9so3883380pff.1 for ; Fri, 20 Apr 2018 00:29:08 -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=49yU7vZwxvSoJneMyj28Z9s1Gy9jANj6dG38mDyBsJE=; b=ixxtxBwV8QttUGbxH07XwFf/3gJVmZqKnpKEzDt50UkGWIDQ3TV2Mf+Fw24/xHSbXg GBiRFXmcYqVEivU16WbPRsip6FHKBMj5XenE4/uDMHUKuQ5WIy1Z4RoqJH4/kFh7IPsI /AgKdkkrNXZvD/ubvketrgU8yWoyOc+zWU2Su6eI9MisZxNVgJxPce0cgmy9SIccNe2N KiCq46GjWx4kUtGwlNwOxtYUP9dPtTbeiJNd3Vt6JLMFLxmPl2ix74l6RFWadRpd2Scb WMqQv1AMIfWmG3LIZUTEQsVo+YaWGUT8KvvUZUGww2xSzkR+YCyWJYZ8ZQni6keJz/kb azfA== 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=49yU7vZwxvSoJneMyj28Z9s1Gy9jANj6dG38mDyBsJE=; b=aSFYbHWFEnivifpeXxQWpyhGrRgNYzHGVtGhF85e5ATms5d7w8OT6Rzw3XaOLNC63m CSS8PBFgRS49t4ExWdYXlvu0UGViU/UctLtvZNbYhC2yhT15Y4tALTcE0Z03AUbaDwdy lf+4g0nmMOLuR9UF+tv32au5hV1dItSoU83of+x9PihiynjJEj3cuVVj6Pf9mgM1rH1n E56SMRqh+niBahkvPly+n9o1ZVNKPEm8mXIht9AWtYC0eherUxngSrk8gZSpFppGV3fS n2LmYvKo5c3xuO3bqK7iZN5y53SYwWZmRLZ6iqQHaKwAHwxbNY4gqL2gZHMavIr3hxOm yTuA== X-Gm-Message-State: ALQs6tBv0BMz3UIltAlcvqfspP3vH8JVinJATxZmlKeMxFDusbOkO9AC IswVXXN8vwzjTPtT9N3mzeA= X-Received: by 10.99.50.134 with SMTP id y128mr7850890pgy.419.1524209347900; Fri, 20 Apr 2018 00:29:07 -0700 (PDT) Received: from localhost ([39.7.53.105]) by smtp.gmail.com with ESMTPSA id r80sm478425pfe.44.2018.04.20.00.29.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Apr 2018 00:29:06 -0700 (PDT) Date: Fri, 20 Apr 2018 16:29:03 +0900 From: Sergey Senozhatsky To: Cyrill Gorcunov Cc: Sergey Senozhatsky , 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: <20180420072903.GA594@jagdpanzerIV> References: <20180405182651.GM15783@uranus.lan> <20180420023809.GD6397@jagdpanzerIV> <20180420070257.GJ19578@uranus.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180420070257.GJ19578@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/20/18 10:02), Cyrill Gorcunov wrote: > On Fri, Apr 20, 2018 at 11:38:09AM +0900, Sergey Senozhatsky wrote: > > 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. > > I don't mind. Could you please make the patch on top of linux-next? As far as I can see, it's not in linux-next yet. So the following is against the mmots tree. I wouldn't mind it if we could just squash the patches. ======================================================================= From: Sergey Senozhatsky Subject: [PATCH] prctl: Don't compile some of prctl functions when CRUI disabled CHECKPOINT_RESTORE is the only user of validate_prctl_map() and prctl_set_mm_exe_file(), so we can move those two under CONFIG_CHECKPOINT_RESTORE. Signed-off-by: Sergey Senozhatsky --- 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, }; -- 2.17.0