Messages in this thread |  | | | Date | Fri, 12 Sep 2008 07:49:08 +0200 | | From | "Vegard Nossum" <> | | Subject | Re: [PATCH] netlink: fix overrun in attribute iteration | |
On Fri, Sep 12, 2008 at 5:51 AM, David Wagner <daw@cs.berkeley.edu> wrote:
> Vegard Nossum wrote:
>> /**
>> * nla_ok - check if the netlink attribute fits into the remaining bytes
>> * @nla: netlink attribute
>> * @remaining: number of bytes remaining in attribute stream
>> */
>> static inline int nla_ok(const struct nlattr *nla, int remaining)
>> {
>> return remaining >= sizeof(*nla) &&
>> nla->nla_len >= sizeof(*nla) &&
>> nla->nla_len <= remaining;
>> }
>
> If 'remaining' had been declared to be of type size_t, this would
> not have happened.
Hm. Yes, it would!
The problem here is that "remaining" can legitimately contain negative
values (see the pointer advancement in nla_next()). And size_t can't
hold negative values.
Vegard
--
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
-- E. W. Dijkstra, EWD1036
|  |