* [bug report] mm: brk: downgrade mmap_sem to read when shrinking
@ 2018-10-10 10:44 Dan Carpenter
2018-10-10 16:31 ` Yang Shi
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2018-10-10 10:44 UTC (permalink / raw)
To: yang.shi; +Cc: linux-mm
Hello Yang Shi,
The patch ca761a3ea456: "mm: brk: downgrade mmap_sem to read when
shrinking" from Oct 4, 2018, leads to the following static checker
warning:
mm/mmap.c:252 __do_sys_brk()
warn: unsigned 'retval' is never less than zero.
mm/mmap.c
223 /*
224 * Check against rlimit here. If this check is done later after the test
225 * of oldbrk with newbrk then it can escape the test and let the data
226 * segment grow beyond its set limit the in case where the limit is
227 * not page aligned -Ram Gupta
228 */
229 if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
230 mm->end_data, mm->start_data))
231 goto out;
232
233 newbrk = PAGE_ALIGN(brk);
234 oldbrk = PAGE_ALIGN(mm->brk);
235 if (oldbrk == newbrk) {
236 mm->brk = brk;
237 goto success;
238 }
239
240 /*
241 * Always allow shrinking brk.
242 * __do_munmap() may downgrade mmap_sem to read.
243 */
244 if (brk <= mm->brk) {
245 /*
246 * mm->brk must to be protected by write mmap_sem so update it
247 * before downgrading mmap_sem. When __do_munmap() fails,
248 * mm->brk will be restored from origbrk.
249 */
250 mm->brk = brk;
251 retval = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true);
252 if (retval < 0) {
^^^^^^^^^^
Impossible.
253 mm->brk = origbrk;
254 goto out;
255 } else if (retval == 1)
256 downgraded = true;
257 goto success;
258 }
259
See also:
mm/mremap.c:571 __do_sys_mremap() warn: unsigned 'ret' is never less than zero.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [bug report] mm: brk: downgrade mmap_sem to read when shrinking
2018-10-10 10:44 [bug report] mm: brk: downgrade mmap_sem to read when shrinking Dan Carpenter
@ 2018-10-10 16:31 ` Yang Shi
0 siblings, 0 replies; 2+ messages in thread
From: Yang Shi @ 2018-10-10 16:31 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-mm
Hi Dan,
Thanks for reporting this bug. Colin Ian King reported the same issue a
couple of days ago, please see
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1780112.html.
And, the fixes have been merged into Andrew's -mm tree.
Regards,
Yang
On 10/10/18 3:44 AM, Dan Carpenter wrote:
> Hello Yang Shi,
>
> The patch ca761a3ea456: "mm: brk: downgrade mmap_sem to read when
> shrinking" from Oct 4, 2018, leads to the following static checker
> warning:
>
> mm/mmap.c:252 __do_sys_brk()
> warn: unsigned 'retval' is never less than zero.
>
> mm/mmap.c
> 223 /*
> 224 * Check against rlimit here. If this check is done later after the test
> 225 * of oldbrk with newbrk then it can escape the test and let the data
> 226 * segment grow beyond its set limit the in case where the limit is
> 227 * not page aligned -Ram Gupta
> 228 */
> 229 if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
> 230 mm->end_data, mm->start_data))
> 231 goto out;
> 232
> 233 newbrk = PAGE_ALIGN(brk);
> 234 oldbrk = PAGE_ALIGN(mm->brk);
> 235 if (oldbrk == newbrk) {
> 236 mm->brk = brk;
> 237 goto success;
> 238 }
> 239
> 240 /*
> 241 * Always allow shrinking brk.
> 242 * __do_munmap() may downgrade mmap_sem to read.
> 243 */
> 244 if (brk <= mm->brk) {
> 245 /*
> 246 * mm->brk must to be protected by write mmap_sem so update it
> 247 * before downgrading mmap_sem. When __do_munmap() fails,
> 248 * mm->brk will be restored from origbrk.
> 249 */
> 250 mm->brk = brk;
> 251 retval = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true);
> 252 if (retval < 0) {
> ^^^^^^^^^^
> Impossible.
>
> 253 mm->brk = origbrk;
> 254 goto out;
> 255 } else if (retval == 1)
> 256 downgraded = true;
> 257 goto success;
> 258 }
> 259
>
> See also:
> mm/mremap.c:571 __do_sys_mremap() warn: unsigned 'ret' is never less than zero.
>
> regards,
> dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-10 16:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 10:44 [bug report] mm: brk: downgrade mmap_sem to read when shrinking Dan Carpenter
2018-10-10 16:31 ` Yang Shi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox