Received: by 10.213.65.68 with SMTP id h4csp54818imn; Mon, 26 Mar 2018 15:01:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELtnNZydoBpQMSagyr4tAA7Ggi2Dr2RFAg1yThiNTQiU6lf7zRc8n1Qx9ntFgYf0FJrJqOjm X-Received: by 10.98.157.7 with SMTP id i7mr24424983pfd.85.1522101672191; Mon, 26 Mar 2018 15:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522101672; cv=none; d=google.com; s=arc-20160816; b=atrT3qJTHoDaPHoPVnPQKEkn3wzAKsiYm4eZoGa9WDfAHu7QvThxWPFfCW46vDHv3s ejFTvwrIRh+kDKWXSJE7wlLYtiydG52aAdHfMcfInTChXJRmGimIkzrx6gyA/Uu3fAd7 ulU/zSO9sg36ADkDPNwmL0XqRQPYziNbEt2AeMxUfnnCpWG+AiLZJGpTFAGQMhGCODsu sHccRC9x3vuU4GcYbZA9rqm4wrsyYn7uX/u020LW3QpUBxGP5nWwMMkMfPgk8H1pVH0r OdYrxNlsJ08hisiIPnTJtkBZ20XhQbXF8x5ufH0BmVd638uolf9nXNjWTkPLr879UW9H rSfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=B29EeRZzMKAPjbDctrUErcHcohSzLIT3dSL6O7R/9Do=; b=XaWYoua9sLhPK4IxWzkVL97hBBOGz4fwv6Y3PryT397Yrt4ZEtSG/FYxAzI0L+AeeC WGa1bwxVbvhvvq8YCNcgyX7LrCECr/T7DrWX76HvY9exdsHfnLgk6/YF6cXR7Wqw/eXb /H6HUMgPUNsv5MGHRu4h5hhcdNlnBbEMNzajdRE3pEqSgTue/WGLSMU88OBy8KOwqCG0 dailNzngsNz17rivUJPkM1mOf3V6m7GkJOY2Ndxfm0xP3HsNcV9Ql+jdxxQuxg5D+6IH HGcT93vK0HKlG9t1kVZ7CpEnEhAnQRMENjpXPsPH388Dz5N7l01uFbl2nhWcgH70xUb2 b3Vg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6si10818601pgf.658.2018.03.26.15.00.56; Mon, 26 Mar 2018 15:01:12 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752138AbeCZWAE (ORCPT + 99 others); Mon, 26 Mar 2018 18:00:04 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:44463 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751739AbeCZWAD (ORCPT ); Mon, 26 Mar 2018 18:00:03 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0T-8hMkn_1522101590; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:121.0.29.199) by smtp.aliyun-inc.com(127.0.0.1); Tue, 27 Mar 2018 05:59:55 +0800 Subject: Re: [v2 PATCH] mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct To: Cyrill Gorcunov , Matthew Wilcox Cc: adobriyan@gmail.com, mhocko@kernel.org, mguzik@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1522088439-105930-1-git-send-email-yang.shi@linux.alibaba.com> <20180326183725.GB27373@bombadil.infradead.org> <20180326192132.GE2236@uranus> From: Yang Shi Message-ID: Date: Mon, 26 Mar 2018 17:59:49 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20180326192132.GE2236@uranus> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/26/18 3:21 PM, Cyrill Gorcunov wrote: > On Mon, Mar 26, 2018 at 11:37:25AM -0700, Matthew Wilcox wrote: >> On Tue, Mar 27, 2018 at 02:20:39AM +0800, Yang Shi wrote: >>> +++ b/kernel/sys.c >>> @@ -1959,7 +1959,7 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data >>> return error; >>> } >>> >>> - down_write(&mm->mmap_sem); >>> + down_read(&mm->mmap_sem); >>> >>> /* >>> * We don't validate if these members are pointing to >>> @@ -1980,10 +1980,13 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long data >>> mm->start_brk = prctl_map.start_brk; >>> mm->brk = prctl_map.brk; >>> mm->start_stack = prctl_map.start_stack; >>> + >>> + spin_lock(&mm->arg_lock); >>> 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); >>> >>> /* >>> * Note this update of @saved_auxv is lockless thus >> I see the argument for the change to a write lock was because of a BUG >> validating arg_start and arg_end, but more generally, we are updating these >> values, so a write-lock is probably a good idea, and this is a very rare >> operation to do, so we don't care about making this more parallel. I would >> not make this change (but if other more knowledgable people in this area >> disagree with me, I will withdraw my objection to this part). > Say we've two syscalls running prctl_set_mm_map in parallel, and imagine > one have @start_brk = 20 @brk = 10 and second caller has @start_brk = 30 > and @brk = 20. Since now the call is guarded by _read_ the both calls > unlocked and due to OO engine it may happen then when both finish > we have @start_brk = 30 and @brk = 10. In turn "write" semaphore > has been take to have consistent data on exit, either you have [20;10] > or [30;20] assigned not something mixed. > > That said I think using read-lock here would be a bug. Yes it sounds so. However, it was down_read before ddf1d398e517e660207e2c807f76a90df543a217 ("prctl: take mmap sem for writing to protect against others"). And, that commit is for fixing the concurrent writing to arg_* and env_*. I just checked that commit, but omitted the brk part. The potential issue mentioned by you should exist before that commit, but might be just not discovered or very rare to hit. I will change it back to down_write. Thanks, Yang > > Cyrill