netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netlink: fix (theoretical) overrun in message iteration
@ 2008-12-21 13:42 Vegard Nossum
  2008-12-21 14:44 ` Vegard Nossum
  2008-12-26  1:20 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Vegard Nossum @ 2008-12-21 13:42 UTC (permalink / raw)
  To: David S. Miller
  Cc: Thomas Graf, Eugene Teo, Andrew Morton, Al Viro, netdev,
	linux-kernel

>From bb805d89e84ddb11c9bb58afcfd9a6b37bbe5a9b Mon Sep 17 00:00:00 2001
From: Vegard Nossum <vegard.nossum@gmail.com>
Date: Sun, 21 Dec 2008 14:20:49 +0100
Subject: [PATCH] netlink: fix (theoretical) overrun in message iteration

See commit 1045b03e07d85f3545118510a587035536030c1c for a detailed
explanation of why this patch is necessary.

In short, nlmsg_next() can make "remaining" go negative, and the
remaining >= sizeof(...) comparison will promote "remaining" to an
unsigned type, which means that the expression will evaluate to
true for negative numbers, even though it was not intended.

I put "theoretical" in the title because I have no evidence that
this can actually happen, but I suspect that a crafted netlink
packet can trigger some badness.

Note that the last test, which seemingly has the exact same
problem (also true for nla_ok()), is perfectly OK, since we
already know that remaining is positive.

Cc: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
---
 include/net/netlink.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/net/netlink.h b/include/net/netlink.h
index 3643bbb..13dd525 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -332,7 +332,7 @@ static inline int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
  */
 static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
 {
-	return (remaining >= sizeof(struct nlmsghdr) &&
+	return (remaining >= (int) sizeof(struct nlmsghdr) &&
 		nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
 		nlh->nlmsg_len <= remaining);
 }
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] netlink: fix (theoretical) overrun in message iteration
  2008-12-21 13:42 [PATCH] netlink: fix (theoretical) overrun in message iteration Vegard Nossum
@ 2008-12-21 14:44 ` Vegard Nossum
  2008-12-21 14:46   ` Vegard Nossum
  2008-12-26  1:20 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Vegard Nossum @ 2008-12-21 14:44 UTC (permalink / raw)
  To: David S. Miller
  Cc: Thomas Graf, Eugene Teo, Andrew Morton, Al Viro, netdev,
	linux-kernel

On Sun, Dec 21, 2008 at 2:42 PM, Vegard Nossum <vegard.nossum@gmail.com> wrote:
> From bb805d89e84ddb11c9bb58afcfd9a6b37bbe5a9b Mon Sep 17 00:00:00 2001
> From: Vegard Nossum <vegard.nossum@gmail.com>
> Date: Sun, 21 Dec 2008 14:20:49 +0100
> Subject: [PATCH] netlink: fix (theoretical) overrun in message iteration
>
> See commit 1045b03e07d85f3545118510a587035536030c1c for a detailed
> explanation of why this patch is necessary.
>
> In short, nlmsg_next() can make "remaining" go negative, and the
> remaining >= sizeof(...) comparison will promote "remaining" to an
> unsigned type, which means that the expression will evaluate to
> true for negative numbers, even though it was not intended.
>
> I put "theoretical" in the title because I have no evidence that
> this can actually happen, but I suspect that a crafted netlink
> packet can trigger some badness.

nlmsg


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] netlink: fix (theoretical) overrun in message iteration
  2008-12-21 14:44 ` Vegard Nossum
@ 2008-12-21 14:46   ` Vegard Nossum
  0 siblings, 0 replies; 4+ messages in thread
From: Vegard Nossum @ 2008-12-21 14:46 UTC (permalink / raw)
  To: David S. Miller
  Cc: Thomas Graf, Eugene Teo, Andrew Morton, Al Viro, netdev,
	linux-kernel

On Sun, Dec 21, 2008 at 3:44 PM, Vegard Nossum <vegard.nossum@gmail.com> wrote:
> On Sun, Dec 21, 2008 at 2:42 PM, Vegard Nossum <vegard.nossum@gmail.com> wrote:
>> From bb805d89e84ddb11c9bb58afcfd9a6b37bbe5a9b Mon Sep 17 00:00:00 2001
>> From: Vegard Nossum <vegard.nossum@gmail.com>
>> Date: Sun, 21 Dec 2008 14:20:49 +0100
>> Subject: [PATCH] netlink: fix (theoretical) overrun in message iteration
>>
>> See commit 1045b03e07d85f3545118510a587035536030c1c for a detailed
>> explanation of why this patch is necessary.
>>
>> In short, nlmsg_next() can make "remaining" go negative, and the
>> remaining >= sizeof(...) comparison will promote "remaining" to an
>> unsigned type, which means that the expression will evaluate to
>> true for negative numbers, even though it was not intended.
>>
>> I put "theoretical" in the title because I have no evidence that
>> this can actually happen, but I suspect that a crafted netlink
>> packet can trigger some badness.
>
> nlmsg

Oops. I meant to say that nlmsg_for_each_msg() has no users at all,
which means that the change is all the more "theoretical" :-)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] netlink: fix (theoretical) overrun in message iteration
  2008-12-21 13:42 [PATCH] netlink: fix (theoretical) overrun in message iteration Vegard Nossum
  2008-12-21 14:44 ` Vegard Nossum
@ 2008-12-26  1:20 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2008-12-26  1:20 UTC (permalink / raw)
  To: vegard.nossum; +Cc: tgraf, eugeneteo, akpm, viro, netdev, linux-kernel

From: Vegard Nossum <vegard.nossum@gmail.com>
Date: Sun, 21 Dec 2008 14:42:18 +0100

> netlink: fix (theoretical) overrun in message iteration

I'll apply this but we should also consider getting rid
of unused interfaces such as nlmsg_for_each_msg().


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-26  1:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-21 13:42 [PATCH] netlink: fix (theoretical) overrun in message iteration Vegard Nossum
2008-12-21 14:44 ` Vegard Nossum
2008-12-21 14:46   ` Vegard Nossum
2008-12-26  1:20 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).