Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4624443yba; Tue, 30 Apr 2019 01:21:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1zXNHMdYrpxEXc4c1wSJlO6PHm/ndF3ahmSgnaecQ8CM85MJXoFZ8jf8q3HhIOorlTLHo X-Received: by 2002:a63:5041:: with SMTP id q1mr41746092pgl.386.1556612487145; Tue, 30 Apr 2019 01:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556612487; cv=none; d=google.com; s=arc-20160816; b=YQvjBEqyOZGM8VMc+u4JR92Rzy5AHadh4EuS2hU4kc+C5pJKHV2jNXrafop2Y2nsvD 2aTMFx2GOuYmzRBupuyK5jnyNDQPRakdc6dWwugNnCORSa1woCNx1Zq4cKV5DucIJ8pV OE/3HRe9Onfo2ZMAGJ8TGZvgwinElQJmCxSQ3yOJ6fGKygvJq80l8XvlwI/ssUkC91Ua POWOmnTXSjLVaY3vScD+3eux5WsYwUCx9Y9zSsFOPoFNIXr7xHBvxZUJdIXXtWkqEAvj 9JIwnX5CpyT8OglDITZelDGUSlAW0urACfVQXuDENjY8XMTB+j5RziVO1niwzExaWh// u7ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ERxQzSRXhs37aXd6I3tui7KO633dxHDTInCcOE2dV9U=; b=t6W1OmPfmzCcXG3eNsDiogXbVlEXBF79RMv2VAxqcSxGNfQQrOFBhV+7u2Ugkz06hI IqO6JtpWRQ3NGJpk0COW+3hlDZz+d3Sz6+ILtLnHcUCijWafClXIcaEG1EhVwQyqYC2l n+hyIxUr+ARSbotF3Nmy+vUJl0hsU6ugvP4UMX1bfJJeM+o9TeYG6XojC9SH8e/Qdl/b NyLgSLWV3USK0SNZhBtIg48WvYuHWzE1bhz/7ab85RXgUe6S2s1DT6xrds2mU1xZPlYI KiAfFvaHx7Ec2wegMGe4v4V9l2vSe5N6MxxwVi0PD6ZwmWKWUOfHMTXHix5Y0hI6PQyI /sWA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15si29023546pga.358.2019.04.30.01.21.11; Tue, 30 Apr 2019 01:21:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbfD3ITh (ORCPT + 99 others); Tue, 30 Apr 2019 04:19:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:55642 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726648AbfD3ITc (ORCPT ); Tue, 30 Apr 2019 04:19:32 -0400 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=20Koutn=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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.16.4