From patchwork Mon May 7 07:52:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyrill Gorcunov X-Patchwork-Id: 10383393 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 3482B6037F for ; Mon, 7 May 2018 07:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 296A928B10 for ; Mon, 7 May 2018 07:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BE3F28B1B; Mon, 7 May 2018 07:56:34 +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 87B3928B10 for ; Mon, 7 May 2018 07:56:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 940FE6B0269; Mon, 7 May 2018 03:56:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8F0666B026A; Mon, 7 May 2018 03:56:32 -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 808016B026B; Mon, 7 May 2018 03:56:32 -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 1275A6B0269 for ; Mon, 7 May 2018 03:56:32 -0400 (EDT) Received: by mail-lf0-f72.google.com with SMTP id o98-v6so3620069lfg.2 for ; Mon, 07 May 2018 00:56:32 -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=W5Ego1j25xgYkLt17ECC0ZvEZZZx1S9uyNJQo/BxMr8=; b=co43/NGJEU/C0LExFdIr+ZJoIdI/Z4W6r1RfgeAxlMQCvvFq8K9j4LVQ0U+pGqoc2l qWUxGaSKgzOyEEXQITEJK/jjcoj+iNnBUkKtHibw+uUZmkq0fPvEBPr2QtMaPGYqnaOZ m5MFDxfxlnK9/b1WmpPH9g1dybdR8jYGAGjgF0TJETWGnMCveZftSfi0VXr+InvSsCYh mztyWzioR+W0OTPAM8mCUA5nzUJEbg9tuRrvHTJm0k56YqJr5fGYo49DvmDXg6ktQ56t Q1FLBpPvFTnITk1N7YQyRFXb0x0RrUXsaiTcXDneVlt1PEbw6woA8ajY7ePUCGGzQT8K qovQ== X-Gm-Message-State: ALKqPweei6oXmMPvBdN4H+3MK7o/PBuTTCYQkEVkwcVefWVShc3MdPry puObXmgp/JR1D+bMS6WoTUjT9t6o2hQ6id8k2u8gv3irrYuMJ51J3oSKXuO9mYWMUk5g0X1K/Ox EGFOeOQi/LCBw+/J3nKJTvLwVTKn0Hxw9BAB2ukLWyEsAshMIaWOBDty8R4FRLYpjO8LL1KeGP2 RsbzFy+MIXqMYvMZfOqycGICm0LE0i/u2kP/fblDwdDPJkPGk+9Xy8gS2gamWGUF4KW/2MHBOMC KeQpT6J9H9zLCecnwXVTu7ukJa277lcT35s8c8kO4bF1aj2kUfj0i61ya+WOJVLCOUy/+glR8e2 kv0D6TEgWeUpTzEl8SiVv9h+Oez8F16Rrg2eCM6XPbcs73NAbtw3KLGPbOzfHxeMmQ6ngTngN3p a X-Received: by 2002:a19:c6c1:: with SMTP id w184-v6mr750350lff.126.1525679791536; Mon, 07 May 2018 00:56:31 -0700 (PDT) X-Received: by 2002:a19:c6c1:: with SMTP id w184-v6mr750319lff.126.1525679790891; Mon, 07 May 2018 00:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525679790; cv=none; d=google.com; s=arc-20160816; b=n1Wdb+EASUHFpTDpF2ECb9gNVbpmgDbUMlnD1F42TpDUjTys/3hrxbImOu0jHoIaXJ Am83npZ5zoL7o1cojGHpEyhxgaYK7MZGgp5dcSgC2R4yyb5yjy8M5vE0Jg3ujH0STo45 dUtPmiWUkhoJMNaXCGzguCu021pgkNiL9zzYnU2woHtPqT3nWQhPnKo6w1xtpJ7iHFW1 5VwoZ/tutKUFK7U7cnBm8sp8QM8ECwsO0ryIycbB7CbqRLY4L6bl3dPCmYRf20kNNhMo 8cA21mlTcreiHDcxVSJdrclDNWQyJ1h+L93/hmzt9M6/ASdyJ85gwkej4n1mubxi2z3B pYWw== 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=W5Ego1j25xgYkLt17ECC0ZvEZZZx1S9uyNJQo/BxMr8=; b=P/t25nj8zTGNfDDx+yyFt4RUK6+YLSxrYnoHtRQneTPTnrjnUSPkepbfAAycwQnCs/ zv2iKvRMLBf85wxX/qAo+FW1GuCGPg/JQ1Jhstg1ucf6Lf4XCXDn/Uk+w2ithty+Nkkl v35UzBmWSTX1gCWEBuQxu2VAWRZM7i76jeqPBBv/3YcRtba3xZwv8AJuK4yqCyDQTmuh BZ1siIoD6rYYjMYY2Qrbi+03CnunJwBmBQaGGXy5G/4iPYTE8N4ZZ50k4Lp69NHE/1SM VoJszunWVMGRONvKqitXm+wQdDAQcJy1Lxls9Z8pAoHebO9O5o8OBCncBqpizlZVd9F3 FOzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZtbowRvn; 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 h8-v6sor2518184lfj.49.2018.05.07.00.56.30 for (Google Transport Security); Mon, 07 May 2018 00:56:30 -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=ZtbowRvn; 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=W5Ego1j25xgYkLt17ECC0ZvEZZZx1S9uyNJQo/BxMr8=; b=ZtbowRvn21fx0WBttA0xFmDece5Ol9T82dCG6EZvc0pulE5EzpT0ahLyNXJSnnxVhn 6nZSbibXJpewm0KoAeEMLqFgNKhFn3BGKusBaeclvPj0JgIX+T8N78pB8C6+CIRWlVfm K5KsOg01/XJGYPdOTjPv7nd5qcngC2xvF8kFBLD1nmi/A82+g2ZQ2cCSFrwvo5xgAhDj w9HYTiyGkBJTtihzVChCQ8x13dHoEeS532CtdVSTODSvH615ymJMJwUCYFJUUS0/5DyE lvU3hUaVDoLGUDEpqBoYmHrpXQaOmmNIW/iLDqXLHd67/yAVMfyShqXA8txaACNAxH6I +Blw== X-Google-Smtp-Source: AB8JxZrzstPumuaUXqQ4jJgGG4ygGCzAatC2FrUcAYgwjYHa7EsIlMOINWszo7eNWGqmZiq/D0lzXQ== X-Received: by 2002:a19:ebdd:: with SMTP id f90-v6mr2594282lfk.20.1525679790550; Mon, 07 May 2018 00:56:30 -0700 (PDT) Received: from uranus.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id l10-v6sm4166023lja.62.2018.05.07.00.56.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 00:56:29 -0700 (PDT) Received: by uranus.localdomain (Postfix, from userid 1000) id D030C46075D; Mon, 7 May 2018 10:56:06 +0300 (MSK) Message-Id: <20180507075606.786573575@gmail.com> User-Agent: quilt/0.65 Date: Mon, 07 May 2018 10:52:15 +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 2/3] [RFC] prctl: prctl_set_mm -- Make prctl_set_mm_map to accept map as an argument MIME-Version: 1.0 Content-Disposition: inline; filename=prctl-use-prctl_map 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 Once we make it to accept struct prctl_mm_map as an argument it will be possible to reuse this functionallity for the rest of PR_SET_MM_x operations. Here we simply allocate struct prctl_mm_map in a caller and provide it downstairs. 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 | 59 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) Index: linux-ml.git/kernel/sys.c =================================================================== --- linux-ml.git.orig/kernel/sys.c +++ linux-ml.git/kernel/sys.c @@ -1969,9 +1969,8 @@ exit_err: goto exit; } -static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data_size) +static int prctl_set_mm_map(struct prctl_mm_map *prctl_map) { - struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, }; unsigned long user_auxv[AT_VECTOR_SIZE]; struct mm_struct *mm = current->mm; int error; @@ -1979,21 +1978,15 @@ static int prctl_set_mm_map(int opt, con BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv)); BUILD_BUG_ON(sizeof(struct prctl_mm_map) > 256); - if (data_size != sizeof(prctl_map)) - return -EINVAL; - - if (copy_from_user(&prctl_map, addr, sizeof(prctl_map))) - return -EFAULT; - - error = validate_prctl_map(&prctl_map); + error = validate_prctl_map(prctl_map); if (error) return error; - if (prctl_map.auxv_size) { + if (prctl_map->auxv_size) { memset(user_auxv, 0, sizeof(user_auxv)); if (copy_from_user(user_auxv, - (const void __user *)prctl_map.auxv, - prctl_map.auxv_size)) + (const void __user *)prctl_map->auxv, + prctl_map->auxv_size)) return -EFAULT; /* Last entry must be AT_NULL as specification requires */ @@ -2001,8 +1994,8 @@ static int prctl_set_mm_map(int opt, con user_auxv[AT_VECTOR_SIZE - 1] = AT_NULL; } - if (prctl_map.exe_fd != (u32)-1) { - error = prctl_set_mm_exe_file(mm, prctl_map.exe_fd); + if (prctl_map->exe_fd != (u32)-1) { + error = prctl_set_mm_exe_file(mm, prctl_map->exe_fd); if (error) return error; } @@ -2026,17 +2019,17 @@ static int prctl_set_mm_map(int opt, con */ spin_lock(&mm->arg_lock); - mm->start_code = prctl_map.start_code; - mm->end_code = prctl_map.end_code; - mm->start_data = prctl_map.start_data; - mm->end_data = prctl_map.end_data; - mm->start_brk = prctl_map.start_brk; - mm->brk = prctl_map.brk; - mm->start_stack = prctl_map.start_stack; - mm->arg_start = prctl_map.arg_start; - mm->arg_end = prctl_map.arg_end; - mm->env_start = prctl_map.env_start; - mm->env_end = prctl_map.env_end; + mm->start_code = prctl_map->start_code; + mm->end_code = prctl_map->end_code; + mm->start_data = prctl_map->start_data; + mm->end_data = prctl_map->end_data; + mm->start_brk = prctl_map->start_brk; + mm->brk = prctl_map->brk; + mm->start_stack = prctl_map->start_stack; + mm->arg_start = prctl_map->arg_start; + mm->arg_end = prctl_map->arg_end; + mm->env_start = prctl_map->env_start; + mm->env_end = prctl_map->env_end; spin_unlock(&mm->arg_lock); /* @@ -2047,7 +2040,7 @@ static int prctl_set_mm_map(int opt, con * not introduce additional locks here making the kernel * more complex. */ - if (prctl_map.auxv_size) + if (prctl_map->auxv_size) memcpy(mm->saved_auxv, user_auxv, sizeof(user_auxv)); up_read(&mm->mmap_sem); @@ -2063,8 +2056,18 @@ static int prctl_set_mm(int opt, unsigne return put_user((unsigned int)sizeof(struct prctl_mm_map), (unsigned int __user *)addr); - if (opt == PR_SET_MM_MAP) - return prctl_set_mm_map(opt, (const void __user *)addr, arg4); + if (opt == PR_SET_MM_MAP) { + struct prctl_mm_map prctl_map = { .exe_fd = (u32)-1, }; + + if (arg4 != sizeof(prctl_map)) + return -EINVAL; + + if (copy_from_user(&prctl_map, (const void __user *)addr, + sizeof(prctl_map))) + return -EFAULT; + + return prctl_set_mm_map(&prctl_map); + } #endif pr_warn_once("PR_SET_MM_* has been removed. Use PR_SET_MM_MAP instead\n");