diff options
author | David S. Miller <davem@sunset.davemloft.net> | 2006-10-12 03:49:15 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-10-12 03:49:15 -0400 |
commit | 8238b218ec883adb44d710960a031c76105274cd (patch) | |
tree | 09880b229d0090298f30bf0168a4702bbc0e918a /net | |
parent | 42b6785eeb40fe3e9dab9981b6e3231a77c7c2f6 (diff) |
[NET]: Do not memcmp() over pad bytes of struct flowi.
They are not necessarily initialized to zero by the compiler,
for example when using run-time initializers of automatic
on-stack variables.
Noticed by Eric Dumazet and Patrick McHardy.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/decnet/dn_route.c | 11 | ||||
-rw-r--r-- | net/ipv4/route.c | 12 |
2 files changed, 17 insertions, 6 deletions
diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c index dd0761e3d280..a2a43d8d93fe 100644 --- a/net/decnet/dn_route.c +++ b/net/decnet/dn_route.c | |||
@@ -267,9 +267,14 @@ static void dn_dst_link_failure(struct sk_buff *skb) | |||
267 | 267 | ||
268 | static inline int compare_keys(struct flowi *fl1, struct flowi *fl2) | 268 | static inline int compare_keys(struct flowi *fl1, struct flowi *fl2) |
269 | { | 269 | { |
270 | return memcmp(&fl1->nl_u.dn_u, &fl2->nl_u.dn_u, sizeof(fl1->nl_u.dn_u)) == 0 && | 270 | return ((fl1->nl_u.dn_u.daddr ^ fl2->nl_u.dn_u.daddr) | |
271 | fl1->oif == fl2->oif && | 271 | (fl1->nl_u.dn_u.saddr ^ fl2->nl_u.dn_u.saddr) | |
272 | fl1->iif == fl2->iif; | 272 | #ifdef CONFIG_IP_ROUTE_FWMARK |
273 | (fl1->nl_u.dn_u.fwmark ^ fl2->nl_u.dn_u.fwmark) | | ||
274 | #endif | ||
275 | (fl1->nl_u.dn_u.scope ^ fl2->nl_u.dn_u.scope) | | ||
276 | (fl1->oif ^ fl2->oif) | | ||
277 | (fl1->iif ^ fl2->iif)) == 0; | ||
273 | } | 278 | } |
274 | 279 | ||
275 | static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp) | 280 | static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route **rp) |
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index c41ddba02e9d..925ee4dfc32c 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -566,9 +566,15 @@ static inline u32 rt_score(struct rtable *rt) | |||
566 | 566 | ||
567 | static inline int compare_keys(struct flowi *fl1, struct flowi *fl2) | 567 | static inline int compare_keys(struct flowi *fl1, struct flowi *fl2) |
568 | { | 568 | { |
569 | return memcmp(&fl1->nl_u.ip4_u, &fl2->nl_u.ip4_u, sizeof(fl1->nl_u.ip4_u)) == 0 && | 569 | return ((fl1->nl_u.ip4_u.daddr ^ fl2->nl_u.ip4_u.daddr) | |
570 | fl1->oif == fl2->oif && | 570 | (fl1->nl_u.ip4_u.saddr ^ fl2->nl_u.ip4_u.saddr) | |
571 | fl1->iif == fl2->iif; | 571 | #ifdef CONFIG_IP_ROUTE_FWMARK |
572 | (fl1->nl_u.ip4_u.fwmark ^ fl2->nl_u.ip4_u.fwmark) | | ||
573 | #endif | ||
574 | (*(u16 *)&fl1->nl_u.ip4_u.tos ^ | ||
575 | *(u16 *)&fl2->nl_u.ip4_u.tos) | | ||
576 | (fl1->oif ^ fl2->oif) | | ||
577 | (fl1->iif ^ fl2->iif)) == 0; | ||
572 | } | 578 | } |
573 | 579 | ||
574 | #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED | 580 | #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED |