All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: yang.shi@linux.alibaba.com
Cc: linux-mm@kvack.org
Subject: [bug report] mm: brk: downgrade mmap_sem to read when shrinking
Date: Wed, 10 Oct 2018 13:44:21 +0300	[thread overview]
Message-ID: <20181010104420.GA15538@mwanda> (raw)

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

             reply	other threads:[~2018-10-10 10:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 10:44 Dan Carpenter [this message]
2018-10-10 16:31 ` [bug report] mm: brk: downgrade mmap_sem to read when shrinking Yang Shi

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=20181010104420.GA15538@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=linux-mm@kvack.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.