Skip to content

Commit 338bb57

Browse files
idoschPaolo Abeni
authored andcommitted
ipv4: Fix incorrect TOS in route get reply
The TOS value that is returned to user space in the route get reply is the one with which the lookup was performed ('fl4->flowi4_tos'). This is fine when the matched route is configured with a TOS as it would not match if its TOS value did not match the one with which the lookup was performed. However, matching on TOS is only performed when the route's TOS is not zero. It is therefore possible to have the kernel incorrectly return a non-zero TOS: # ip link add name dummy1 up type dummy # ip address add 192.0.2.1/24 dev dummy1 # ip route get 192.0.2.2 tos 0xfc 192.0.2.2 tos 0x1c dev dummy1 src 192.0.2.1 uid 0 cache Fix by adding a DSCP field to the FIB result structure (inside an existing 4 bytes hole), populating it in the route lookup and using it when filling the route get reply. Output after the patch: # ip link add name dummy1 up type dummy # ip address add 192.0.2.1/24 dev dummy1 # ip route get 192.0.2.2 tos 0xfc 192.0.2.2 dev dummy1 src 192.0.2.1 uid 0 cache Fixes: 1a00fee ("ipv4: Remove rt_key_{src,dst,tos} from struct rtable.") Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Guillaume Nault <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 120f1c8 commit 338bb57

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

include/net/ip_fib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct fib_result {
173173
unsigned char type;
174174
unsigned char scope;
175175
u32 tclassid;
176+
dscp_t dscp;
176177
struct fib_nh_common *nhc;
177178
struct fib_info *fi;
178179
struct fib_table *table;

net/ipv4/fib_trie.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
16291629
res->nhc = nhc;
16301630
res->type = fa->fa_type;
16311631
res->scope = fi->fib_scope;
1632+
res->dscp = fa->fa_dscp;
16321633
res->fi = fi;
16331634
res->table = tb;
16341635
res->fa_head = &n->leaf;

net/ipv4/route.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,9 +2867,9 @@ EXPORT_SYMBOL_GPL(ip_route_output_flow);
28672867

28682868
/* called with rcu_read_lock held */
28692869
static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
2870-
struct rtable *rt, u32 table_id, struct flowi4 *fl4,
2871-
struct sk_buff *skb, u32 portid, u32 seq,
2872-
unsigned int flags)
2870+
struct rtable *rt, u32 table_id, dscp_t dscp,
2871+
struct flowi4 *fl4, struct sk_buff *skb, u32 portid,
2872+
u32 seq, unsigned int flags)
28732873
{
28742874
struct rtmsg *r;
28752875
struct nlmsghdr *nlh;
@@ -2885,7 +2885,7 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
28852885
r->rtm_family = AF_INET;
28862886
r->rtm_dst_len = 32;
28872887
r->rtm_src_len = 0;
2888-
r->rtm_tos = fl4 ? fl4->flowi4_tos : 0;
2888+
r->rtm_tos = inet_dscp_to_dsfield(dscp);
28892889
r->rtm_table = table_id < 256 ? table_id : RT_TABLE_COMPAT;
28902890
if (nla_put_u32(skb, RTA_TABLE, table_id))
28912891
goto nla_put_failure;
@@ -3035,7 +3035,7 @@ static int fnhe_dump_bucket(struct net *net, struct sk_buff *skb,
30353035
goto next;
30363036

30373037
err = rt_fill_info(net, fnhe->fnhe_daddr, 0, rt,
3038-
table_id, NULL, skb,
3038+
table_id, 0, NULL, skb,
30393039
NETLINK_CB(cb->skb).portid,
30403040
cb->nlh->nlmsg_seq, flags);
30413041
if (err)
@@ -3358,8 +3358,8 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
33583358
err = fib_dump_info(skb, NETLINK_CB(in_skb).portid,
33593359
nlh->nlmsg_seq, RTM_NEWROUTE, &fri, 0);
33603360
} else {
3361-
err = rt_fill_info(net, dst, src, rt, table_id, &fl4, skb,
3362-
NETLINK_CB(in_skb).portid,
3361+
err = rt_fill_info(net, dst, src, rt, table_id, res.dscp, &fl4,
3362+
skb, NETLINK_CB(in_skb).portid,
33633363
nlh->nlmsg_seq, 0);
33643364
}
33653365
if (err < 0)

0 commit comments

Comments
 (0)