Re: [RFC][PATCH] mm: Remove ZERO_SIZE_PTR.

From: KOSAKI Motohiro
Date: Fri Feb 26 2010 - 01:59:18 EST


> [RFC][PATCH] mm: Remove ZERO_SIZE_PTR.
>
> kmalloc() and friends are sometimes used in a way
>
> struct foo *ptr = kmalloc(size + sizeof(struct foo), GFP_KERNEL);
> if (!ptr)
> return -ENOMEM;
> ptr->size = size;
> ...
> return 0;
>
> Everybody should check for ptr != NULL, and most callers are actually checking
> for ptr != NULL. But nobody is checking for ptr != ZERO_SIZE_PTR.
>
> If caller passed 0 as size argument by error (e.g. integer overflow bug),
> the caller will start writing against address starting from ZERO_SIZE_PTR
> because the caller assumes that "size + sizeof(struct foo)" bytes of memory is
> successfully allocated. (kstrdup() is an example, although it will be
> impossible to pass s where strlen(s) == (size_t) -1 .)
>
> Yes, this is the fault of caller. But ZERO_SIZE_PTR is too small value to
> distinguish "NULL pointer dereference" and "ZERO_SIZE_PTR dereference" because
> address printed by oops message can easily exceed ZERO_SIZE_PTR when
> "struct foo" is large.
>
> Therefore, at the cost of being unable to distinguish "NULL pointer
> dereference" and "ZERO_SIZE_PTR dereference" in some cases, removing
> ZERO_SIZE_PTR could reduce the risk of "ZERO_SIZE_PTR dereference" in many
> cases.

NAK. yes, it could. but it is no worth. nobody want slower kernel.



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/