From patchwork Tue Apr 30 08:18:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 10923003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 91800933 for ; Tue, 30 Apr 2019 08:19:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82A3C289F4 for ; Tue, 30 Apr 2019 08:19:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7663E289F8; Tue, 30 Apr 2019 08:19:32 +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=-2.9 required=2.0 tests=BAYES_00,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 15D58289F4 for ; Tue, 30 Apr 2019 08:19:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EABA06B0005; Tue, 30 Apr 2019 04:19:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E5D046B0007; Tue, 30 Apr 2019 04:19:28 -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 CAE1B6B0008; Tue, 30 Apr 2019 04:19:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 7ED926B0005 for ; Tue, 30 Apr 2019 04:19:28 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id t58so1464670edb.22 for ; Tue, 30 Apr 2019 01:19:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=fDn6LMx54Jj8tVS5WSjg5QS85E5llcN/rmWDGPkaEho=; b=EWBtFSBsr+PTd9UHKSMANIYd4g6bXjktbfHLaBQ1BuNiGoVsuxmT3cB5qsKW17scHC d41h0BU/mU0oqlLpZ9IL2+KZwM7UErQndSTA/3u/soh+DsA3b/mAHKznukRbdMRfTok1 wBt0V0LhsDBEeCb3FL3EroXcgYKv91fv8gJuIkigGm6QpDHo+0plmHaUsUyvS8Cs3U0Z hsmy0E4Jo8zMrEkbhYrznfTsFAq91tdt3NHNTS6rN44Uqpoih6in/vCRRLIFwyJQnRSm 599dp978An2AkSjv9X4+IaeETJ7NNnFtDxla0sVJ1jr0l751sX6/8+r8ktGzNHS7/hWP zPqw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-Gm-Message-State: APjAAAXfyO8AeOnKqJ9EKGldNSDqIPb5Nuf6XhMkBLIXVXndS5oQkAvs v9a3IlrcgLahNq6ptwQIGJvafIHyblvu1NbHdoOM/WXr6/X88Mwx4efXsDRW2+j72TsmcfAx1eq 9kTLgqu0ZMbrE2O4V/G6DPxy4Yq/iJz8GHG1B4Gp3lUqqzSKwOqWK4Fq86tpIzgx42w== X-Received: by 2002:aa7:c750:: with SMTP id c16mr39915215eds.106.1556612367985; Tue, 30 Apr 2019 01:19:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxJW4CSEaJJSnU7988DevgImsQnZRA1aXUUpR/qtXbGnEqPLvwjtG7T+x/4YMSFsQDFoxt X-Received: by 2002:aa7:c750:: with SMTP id c16mr39915175eds.106.1556612366912; Tue, 30 Apr 2019 01:19:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556612366; cv=none; d=google.com; s=arc-20160816; b=Z3Ey/tz+VGgfdHPxe+kkD8gTBeOP9gIrAA1GvG95Rq+MoZk4nhuuqHl4SOjbshNFwj tUt2MxPAE1pVSEfHL3KCIyF/8KQFgMWtIQOL3Isluu+ibJ+vofuO6qAhrg69uEkv9RNc bgnA7DXEeEKtl9fVEhAeJTEhM/uhmNJJRTWWAfssDOh0yrYjinMfsNNKMlNDrJwafPZO /khxFBOAbSzaM4FqomIY0O6gfFAbsItcPLFnMtsclzGiPpZJaWvA/2sACoI8WaQs+07Z XZBkd+eSoTLrQmKZ+lCgtfyF+OvwKO0YN4s/qEpOrk6Dn6huqIH25jZRF4BgHOxyTSAC ULSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=fDn6LMx54Jj8tVS5WSjg5QS85E5llcN/rmWDGPkaEho=; b=RlbaUvG9bglXwqItQpR4LxXT2IsWbpI3Xese/bIfipG2rDdCwGPT8CWe/m3NEU3d0S k6CYGVALkp861h+ef+GiBMIuisjCS8ywAjIx7ZJ2OjjqiOQ6cGLYGr2JOSCdgGgbik3G O4LUKRMAvqMUYuUPR2hXQvxcxZtIGWlUsDeNjeoWZQVu4rn3g55w3rY1HAGtr7SnPsZ/ QDlWYrTlpCngtOgkX0a6a5FZtITPyq+K/Bz6ixeyN2xDN07Wsl4ZwuvxBztUbNQdG2Ou f/EWoVvdxaonqp8du0JcZoJqYsh2ORPVSqZWuMSslYIANuWQm+IHPuyVZx687nUdKRPG T6+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id 43si40013eds.232.2019.04.30.01.19.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 01:19:26 -0700 (PDT) Received-SPF: pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 85D05AE4F; Tue, 30 Apr 2019 08:19:26 +0000 (UTC) From: =?utf-8?q?Michal_Koutn=C3=BD?= To: gorcunov@gmail.com Cc: akpm@linux-foundation.org, arunks@codeaurora.org, brgl@bgdev.pl, geert+renesas@glider.be, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mguzik@redhat.com, mhocko@kernel.org, mkoutny@suse.com, rppt@linux.ibm.com, vbabka@suse.cz, ktkhai@virtuozzo.com Subject: [PATCH 1/3] mm: get_cmdline use arg_lock instead of mmap_sem Date: Tue, 30 Apr 2019 10:18:42 +0200 Message-Id: <20190430081844.22597-2-mkoutny@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190430081844.22597-1-mkoutny@suse.com> References: <20190418182321.GJ3040@uranus.lan> <20190430081844.22597-1-mkoutny@suse.com> MIME-Version: 1.0 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 The commit a3b609ef9f8b ("proc read mm's {arg,env}_{start,end} with mmap semaphore taken.") added synchronization of reading argument/environment boundaries under mmap_sem. Later commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") avoided the coarse use of mmap_sem in similar situations. get_cmdline can also use arg_lock instead of mmap_sem when it reads the boundaries. Fixes: 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") Cc: Yang Shi Cc: Mateusz Guzik Signed-off-by: Michal Koutný Signed-off-by: Laurent Dufour --- mm/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/util.c b/mm/util.c index 43a2984bccaa..5cf0e84a0823 100644 --- a/mm/util.c +++ b/mm/util.c @@ -758,12 +758,12 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen) if (!mm->arg_end) goto out_mm; /* Shh! No looking before we're done */ - down_read(&mm->mmap_sem); + spin_lock(&mm->arg_lock); arg_start = mm->arg_start; arg_end = mm->arg_end; env_start = mm->env_start; env_end = mm->env_end; - up_read(&mm->mmap_sem); + spin_unlock(&mm->arg_lock); len = arg_end - arg_start; From patchwork Tue Apr 30 08:18:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 10923007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1D1D14DB for ; Tue, 30 Apr 2019 08:19:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 927D9289F5 for ; Tue, 30 Apr 2019 08:19:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80512289F4; Tue, 30 Apr 2019 08:19:35 +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=-2.9 required=2.0 tests=BAYES_00,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 B8AB1289F4 for ; Tue, 30 Apr 2019 08:19:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0796B000A; Tue, 30 Apr 2019 04:19:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 251366B000C; Tue, 30 Apr 2019 04:19:33 -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 0525B6B000D; Tue, 30 Apr 2019 04:19:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id A89FA6B000A for ; Tue, 30 Apr 2019 04:19:32 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id m57so6018689edc.7 for ; Tue, 30 Apr 2019 01:19:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=INByUq3lVa3EFEeFkF0GCwcbXF+CEthavbsWjHwZITo=; b=jPvI0/vRH4BY7xkKuCHh1CEJ4sfqtb4QnOxhXhhfrE/E6DKzXmMdd277RaJlVg/afY 9QFuKmAK3QC+Kj42SNYKQKE5THR60FaFGQ8CR39I658uuMfF+K/dDixhdyNCIgpVFjhy y5CjDa8Ueu0YuhrUlj9U7nYA7Uy78EfctWF/51Fazc6MrJoHEz0uHudcpyxjBG6mfCgg /qtBiEcDBlFVfQCLNTjBOSHXsoxF7CMNq87xvCMsDYhiKQi38kE+ayQxcDiygbylXZL2 vlVLyCv1Ygrt8/4jbXTo/sl8+OtH5D6W1RnS2WJ/OWj1jW7mANT0ucT1HRsEvqKTb1jA 9JDw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-Gm-Message-State: APjAAAUMi+fxckhYgmkwHr3lcZC82Q72Sk47e72R/fapEqozVrF6fxgj 51dQNu61w1q/WFTc75v1Cwlm/PG+v5Gp5nlbt8EDQ/LoAM46rv6QqZlUyiddlIwFyZZbiBkuqAR c3X1V1l1IyIDZQTLP3EdbTMTbipJsXbtMUfY1lIXeStEcYF61kbQHn8g9Oqpx0N5oaw== X-Received: by 2002:a17:906:4988:: with SMTP id p8mr6562564eju.220.1556612372148; Tue, 30 Apr 2019 01:19:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQH4iozUr1MfRRGqxJv8FWF50u1G6R5YGQjPveu/5UcnmOFKMV1bG/Zu00ZF53/cRNiKMP X-Received: by 2002:a17:906:4988:: with SMTP id p8mr6562521eju.220.1556612370601; Tue, 30 Apr 2019 01:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556612370; cv=none; d=google.com; s=arc-20160816; b=RVOzcqqrspetmahYLNy3/DMtBLJAikKNNcnaHqqMjWVPj+1kw9Gh701cn7LyDB5UDr aHF4dum0KA/3wSyypqcArkExE6hxGuHL3Ghh86e+57TrjNLVT0eeDk3dFrUkQNNDi8Dv MOTZ/o5l0q+fCR53VsEROyzQspeNmADEjSNI+wmVL4v8ksfwUGAexdEzdheI47niLY/5 g8c57qY497bMf2nQPFuaGoRXnzz0o55mM5Z7CJU3FDc89B/LK/5x7hYq6eVDO0ePu/Qr 5wOTsoYpEXNsysAwq6NCLAXwEuvTmI1TLs3LJ5G7E6Q2ia5Ccm/sGbhYbC7Ujojdd2uP wVrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=INByUq3lVa3EFEeFkF0GCwcbXF+CEthavbsWjHwZITo=; b=LPYhq8PkKnyzU924fycFbhuxFZIaOyyym5J2oCvFz2ndk+FNsnwvpiBtyt3Qhz+mRI gAmmpZ8uYI3TlcgKjyEb4j974zPno4RsCAhwMKaHC6mqDdKjAeHpPnaqs84xrJHuf/12 xxhzIr79beYZlgN8sKZZljsxo/Ll/RHY9QjHYF0V+g5DKTawgJlUxo6Nk9nIzp0ylw08 JI0hJPO0y7G7b3us6Uons2FbhbCNM+kSl3g0qBxEg+fRXHyngkeWAn/uBKUAr3wb4Bqd zgGjhsb1/ZW6jOznLv9eoDiPY5AKSd2b3R1eEvdO3gnUtXTQ9GvsLtEl7N64h7I45L0o rNQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id y55si3555460edc.206.2019.04.30.01.19.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 01:19:30 -0700 (PDT) Received-SPF: pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 19136AE3F; Tue, 30 Apr 2019 08:19:30 +0000 (UTC) From: =?utf-8?q?Michal_Koutn=C3=BD?= To: gorcunov@gmail.com Cc: akpm@linux-foundation.org, arunks@codeaurora.org, brgl@bgdev.pl, geert+renesas@glider.be, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mguzik@redhat.com, mhocko@kernel.org, mkoutny@suse.com, rppt@linux.ibm.com, vbabka@suse.cz, ktkhai@virtuozzo.com Subject: [PATCH 2/3] prctl_set_mm: Refactor checks from validate_prctl_map Date: Tue, 30 Apr 2019 10:18:43 +0200 Message-Id: <20190430081844.22597-3-mkoutny@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190430081844.22597-1-mkoutny@suse.com> References: <20190418182321.GJ3040@uranus.lan> <20190430081844.22597-1-mkoutny@suse.com> MIME-Version: 1.0 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 Despite comment of validate_prctl_map claims there are no capability checks, it is not completely true since commit 4d28df6152aa ("prctl: Allow local CAP_SYS_ADMIN changing exe_file"). Extract the check out of the function and make the function perform purely arithmetic checks. This patch should not change any behavior, it is mere refactoring for following patch. CC: Kirill Tkhai CC: Cyrill Gorcunov Signed-off-by: Michal Koutný Reviewed-by: Kirill Tkhai --- kernel/sys.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/kernel/sys.c b/kernel/sys.c index 12df0e5434b8..e1acb444d7b0 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1882,10 +1882,12 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) } /* + * Check arithmetic relations of passed addresses. + * * WARNING: we don't require any capability here so be very careful * in what is allowed for modification from userspace. */ -static int validate_prctl_map(struct prctl_mm_map *prctl_map) +static int validate_prctl_map_addr(struct prctl_mm_map *prctl_map) { unsigned long mmap_max_addr = TASK_SIZE; struct mm_struct *mm = current->mm; @@ -1949,24 +1951,6 @@ static int validate_prctl_map(struct prctl_mm_map *prctl_map) prctl_map->start_data)) goto out; - /* - * Someone is trying to cheat the auxv vector. - */ - if (prctl_map->auxv_size) { - if (!prctl_map->auxv || prctl_map->auxv_size > sizeof(mm->saved_auxv)) - goto out; - } - - /* - * Finally, make sure the caller has the rights to - * change /proc/pid/exe link: only local sys admin should - * be allowed to. - */ - if (prctl_map->exe_fd != (u32)-1) { - if (!ns_capable(current_user_ns(), CAP_SYS_ADMIN)) - goto out; - } - error = 0; out: return error; @@ -1993,11 +1977,17 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data if (copy_from_user(&prctl_map, addr, sizeof(prctl_map))) return -EFAULT; - error = validate_prctl_map(&prctl_map); + error = validate_prctl_map_addr(&prctl_map); if (error) return error; if (prctl_map.auxv_size) { + /* + * Someone is trying to cheat the auxv vector. + */ + if (!prctl_map.auxv || prctl_map.auxv_size > sizeof(mm->saved_auxv)) + return -EINVAL; + memset(user_auxv, 0, sizeof(user_auxv)); if (copy_from_user(user_auxv, (const void __user *)prctl_map.auxv, @@ -2010,6 +2000,14 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data } if (prctl_map.exe_fd != (u32)-1) { + /* + * Make sure the caller has the rights to + * change /proc/pid/exe link: only local sys admin should + * be allowed to. + */ + if (!ns_capable(current_user_ns(), CAP_SYS_ADMIN)) + return -EINVAL; + error = prctl_set_mm_exe_file(mm, prctl_map.exe_fd); if (error) return error; @@ -2097,7 +2095,7 @@ static int prctl_set_mm(int opt, unsigned long addr, unsigned long arg4, unsigned long arg5) { struct mm_struct *mm = current->mm; - struct prctl_mm_map prctl_map; + struct prctl_mm_map prctl_map = { .auxv = NULL, .auxv_size = 0, .exe_fd = -1 }; struct vm_area_struct *vma; int error; @@ -2139,9 +2137,6 @@ static int prctl_set_mm(int opt, unsigned long addr, prctl_map.arg_end = mm->arg_end; prctl_map.env_start = mm->env_start; prctl_map.env_end = mm->env_end; - prctl_map.auxv = NULL; - prctl_map.auxv_size = 0; - prctl_map.exe_fd = -1; switch (opt) { case PR_SET_MM_START_CODE: @@ -2181,7 +2176,7 @@ static int prctl_set_mm(int opt, unsigned long addr, goto out; } - error = validate_prctl_map(&prctl_map); + error = validate_prctl_map_addr(&prctl_map); if (error) goto out; From patchwork Tue Apr 30 08:18:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 10923009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD04514DB for ; Tue, 30 Apr 2019 08:19:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0421289F4 for ; Tue, 30 Apr 2019 08:19:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C40F9289F8; Tue, 30 Apr 2019 08:19:37 +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=-2.9 required=2.0 tests=BAYES_00,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 6B6B7289F4 for ; Tue, 30 Apr 2019 08:19:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E85806B000C; Tue, 30 Apr 2019 04:19:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DED8C6B000D; Tue, 30 Apr 2019 04:19:33 -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 B7A006B000E; Tue, 30 Apr 2019 04:19:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 5715B6B000C for ; Tue, 30 Apr 2019 04:19:33 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id n52so2622007edd.2 for ; Tue, 30 Apr 2019 01:19:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ERxQzSRXhs37aXd6I3tui7KO633dxHDTInCcOE2dV9U=; b=K/MXJXCmZj6G2yzSVU+wBUtWUhQP1cjHgtNI2ySqEtYNUo7bZ3qBsEN4zNrYpt4u1L MTzLI01dl11S980LYsUsZVdfmlPB1TTto6kaFsqCQotjQJGzeP8pJ8UOyMhCqmldrbyD OTCJBwgjEuh2fpc5RRWVSo/mX90ito3677sDtZaOHgvtCNLerubeGuvyahaNxucw5vCD PRMag2JSAoBt/aLqub6dydQyHJwx+x0XVBX5pRc6M4ZRdrOCprUwBJjLmdoHiD4+DFde oOuuuwyw52BxeWc/alvPbRbB0JKTBEEYsuLfENhcoQLhyNjJaA4RwkWf+MCrP4CW+Z17 Ms4w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-Gm-Message-State: APjAAAVIH6CKCPugDhmzBk/qHdvaF49E7IsDcBR/T46cS3K6Cn4dL1cm 9bSkpuR3l3FqNpThWNh0gLOxd0UfhyiaUMowpdEzabJavKWfNbWILEPX2NvYymYHJJe7c76z2br tQD2c3CyRhkN8WyEi3OUNo2N3ps5fUikwO7a94OQxr4WeVfNodar7t/sPYt4gG0DaJQ== X-Received: by 2002:a50:b103:: with SMTP id k3mr40994154edd.176.1556612372957; Tue, 30 Apr 2019 01:19:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfK2g0EDGE6pz78/05eQuxtJEc+F/A7di/cvEXyyqboFUCTWrvxDL0qtVsc6F9tHc5UJS/ X-Received: by 2002:a50:b103:: with SMTP id k3mr40994113edd.176.1556612372039; Tue, 30 Apr 2019 01:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556612372; cv=none; d=google.com; s=arc-20160816; b=GSiq2rqSGYzqSgaEsMTHhyQVn5xfjwfCI4WtQN1HbswQ4xof1KlsgTiFvAJjrwulBH Kfu/CRPwmzceP0MWyiFBQgeB5qK5rhB/DjbvjZEUa1M46h1MjtGwsz/NYL7HNcv7E+fn blUNBAD/d70YfzNFYM2qrdMGlY9zBlpdQlAf5fUmdv36HhQHOrRQTElI+sy3cFcKAEVC KmdXGdpdjRcqufz0PHClFOn4HVNkmjcq7zDFWwHg5DzFtwlCGUh+yXkO2jRn/6sGCUJ4 0qLONvaIkOozDTnQQqfBz7hEUzqy8aOqpyULx/MsycNtWi8z5R46uo4PSPyHOLdPIC63 IUcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=ERxQzSRXhs37aXd6I3tui7KO633dxHDTInCcOE2dV9U=; b=Se/sF9mdPl4jazBQAZOk9LZH1vQ31Lg9zWPqLPSg4belROm4jDJNNa873luJz48YvT hmb98mhiaBQssUzmE5iSizPa32Ihj3k4/LK9X6fw70Ev8Dpjf2j90IYXoUzaW2CfhAZo hfCVJldhV+ODy2qmLnkGsJVWQLNoFhOyIW+MPpk2T77wAbFGZU0qHv63Jkn3T6w9Ry9c MnkbDLJM0amkS9Uy0bauYTXzw059Mo+dIK0reENFkXEDdHzrDgB5ZgnGB2qElmYTYddI YjFh19flI/3FMuelvhj6Hn8+ssocTTBd2UINrWoJezVK2bMcsPBNHE4Vn/1xSmWHYI4Q 6cfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com Received: from mx1.suse.de (mx2.suse.de. [195.135.220.15]) by mx.google.com with ESMTPS id s2si4869058ejh.347.2019.04.30.01.19.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 01:19:32 -0700 (PDT) Received-SPF: pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) client-ip=195.135.220.15; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mkoutny@suse.com designates 195.135.220.15 as permitted sender) smtp.mailfrom=mkoutny@suse.com X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A3F04AE4F; Tue, 30 Apr 2019 08:19:31 +0000 (UTC) From: =?utf-8?q?Michal_Koutn=C3=BD?= To: gorcunov@gmail.com Cc: akpm@linux-foundation.org, arunks@codeaurora.org, brgl@bgdev.pl, geert+renesas@glider.be, ldufour@linux.ibm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mguzik@redhat.com, mhocko@kernel.org, mkoutny@suse.com, rppt@linux.ibm.com, vbabka@suse.cz, ktkhai@virtuozzo.com Subject: [PATCH 3/3] prctl_set_mm: downgrade mmap_sem to read lock Date: Tue, 30 Apr 2019 10:18:44 +0200 Message-Id: <20190430081844.22597-4-mkoutny@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190430081844.22597-1-mkoutny@suse.com> References: <20190418182321.GJ3040@uranus.lan> <20190430081844.22597-1-mkoutny@suse.com> MIME-Version: 1.0 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 Since commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") we use arg_lock for boundaries modifications. Synchronize prctl_set_mm with this lock and keep mmap_sem for reading only (analogous to what we already do in prctl_set_mm_map). v2: call find_vma without arg_lock held CC: Cyrill Gorcunov CC: Laurent Dufour Signed-off-by: Michal Koutný --- kernel/sys.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/sys.c b/kernel/sys.c index e1acb444d7b0..641fda756575 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2123,9 +2123,14 @@ static int prctl_set_mm(int opt, unsigned long addr, error = -EINVAL; - down_write(&mm->mmap_sem); + /* + * arg_lock protects concurent updates of arg boundaries, we need mmap_sem for + * a) concurrent sys_brk, b) finding VMA for addr validation. + */ + down_read(&mm->mmap_sem); vma = find_vma(mm, addr); + 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; @@ -2213,7 +2218,8 @@ static int prctl_set_mm(int opt, unsigned long addr, error = 0; out: - up_write(&mm->mmap_sem); + spin_unlock(&mm->arg_lock); + up_read(&mm->mmap_sem); return error; }