Skip to content

Commit 9e0f043

Browse files
committed
netfilter: nft_flow_offload: reset dst in route object after setting up flow
dst is transferred to the flow object, route object does not own it anymore. Reset dst in route object, otherwise if flow_offload_add() fails, error path releases dst twice, leading to a refcount underflow. Fixes: a3c90f7 ("netfilter: nf_tables: flow offload expression") Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent bccebf6 commit 9e0f043

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/net/netfilter/nf_flow_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table,
276276
}
277277

278278
void flow_offload_route_init(struct flow_offload *flow,
279-
const struct nf_flow_route *route);
279+
struct nf_flow_route *route);
280280

281281
int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
282282
void flow_offload_refresh(struct nf_flowtable *flow_table,

net/netfilter/nf_flow_table_core.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,22 @@ static u32 flow_offload_dst_cookie(struct flow_offload_tuple *flow_tuple)
8787
return 0;
8888
}
8989

90+
static struct dst_entry *nft_route_dst_fetch(struct nf_flow_route *route,
91+
enum flow_offload_tuple_dir dir)
92+
{
93+
struct dst_entry *dst = route->tuple[dir].dst;
94+
95+
route->tuple[dir].dst = NULL;
96+
97+
return dst;
98+
}
99+
90100
static int flow_offload_fill_route(struct flow_offload *flow,
91-
const struct nf_flow_route *route,
101+
struct nf_flow_route *route,
92102
enum flow_offload_tuple_dir dir)
93103
{
94104
struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
95-
struct dst_entry *dst = route->tuple[dir].dst;
105+
struct dst_entry *dst = nft_route_dst_fetch(route, dir);
96106
int i, j = 0;
97107

98108
switch (flow_tuple->l3proto) {
@@ -146,7 +156,7 @@ static void nft_flow_dst_release(struct flow_offload *flow,
146156
}
147157

148158
void flow_offload_route_init(struct flow_offload *flow,
149-
const struct nf_flow_route *route)
159+
struct nf_flow_route *route)
150160
{
151161
flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_ORIGINAL);
152162
flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_REPLY);

0 commit comments

Comments
 (0)