lkml.org 
[lkml]   [2008]   [Sep]   [12]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateFri, 12 Sep 2008 07:49:08 +0200
From"Vegard Nossum" <>
SubjectRe: [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


\
 
 \ /
  Last update: 2008-09-12 07:51    [from the cache]
©2003-2008