From: David Rientjes <rientjes@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Nazarewicz <mpn@google.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cma: use unsigned type for count argument
Date: Thu, 20 Dec 2012 16:03:26 -0800 (PST) [thread overview]
Message-ID: <alpine.DEB.2.00.1212201557270.13223@chino.kir.corp.google.com> (raw)
In-Reply-To: <20121220153525.97841100.akpm@linux-foundation.org>
On Thu, 20 Dec 2012, Andrew Morton wrote:
> > Specifying negative size of buffer makes no sense and thus this commit
> > changes the type of the count argument to unsigned.
> >
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -1038,9 +1038,9 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
> > gfp_t gfp, struct dma_attrs *attrs)
> > {
> > struct page **pages;
> > - int count = size >> PAGE_SHIFT;
> > - int array_size = count * sizeof(struct page *);
> > - int i = 0;
> > + unsigned int count = size >> PAGE_SHIFT;
> > + unsigned int array_size = count * sizeof(struct page *);
> > + unsigned int i = 0;
>
> C programmers expect a variable called `i' to have type `int'. It
> would be clearer to find a new name for this. `idx', perhaps.
>
I didn't ack this because there's no bounds checking on
dma_alloc_from_contiguous() and bitmap_set() has a dangerous side-effect
when called with an overflowed nr since it takes a signed argument.
Marek, is there some sane upper bound we can put on count?
Additionally, I think at least this is needed for callers of bitmap_set()
for some sanity (unless someone wants to audit the almost 100 callers and
change it to unsigned as well). There's probably additional nastiness in
this library as well, I didn't check.
---
diff --git a/lib/bitmap.c b/lib/bitmap.c
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -287,7 +287,7 @@ void bitmap_set(unsigned long *map, int start, int nr)
mask_to_set = ~0UL;
p++;
}
- if (nr) {
+ if (nr > 0) {
mask_to_set &= BITMAP_LAST_WORD_MASK(size);
*p |= mask_to_set;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-12-21 0:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-19 17:44 Michal Nazarewicz
2012-12-20 23:35 ` Andrew Morton
2012-12-21 0:03 ` David Rientjes [this message]
2012-12-22 15:31 ` Michal Nazarewicz
2012-12-27 1:59 ` David Rientjes
2012-12-27 2:05 ` Michal Nazarewicz
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=alpine.DEB.2.00.1212201557270.13223@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=mpn@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox