linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Arithmetic overflow in may_expand_vm()
@ 2009-10-15 17:24 Earl Chew
  2009-10-19  7:53 ` Johannes Weiner
  0 siblings, 1 reply; 4+ messages in thread
From: Earl Chew @ 2009-10-15 17:24 UTC (permalink / raw)
  To: linux-kernel

This code currently reads:

> int may_expand_vm(struct mm_struct *mm, unsigned long npages)
> {
>         unsigned long cur = mm->total_vm;       /* pages */
>         unsigned long lim;
> 
>         lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
> 
>         if (cur + npages > lim)
>                 return 0;
>         return 1;
> }

If npages is stupendously large, the failure predicate may
return a false negative due to (cur + npages) overflowing and
wrapping.

I think it's more robustly written as:

          if (npages > lim - cur)
                  return 0;




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-19 23:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-15 17:24 Arithmetic overflow in may_expand_vm() Earl Chew
2009-10-19  7:53 ` Johannes Weiner
2009-10-19 14:43   ` Earl Chew
2009-10-19 23:40     ` Johannes Weiner

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).