diff options
author | Michal Koutný <mkoutny@suse.com> | 2019-06-01 01:30:19 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-06-01 18:51:31 -0400 |
commit | bc81426f5beef7da863d3365bc9d45e820448745 (patch) | |
tree | c26cfabbc7b48e47b65ea33060067dd7b00567c1 | |
parent | 11bbd8b416f8abf40900dc5041152892f873d915 (diff) |
prctl_set_mm: downgrade mmap_sem to read lock
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. But there still
remained two places that (mis)use mmap_sem.
get_cmdline should also use arg_lock instead of mmap_sem when it reads the
boundaries.
The second place that should use arg_lock is in prctl_set_mm. By
protecting the boundaries fields with the arg_lock, we can downgrade
mmap_sem to reader lock (analogous to what we already do in
prctl_set_mm_map).
[akpm@linux-foundation.org: coding style fixes]
Link: http://lkml.kernel.org/r/20190502125203.24014-3-mkoutny@suse.com
Fixes: 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")
Signed-off-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
Co-developed-by: Laurent Dufour <ldufour@linux.ibm.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Mateusz Guzik <mguzik@redhat.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | kernel/sys.c | 11 | ||||
-rw-r--r-- | mm/util.c | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index 775bf8d18d03..2969304c29fe 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -2127,9 +2127,15 @@ static int prctl_set_mm(int opt, unsigned long addr, | |||
2127 | 2127 | ||
2128 | error = -EINVAL; | 2128 | error = -EINVAL; |
2129 | 2129 | ||
2130 | down_write(&mm->mmap_sem); | 2130 | /* |
2131 | * arg_lock protects concurent updates of arg boundaries, we need | ||
2132 | * mmap_sem for a) concurrent sys_brk, b) finding VMA for addr | ||
2133 | * validation. | ||
2134 | */ | ||
2135 | down_read(&mm->mmap_sem); | ||
2131 | vma = find_vma(mm, addr); | 2136 | vma = find_vma(mm, addr); |
2132 | 2137 | ||
2138 | spin_lock(&mm->arg_lock); | ||
2133 | prctl_map.start_code = mm->start_code; | 2139 | prctl_map.start_code = mm->start_code; |
2134 | prctl_map.end_code = mm->end_code; | 2140 | prctl_map.end_code = mm->end_code; |
2135 | prctl_map.start_data = mm->start_data; | 2141 | prctl_map.start_data = mm->start_data; |
@@ -2217,7 +2223,8 @@ static int prctl_set_mm(int opt, unsigned long addr, | |||
2217 | 2223 | ||
2218 | error = 0; | 2224 | error = 0; |
2219 | out: | 2225 | out: |
2220 | up_write(&mm->mmap_sem); | 2226 | spin_unlock(&mm->arg_lock); |
2227 | up_read(&mm->mmap_sem); | ||
2221 | return error; | 2228 | return error; |
2222 | } | 2229 | } |
2223 | 2230 | ||
@@ -718,12 +718,12 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen) | |||
718 | if (!mm->arg_end) | 718 | if (!mm->arg_end) |
719 | goto out_mm; /* Shh! No looking before we're done */ | 719 | goto out_mm; /* Shh! No looking before we're done */ |
720 | 720 | ||
721 | down_read(&mm->mmap_sem); | 721 | spin_lock(&mm->arg_lock); |
722 | arg_start = mm->arg_start; | 722 | arg_start = mm->arg_start; |
723 | arg_end = mm->arg_end; | 723 | arg_end = mm->arg_end; |
724 | env_start = mm->env_start; | 724 | env_start = mm->env_start; |
725 | env_end = mm->env_end; | 725 | env_end = mm->env_end; |
726 | up_read(&mm->mmap_sem); | 726 | spin_unlock(&mm->arg_lock); |
727 | 727 | ||
728 | len = arg_end - arg_start; | 728 | len = arg_end - arg_start; |
729 | 729 | ||