* [PATCH] __kmalloc: Generate BUG if size requested is too large.
@ 2005-09-22 19:32 Christoph Lameter
2005-09-22 20:31 ` Dave Hansen
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Lameter @ 2005-09-22 19:32 UTC (permalink / raw)
To: linux-mm
I had an issue on ia64 where I got a bug in kernel/workqueue because kzalloc
returned a NULL pointer due to the task structure getting too big for the slab
allocator. Usually these cases are caught by the kmalloc macro in include/linux/slab.h.
Compilation will fail if a too big value is passed to kmalloc.
However, kzalloc uses __kmalloc which has no check for that. This patch makes __kmalloc
bug if a too large entity is requested.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Index: linux-2.6.14-rc2/mm/slab.c
===================================================================
--- linux-2.6.14-rc2.orig/mm/slab.c 2005-09-22 11:21:07.000000000 -0700
+++ linux-2.6.14-rc2/mm/slab.c 2005-09-22 11:58:45.000000000 -0700
@@ -2906,8 +2906,7 @@ void *__kmalloc(size_t size, unsigned in
* functions.
*/
cachep = __find_general_cachep(size, flags);
- if (unlikely(cachep == NULL))
- return NULL;
+ BUG_ON(!cachep); /* Allocation size too large for kmalloc */
return __cache_alloc(cachep, flags);
}
EXPORT_SYMBOL(__kmalloc);
--
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] __kmalloc: Generate BUG if size requested is too large.
2005-09-22 19:32 [PATCH] __kmalloc: Generate BUG if size requested is too large Christoph Lameter
@ 2005-09-22 20:31 ` Dave Hansen
2005-09-22 20:54 ` Christoph Lameter
0 siblings, 1 reply; 3+ messages in thread
From: Dave Hansen @ 2005-09-22 20:31 UTC (permalink / raw)
To: Christoph Lameter; +Cc: linux-mm
On Thu, 2005-09-22 at 12:32 -0700, Christoph Lameter wrote:
> I had an issue on ia64 where I got a bug in kernel/workqueue because kzalloc
> returned a NULL pointer due to the task structure getting too big for the slab
> allocator. Usually these cases are caught by the kmalloc macro in include/linux/slab.h.
> Compilation will fail if a too big value is passed to kmalloc.
I'd be more concerned that the workqueue code wasn't checking for NULL.
Also, the one place where I see the workqueue code using kzalloc(), it
checks for kzalloc() failure (in __create_workqueue).
> However, kzalloc uses __kmalloc which has no check for that. This
> patch makes __kmalloc bug if a too large entity is requested.
I don't see that in current -git, either. Which version of the kernel
are you working against?
> void *kzalloc(size_t size, unsigned int __nocast flags)
> {
> void *ret = kmalloc(size, flags);
> if (ret)
> memset(ret, 0, size);
> return ret;
> }
> EXPORT_SYMBOL(kzalloc);
-- Dave
--
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] __kmalloc: Generate BUG if size requested is too large.
2005-09-22 20:31 ` Dave Hansen
@ 2005-09-22 20:54 ` Christoph Lameter
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Lameter @ 2005-09-22 20:54 UTC (permalink / raw)
To: Dave Hansen; +Cc: linux-mm
On Thu, 22 Sep 2005, Dave Hansen wrote:
> On Thu, 2005-09-22 at 12:32 -0700, Christoph Lameter wrote:
> > I had an issue on ia64 where I got a bug in kernel/workqueue because kzalloc
> > returned a NULL pointer due to the task structure getting too big for the slab
> > allocator. Usually these cases are caught by the kmalloc macro in include/linux/slab.h.
> > Compilation will fail if a too big value is passed to kmalloc.
>
> I'd be more concerned that the workqueue code wasn't checking for NULL.
> Also, the one place where I see the workqueue code using kzalloc(), it
> checks for kzalloc() failure (in __create_workqueue).
The workqueue code is checking for NULL after getting out of a another
function.
> > However, kzalloc uses __kmalloc which has no check for that. This
> > patch makes __kmalloc bug if a too large entity is requested.
>
> I don't see that in current -git, either. Which version of the kernel
> are you working against?
Look at __kmalloc in current not kzalloc. kzalloc calls __kmalloc
since size is not a constant.
--
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-09-22 20:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-22 19:32 [PATCH] __kmalloc: Generate BUG if size requested is too large Christoph Lameter
2005-09-22 20:31 ` Dave Hansen
2005-09-22 20:54 ` Christoph Lameter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox