Re: [PATCH] netlink: fix overrun in attribute iteration

Previous thread: 2.6.26.5-rt9 by Steven Rostedt on Thursday, September 11, 2008 - 1:54 pm. (3 messages)

Next thread: [patch 0/7] x86, cpa: cpa related changes to be inline with TLB Application note by Suresh Siddha on Thursday, September 11, 2008 - 1:30 pm. (6 messages)
From: Vegard Nossum
Date: Thursday, September 11, 2008 - 1:59 pm

From ca63375e8ed91d73d0c2abd1cb64a8b022ce2af8 Mon Sep 17 00:00:00 2001
From: Vegard Nossum <vegard.nossum@gmail.com>
Date: Thu, 11 Sep 2008 22:37:13 +0200
Subject: [PATCH] netlink: fix overrun in attribute iteration

kmemcheck reported this:

  kmemcheck: Caught 16-bit read from uninitialized memory (f6c1ba30)
  0500110001508abf050010000500000002017300140000006f72672e66726565
   i i i i i i i i i i i i i u u u u u u u u u u u u u u u u u u u
                                   ^

  Pid: 3462, comm: wpa_supplicant Not tainted (2.6.27-rc3-00054-g6397ab9-dirty #13)
  EIP: 0060:[<c05de64a>] EFLAGS: 00010296 CPU: 0
  EIP is at nla_parse+0x5a/0xf0
  EAX: 00000008 EBX: fffffffd ECX: c06f16c0 EDX: 00000005
  ESI: 00000010 EDI: f6c1ba30 EBP: f6367c6c ESP: c0a11e88
   DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
  CR0: 8005003b CR2: f781cc84 CR3: 3632f000 CR4: 000006d0
  DR0: c0ead9bc DR1: 00000000 DR2: 00000000 DR3: 00000000
  DR6: ffff4ff0 DR7: 00000400
   [<c05d4b23>] rtnl_setlink+0x63/0x130
   [<c05d5f75>] rtnetlink_rcv_msg+0x165/0x200
   [<c05ddf66>] netlink_rcv_skb+0x76/0xa0
   [<c05d5dfe>] rtnetlink_rcv+0x1e/0x30
   [<c05dda21>] netlink_unicast+0x281/0x290
   [<c05ddbe9>] netlink_sendmsg+0x1b9/0x2b0
   [<c05beef2>] sock_sendmsg+0xd2/0x100
   [<c05bf945>] sys_sendto+0xa5/0xd0
   [<c05bf9a6>] sys_send+0x36/0x40
   [<c05c03d6>] sys_socketcall+0x1e6/0x2c0
   [<c020353b>] sysenter_do_call+0x12/0x3f
   [<ffffffff>] 0xffffffff

This is the line in nla_ok():

  /**
   * 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;
  }

It turns out that remaining can become negative due to alignment in
nla_next(). But GCC promotes "remaining" to unsigned in the ...
From: David Miller
Date: Thursday, September 11, 2008 - 3:04 pm

From: Vegard Nossum <vegard.nossum@gmail.com>

Someone should print that out on a huge poster, it's a good

--

From: Thomas Graf
Date: Thursday, September 11, 2008 - 5:35 pm

Very nice catch, would never have thought of that.
--

From: David Miller
Date: Thursday, September 11, 2008 - 7:05 pm

From: Thomas Graf <tgraf@suug.ch>

Applied, thanks everyone.
--

From: Andrew Morton
Date: Thursday, September 11, 2008 - 4:52 pm

On Thu, 11 Sep 2008 22:59:33 +0200

akpm:/home/akpm> gcc -W t.c
t.c: In function 'main':
t.c:5: warning: comparison between signed and unsigned

Make of that what you will :)
--

From: Vegard Nossum
Date: Thursday, September 11, 2008 - 10:42 pm

On Fri, Sep 12, 2008 at 1:52 AM, Andrew Morton

It doesn't show up with -Wall and the kernel isn't compiled with -W
(aka. -Wextra) as far as I can see. Should it be turned on?


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
--

From: Andrew Morton
Date: Thursday, September 11, 2008 - 11:02 pm

Last time I turned on -W, a full kernel build emitted nearly 10MB of
warnings.

Alas, some of them are useful, as we see here.  They can be turned on
piecemeal - this one is -Wsign-compare, I think.

I think it would be good if owners of particular parts of the kernel
were to occasionally build their stuff with -W and spend half an hour
contemplating the result.  Ditto `make C=1', to see what sparse thinks.


--

Previous thread: 2.6.26.5-rt9 by Steven Rostedt on Thursday, September 11, 2008 - 1:54 pm. (3 messages)

Next thread: [patch 0/7] x86, cpa: cpa related changes to be inline with TLB Application note by Suresh Siddha on Thursday, September 11, 2008 - 1:30 pm. (6 messages)