Skip to content

Commit 3773d65

Browse files
jk-ozlabskuba-moo
authored andcommitted
net: mctp: take ownership of skb in mctp_local_output
Currently, mctp_local_output only takes ownership of skb on success, and we may leak an skb if mctp_local_output fails in specific states; the skb ownership isn't transferred until the actual output routing occurs. Instead, make mctp_local_output free the skb on all error paths up to the route action, so it always consumes the passed skb. Fixes: 833ef3b ("mctp: Populate socket implementation") Signed-off-by: Jeremy Kerr <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e872469 commit 3773d65

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

include/net/mctp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ struct mctp_route {
249249
struct mctp_route *mctp_route_lookup(struct net *net, unsigned int dnet,
250250
mctp_eid_t daddr);
251251

252+
/* always takes ownership of skb */
252253
int mctp_local_output(struct sock *sk, struct mctp_route *rt,
253254
struct sk_buff *skb, mctp_eid_t daddr, u8 req_tag);
254255

net/mctp/route.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
888888
dev = dev_get_by_index_rcu(sock_net(sk), cb->ifindex);
889889
if (!dev) {
890890
rcu_read_unlock();
891-
return rc;
891+
goto out_free;
892892
}
893893
rt->dev = __mctp_dev_get(dev);
894894
rcu_read_unlock();
@@ -903,7 +903,8 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
903903
rt->mtu = 0;
904904

905905
} else {
906-
return -EINVAL;
906+
rc = -EINVAL;
907+
goto out_free;
907908
}
908909

909910
spin_lock_irqsave(&rt->dev->addrs_lock, flags);
@@ -966,12 +967,17 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
966967
rc = mctp_do_fragment_route(rt, skb, mtu, tag);
967968
}
968969

970+
/* route output functions consume the skb, even on error */
971+
skb = NULL;
972+
969973
out_release:
970974
if (!ext_rt)
971975
mctp_route_release(rt);
972976

973977
mctp_dev_put(tmp_rt.dev);
974978

979+
out_free:
980+
kfree_skb(skb);
975981
return rc;
976982
}
977983

0 commit comments

Comments
 (0)