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

From: David Miller
Date: Thu Sep 11 2008 - 18:04:53 EST


From: Vegard Nossum <vegard.nossum@xxxxxxxxx>
Date: Thu, 11 Sep 2008 22:59:33 +0200

> A short example illustrating this point is here:
>
> #include <stdio.h>
>
> main(void)
> {
> printf("%d\n", -1 >= sizeof(int));
> }
>
> ...which prints "1".

Someone should print that out on a huge poster, it's a good
example of why C promotion rules suck :)

> This patch adds a cast in front of the sizeof so that GCC will make
> a signed comparison and fix the illegal memory dereference. With the
> patch applied, there is no kmemcheck report.
>
> Cc: Thomas Graf <tgraf@xxxxxxx>
> Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxx>

Thomas, please review.

> diff --git a/include/net/netlink.h b/include/net/netlink.h
> index 18024b8..208fe5a 100644
> --- a/include/net/netlink.h
> +++ b/include/net/netlink.h
> @@ -702,7 +702,7 @@ static inline int nla_len(const struct nlattr *nla)
> */
> static inline int nla_ok(const struct nlattr *nla, int remaining)
> {
> - return remaining >= sizeof(*nla) &&
> + return remaining >= (int) sizeof(*nla) &&
> nla->nla_len >= sizeof(*nla) &&
> nla->nla_len <= remaining;
> }
> --
> 1.5.5.1
>
--
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/