Skip to content

Commit

Permalink
switchdev: pass pointer to fib_info instead of copy
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jpirko authored and davem330 committed May 17, 2016
1 parent dc327f8 commit da4ed55
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions drivers/net/ethernet/rocker/rocker_ofdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,7 @@ static int ofdpa_port_obj_fib4_add(struct rocker_port *rocker_port,

return ofdpa_port_fib_ipv4(ofdpa_port, trans,
htonl(fib4->dst), fib4->dst_len,
&fib4->fi, fib4->tb_id, 0);
fib4->fi, fib4->tb_id, 0);
}

static int ofdpa_port_obj_fib4_del(struct rocker_port *rocker_port,
Expand All @@ -2737,7 +2737,7 @@ static int ofdpa_port_obj_fib4_del(struct rocker_port *rocker_port,

return ofdpa_port_fib_ipv4(ofdpa_port, NULL,
htonl(fib4->dst), fib4->dst_len,
&fib4->fi, fib4->tb_id,
fib4->fi, fib4->tb_id,
OFDPA_OP_FLAG_REMOVE);
}

Expand Down
2 changes: 1 addition & 1 deletion include/net/switchdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct switchdev_obj_ipv4_fib {
struct switchdev_obj obj;
u32 dst;
int dst_len;
struct fib_info fi;
struct fib_info *fi;
u8 tos;
u8 type;
u32 nlflags;
Expand Down
6 changes: 2 additions & 4 deletions net/switchdev/switchdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
.obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB,
.dst = dst,
.dst_len = dst_len,
.fi = fi,
.tos = tos,
.type = type,
.nlflags = nlflags,
Expand All @@ -1196,8 +1197,6 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
struct net_device *dev;
int err = 0;

memcpy(&ipv4_fib.fi, fi, sizeof(ipv4_fib.fi));

/* Don't offload route if using custom ip rules or if
* IPv4 FIB offloading has been disabled completely.
*/
Expand Down Expand Up @@ -1242,6 +1241,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
.obj.id = SWITCHDEV_OBJ_ID_IPV4_FIB,
.dst = dst,
.dst_len = dst_len,
.fi = fi,
.tos = tos,
.type = type,
.nlflags = 0,
Expand All @@ -1250,8 +1250,6 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
struct net_device *dev;
int err = 0;

memcpy(&ipv4_fib.fi, fi, sizeof(ipv4_fib.fi));

if (!(fi->fib_flags & RTNH_F_OFFLOAD))
return 0;

Expand Down

0 comments on commit da4ed55

Please sign in to comment.