public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Earl Chew <earl_chew@agilent.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH v1 1/1] : mm : mmap.c Arithmetic overflow in may_expand_vm()
Date: Fri, 16 Oct 2009 07:49:40 -0700	[thread overview]
Message-ID: <4AD88804.4090205@agilent.com> (raw)

The function may_expand_vm() may return a false positive if the proposed
increment (npages) is sufficient large to overflow the expression:

	cur + npages

Assuming that cur < lim is an invariant, the proposed patch re-arranges
the expression to avoid unsigned arithmetic overflow.

More robustly:

	if (cur > lim || npages > lim - cur)
		return 0;

might be preferred if it cannot be guaranteed that cur < lim.



--- linux-2.6.21_mvlcge500/mm/mmap.c.orig	2008-06-30 22:43:38.000000000 
-0700
+++ linux-2.6.21_mvlcge500/mm/mmap.c	2009-10-16 07:42:23.000000000 -0700
@@ -2303,7 +2303,7 @@ int may_expand_vm(struct mm_struct *mm,

  	lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;

-	if (cur + npages > lim)
+	if (npages > lim - cur)
  		return 0;
  	return 1;
  }




                 reply	other threads:[~2009-10-16 14:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4AD88804.4090205@agilent.com \
    --to=earl_chew@agilent.com \
    --cc=linux-kernel@vger.kernel.org \
    /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