From patchwork Mon May 7 07:52:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrill Gorcunov X-Patchwork-Id: 10383397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C89DD6037F for ; Mon, 7 May 2018 07:56:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD1B128B11 for ; Mon, 7 May 2018 07:56:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B122528B1E; Mon, 7 May 2018 07:56:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7C1728B11 for ; Mon, 7 May 2018 07:56:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D39586B026A; Mon, 7 May 2018 03:56:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CE8FD6B026B; Mon, 7 May 2018 03:56:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFFD96B026C; Mon, 7 May 2018 03:56:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf0-f72.google.com (mail-lf0-f72.google.com [209.85.215.72]) by kanga.kvack.org (Postfix) with ESMTP id 503A56B026A for ; Mon, 7 May 2018 03:56:43 -0400 (EDT) Received: by mail-lf0-f72.google.com with SMTP id h129-v6so8674984lfg.14 for ; Mon, 07 May 2018 00:56:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:user-agent:date:from :to:cc:subject:mime-version:content-disposition; bh=Vr7lCvWgpqjZk0Bv96O3Re6L1DFzkq1meLx88FS4KEI=; b=Jd8i+AqLx4z43BRcjQvXMoVOmDkG6QEucay/4V4i/4dCgWg8aEUm3hN60RT9uwj3MI FBI7U1mSNVIj5A9upIW9tVRwP6EYgMxHtvlXnqVvLyp2T95m4aS55dqEArY5jfHKEF6I Ciuxu0DE2rdxFFvMSPuCEUSg/AjbnGt3BYDx5+BYIkj6CJWQQbVuJLIb0o6yOLzfIs60 IhWJC+xDJjRzUPwLa1YVQdYrwBPDFF3CAq35uEBfR97j7qV72PN+6e6wAlK9wY8Pm+xN 892rqFCa1k62KZb3Kf7WPhf11H2/xWbks03r7s6ZnXO1IaHaOH33/i8/YfAxGCDV+k/G qaig== X-Gm-Message-State: ALQs6tCI4WcQ3VlRvcHowiIQ8nIvWFo4dVtPP4WB/hR6/BII+sudZWcU 4EZDvPF57m7h51NqS61CFLX6IklKsId0Ke39VMU0XK8DQuPh2wEUXe4hLP373pRMndkSuFQrl0L jPGM8s/kHJYi+zNENvaKoa8a69ZThQuk24w2tF5xZ+yGHaTIN9Z5vmLtoCjT3crHb/e93OwJrXW kk6xVWXtwL4JTRay90M1Zv/vBRQbd6Jnl02xLvZrzDZBSsYfrn2qhxjg1UycOTSBvjci5i6QpLh NhJ/r3YTDos+mWKm7v2EQPDi3kOd3rbI3H3XCEGnj1VvJ2r7knP7ySV/uDvVcXP5Af4VV3mY6FF E62jTAdpFZ0yxndE8qUPu+lUS5kp9kia7tiLmOm6unnnMyMoZAd36xH0tBjH+IFz7kQSuczcAr0 g X-Received: by 2002:a19:6b15:: with SMTP id d21-v6mr22009669lfa.123.1525679802784; Mon, 07 May 2018 00:56:42 -0700 (PDT) X-Received: by 2002:a19:6b15:: with SMTP id d21-v6mr22009653lfa.123.1525679802209; Mon, 07 May 2018 00:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525679802; cv=none; d=google.com; s=arc-20160816; b=my7x3tqx9BZX9Zf1lJdXLTpQopAIQbLGYSZlVSaih1XgI7Am8VYNXzKAMROehs+9A6 EjWJoAlVUzhC5jWm62NZQ0NvOK+yMB88zpUY6Vq4ndX0W/hnzSkJU9hIvOEuyjJIoYHj VrPkoDSoeD8pBqfe0/O9ZrcUpEZYrFsw5C3aBbddKvSlTQhmgFswxpI/fOMpCT3qvzhu tAu+hCGRoNJvG99nh4Fs8dnc4Auq9d8QDxJw+i6FVY1OhQDuRFx9otHON9HDMTKW5m1n 7HEnmnwb6v1GDlf3LxSMwMBGq5DxeMBDEp2Y9ii34/yCOZjN7We93zyItNzg7wEtHIFp u52A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:subject:cc:to:from:date:user-agent :message-id:dkim-signature:arc-authentication-results; bh=Vr7lCvWgpqjZk0Bv96O3Re6L1DFzkq1meLx88FS4KEI=; b=rI4MTk7jWAtVSMzhrJkn7nSg3a9UkYGVOLXrIEwyC3XE89Szfls/WCjhkXbY4KbY2Z m2A07P9fyvTV8q3/dZH89XA/nV5uq9wDLnjYu/b1KCxBG3jbDwUGfKQurcc+CCpuO169 TM0WskXEqdOot5ow7Tj5ZpU1jXuS5yiDXEi+Z/zeary91LDIOEVbhpVEeBVo/7J8fc9k 2NpehsB6Ti7eGbg7jLkw0vOpx0ZCvTVFMBDUK3Itx58jEOHFmJUuiV+3bR5/P85Fk47C eCrvFANuHI8ACnaJdBnrc/5HYtzaL/1As7wN7GcQ074Vo4CyryeJWpan1E8C3JkwHQoj Ivag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=czFsMmLU; spf=pass (google.com: domain of gorcunov@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=gorcunov@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id l18-v6sor1247339lfi.69.2018.05.07.00.56.42 for (Google Transport Security); Mon, 07 May 2018 00:56:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gorcunov@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=czFsMmLU; spf=pass (google.com: domain of gorcunov@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=gorcunov@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:user-agent:date:from:to:cc:subject:mime-version :content-disposition; bh=Vr7lCvWgpqjZk0Bv96O3Re6L1DFzkq1meLx88FS4KEI=; b=czFsMmLUtGxwQcAXw166tm1p5bfcucn1e1ZIL+BFYs7S3Uz71mhNtrJVB263pQ0anj nSk2iv2Noe4bHSGj90poGZXOkqN9dhQsEDPs7OI2BWVD2IwtBBeVLw6URjSdbd6dNNS3 fyQD3w6Na/otdJtcO9gN4V5R2HHc/XoPWW5FRMuvDb+bpZOwOsc1p2oKMAHQ/TEIwiq3 behb6w1CxRLsiLBXMZobEfueNUMSXmkGzUeOSfIc7Ncz7k1Fn9tcbJvf3vlJFKxgQhAo LzPNGZttHZ+NZ4SeMi9g2YQ/HhOdRp2K2N+ZuhXN2C56czGpChUFd4RBvFIUxCOpM3Nm lD4A== X-Google-Smtp-Source: AB8JxZqggVD0BPftGpblpz+/OD5f1ZO4g6mQmcFzhOQkD2feAX81O9mUD5MCnfUrFqY//4iullhWpg== X-Received: by 2002:a19:ead6:: with SMTP id y83-v6mr2840944lfi.117.1525679801843; Mon, 07 May 2018 00:56:41 -0700 (PDT) Received: from uranus.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id y5-v6sm3858681ljd.12.2018.05.07.00.56.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 00:56:40 -0700 (PDT) Received: by uranus.localdomain (Postfix, from userid 1000) id E413646075E; Mon, 7 May 2018 10:56:06 +0300 (MSK) Message-Id: <20180507075606.870903028@gmail.com> User-Agent: quilt/0.65 Date: Mon, 07 May 2018 10:52:16 +0300 From: Cyrill Gorcunov To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jonathan de Boyne Pollard , Andrey Vagin , Andrew Morton , Michael Kerrisk , Yang Shi , Michal Hocko , Cyrill Gorcunov Subject: [rfc linux-next 3/3] [RFC] prctl: prctl_set_mm -- Bring back handling of PR_SET_MM_x MIME-Version: 1.0 Content-Disposition: inline; filename=prctl-back-set-mm-x X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Recently the handling of PR_SET_MM_x been removed because we wanted to improve locking scheme over mm::arg_start,arg_end and etc. Thus to reduce code modification the old PR_SET_MM_x operations have been removed (since initially they've been introduced for c/r sole sake). Before making remove I googled if there are some users of this interface exist and happened to miss that at least systemd is already using PR_SET_MM_ARG_START and PR_SET_MM_ARG_END (see src/basic/process-util.c) Also Jonathan pointed me that there is a need for sole PR_SET_MM_x operations. https://lkml.org/lkml/2018/5/6/127 Here is a trick: since prctl_set_mm_map now accepts struct prctl_mm_map as an argument we can fetch current mm settings, modify the member requested and send the map into prctl_set_mm_map directly, which simply gonna be like an emulation of PR_SET_MM_MAP. Thus users of PR_SET_MM_x should be able to continue utilizing the interface. CC: Jonathan de Boyne Pollard CC: Andrey Vagin CC: Andrew Morton CC: Michael Kerrisk CC: Yang Shi CC: Michal Hocko Signed-off-by: Cyrill Gorcunov --- kernel/sys.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 8 deletions(-) Index: linux-ml.git/kernel/sys.c =================================================================== --- linux-ml.git.orig/kernel/sys.c +++ linux-ml.git/kernel/sys.c @@ -1815,7 +1815,6 @@ SYSCALL_DEFINE1(umask, int, mask) return mask; } -#ifdef CONFIG_CHECKPOINT_RESTORE /* * WARNING: we don't require any capability here so be very careful * in what is allowed for modification from userspace. @@ -2046,19 +2045,36 @@ static int prctl_set_mm_map(struct prctl up_read(&mm->mmap_sem); return 0; } -#endif /* CONFIG_CHECKPOINT_RESTORE */ static int prctl_set_mm(int opt, unsigned long addr, unsigned long arg4, unsigned long arg5) { -#ifdef CONFIG_CHECKPOINT_RESTORE + static const unsigned char offsets[] = { + [PR_SET_MM_START_CODE] = offsetof(struct prctl_mm_map, start_code), + [PR_SET_MM_END_CODE] = offsetof(struct prctl_mm_map, end_code), + [PR_SET_MM_START_DATA] = offsetof(struct prctl_mm_map, start_data), + [PR_SET_MM_END_DATA] = offsetof(struct prctl_mm_map, end_data), + [PR_SET_MM_START_STACK] = offsetof(struct prctl_mm_map, start_brk), + [PR_SET_MM_START_BRK] = offsetof(struct prctl_mm_map, brk), + [PR_SET_MM_BRK] = offsetof(struct prctl_mm_map, start_stack), + [PR_SET_MM_ARG_START] = offsetof(struct prctl_mm_map, arg_start), + [PR_SET_MM_ARG_END] = offsetof(struct prctl_mm_map, arg_end), + [PR_SET_MM_ENV_START] = offsetof(struct prctl_mm_map, env_start), + [PR_SET_MM_ENV_END] = offsetof(struct prctl_mm_map, env_end), + }; + struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, }; + struct mm_struct *mm = current->mm; + + if (arg5 || (arg4 && (opt != PR_SET_MM_AUXV && + opt != PR_SET_MM_MAP && + opt != PR_SET_MM_MAP_SIZE))) + return -EINVAL; + if (opt == PR_SET_MM_MAP_SIZE) return put_user((unsigned int)sizeof(struct prctl_mm_map), (unsigned int __user *)addr); if (opt == PR_SET_MM_MAP) { - struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, }; - if (arg4 != sizeof(prctl_map)) return -EINVAL; @@ -2068,10 +2084,43 @@ static int prctl_set_mm(int opt, unsigne return prctl_set_mm_map(&prctl_map); } -#endif - pr_warn_once("PR_SET_MM_* has been removed. Use PR_SET_MM_MAP instead\n"); - return -EINVAL; + 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); + + if (opt < 1 || opt >= ARRAY_SIZE(offsets)) + return -EINVAL; + + /* + * Emulate PR_SET_MM_MAP call by filling with + * current values and setting one field from + * the request. + */ + down_read(&mm->mmap_sem); + spin_lock(&mm->arg_lock); + prctl_map.start_code = mm->start_code; + prctl_map.end_code = mm->end_code; + prctl_map.start_data = mm->start_data; + prctl_map.end_data = mm->end_data; + prctl_map.start_brk = mm->start_brk; + prctl_map.brk = mm->brk; + prctl_map.start_stack = mm->start_stack; + prctl_map.arg_start = mm->arg_start; + prctl_map.arg_end = mm->arg_end; + prctl_map.env_start = mm->env_start; + prctl_map.env_end = mm->env_end; + spin_unlock(&mm->arg_lock); + up_read(&mm->mmap_sem); + + *(unsigned long *)((char *)&prctl_map + offsets[opt]) = addr; + + return prctl_set_mm_map(&prctl_map, opt); } #ifdef CONFIG_CHECKPOINT_RESTORE