Skip to content

Commit da4ed55

Browse files
jpirkodavem330
authored andcommitted
switchdev: pass pointer to fib_info instead of copy
The problem is that fib_info->nh is [0] so the struct fib_info allocation size depends on number of nexthops. If we just copy fib_info, we do not copy the nexthops info and driver accesses memory which is not ours. Given the fact that fib4 does not defer operations and therefore it does not need copy, just pass the pointer down to drivers as it was done before. Fixes: 850d0cb ("switchdev: remove pointers from switchdev objects") Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dc327f8 commit da4ed55

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎drivers/net/ethernet/rocker/rocker_ofdpa.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,7 @@ static int ofdpa_port_obj_fib4_add(struct rocker_port *rocker_port,
27272727

27282728
return ofdpa_port_fib_ipv4(ofdpa_port, trans,
27292729
htonl(fib4->dst), fib4->dst_len,
2730-
&fib4->fi, fib4->tb_id, 0);
2730+
fib4->fi, fib4->tb_id, 0);
27312731
}
27322732

27332733
static int ofdpa_port_obj_fib4_del(struct rocker_port *rocker_port,
@@ -2737,7 +2737,7 @@ static int ofdpa_port_obj_fib4_del(struct rocker_port *rocker_port,
27372737

27382738
return ofdpa_port_fib_ipv4(ofdpa_port, NULL,
27392739
htonl(fib4->dst), fib4->dst_len,
2740-
&fib4->fi, fib4->tb_id,
2740+
fib4->fi, fib4->tb_id,
27412741
OFDPA_OP_FLAG_REMOVE);
27422742
}
27432743

‎include/net/switchdev.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct switchdev_obj_ipv4_fib {
9797
struct switchdev_obj obj;
9898
u32 dst;
9999
int dst_len;
100-
struct fib_info fi;
100+
struct fib_info *fi;
101101
u8 tos;
102102
u8 type;
103103
u32 nlflags;

‎net/switchdev/switchdev.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
11881188
.obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB,
11891189
.dst = dst,
11901190
.dst_len = dst_len,
1191+
.fi = fi,
11911192
.tos = tos,
11921193
.type = type,
11931194
.nlflags = nlflags,
@@ -1196,8 +1197,6 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
11961197
struct net_device *dev;
11971198
int err = 0;
11981199

1199-
memcpy(&ipv4_fib.fi, fi, sizeof(ipv4_fib.fi));
1200-
12011200
/* Don't offload route if using custom ip rules or if
12021201
* IPv4 FIB offloading has been disabled completely.
12031202
*/
@@ -1242,6 +1241,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
12421241
.obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB,
12431242
.dst = dst,
12441243
.dst_len = dst_len,
1244+
.fi = fi,
12451245
.tos = tos,
12461246
.type = type,
12471247
.nlflags = 0,
@@ -1250,8 +1250,6 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
12501250
struct net_device *dev;
12511251
int err = 0;
12521252

1253-
memcpy(&ipv4_fib.fi, fi, sizeof(ipv4_fib.fi));
1254-
12551253
if (!(fi->fib_flags & RTNH_F_OFFLOAD))
12561254
return 0;
12571255

0 commit comments

Comments
 (0)