From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Michal Hocko <mhocko@kernel.org>,
adobriyan@gmail.com, willy@infradead.org, mguzik@redhat.com,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [v3 PATCH] mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct
Date: Tue, 10 Apr 2018 22:17:42 +0300 [thread overview]
Message-ID: <20180410191742.GE2041@uranus.lan> (raw)
In-Reply-To: <8c19f1fb-7baf-fef3-032d-4e93cfc63932@linux.alibaba.com>
On Tue, Apr 10, 2018 at 11:28:13AM -0700, Yang Shi wrote:
> >
> > At the first glance, it looks feasible to me. Will look into deeper
> > later.
>
> A further look told me this might be *not* feasible.
>
> It looks the new lock will not break check_data_rlimit since in my patch
> both start_brk and brk is protected by mmap_sem. The code flow might look
> like below:
>
> CPU A CPU B
> -------- --------
> prctl sys_brk
> down_write
> check_data_rlimit check_data_rlimit (need mm->start_brk)
> set brk
> down_write up_write
> set start_brk
> set brk
> up_write
>
> If CPU A gets the mmap_sem first, it will set start_brk and brk, then CPU B
> will check with the new start_brk. And, prctl doesn't care if sys_brk is run
> before it since it gets the new start_brk and brk from parameter.
>
> If we protect start_brk and brk with the new lock, sys_brk might get old
> start_brk, then sys_brk might break rlimit check silently, is that right?
>
> So, it looks using new lock in prctl and keeping mmap_sem in brk path has
> race condition.
I fear so. The check_data_rlimit implies that all elements involved into
validation (brk, start_brk, start_data, end_data) are not changed unpredicably
until written back into mm. In turn if we guard start_brk,brk only (as
it is done in the patch) the check_data_rlimit may pass on wrong data
I think. And as you mentioned the race above exact the example of such
situation. I think for prctl case we can simply left use of mmap_sem
as it were before the patch, after all this syscall is really in cold
path all the time.
Cyrill
next prev parent reply other threads:[~2018-04-10 19:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-09 21:52 [v3 PATCH] mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct Yang Shi
2018-04-10 8:48 ` Cyrill Gorcunov
2018-04-10 9:09 ` Michal Hocko
2018-04-10 9:40 ` Cyrill Gorcunov
2018-04-10 10:42 ` Michal Hocko
2018-04-10 11:02 ` Cyrill Gorcunov
2018-04-10 11:10 ` Michal Hocko
2018-04-10 12:28 ` Cyrill Gorcunov
2018-04-10 16:21 ` Yang Shi
2018-04-10 18:28 ` Yang Shi
2018-04-10 19:17 ` Cyrill Gorcunov [this message]
2018-04-10 19:33 ` Yang Shi
2018-04-10 20:06 ` Cyrill Gorcunov
2018-04-12 12:18 ` Michal Hocko
2018-04-12 16:20 ` Yang Shi
2018-04-13 6:56 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180410191742.GE2041@uranus.lan \
--to=gorcunov@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mguzik@redhat.com \
--cc=mhocko@kernel.org \
--cc=willy@infradead.org \
--cc=yang.shi@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).