Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg
Browse files Browse the repository at this point in the history
[ Upstream commit 1b97013 ]

Fix more memory leaks in ip_cmsg_send() callers. Part of them were fixed
earlier in 9194830.

* udp_sendmsg one was there since the beginning when linux sources were
  first added to git;
* ping_v4_sendmsg one was copy/pasted in c319b4d.

Whenever return happens in udp_sendmsg() or ping_v4_sendmsg() IP options
have to be freed if they were allocated previously.

Add label so that future callers (if any) can use it instead of kfree()
before return that is easy to forget.

Fixes: c319b4d (net: ipv4: add IPPROTO_ICMP socket kind)
Signed-off-by: Andrey Ignatov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
rdna authored and gregkh committed May 19, 2018
1 parent c751af5 commit a7aea8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,10 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
ipc.addr = faddr = daddr;

if (ipc.opt && ipc.opt->opt.srr) {
if (!daddr)
return -EINVAL;
if (!daddr) {
err = -EINVAL;
goto out_free;
}
faddr = ipc.opt->opt.faddr;
}
tos = get_rttos(&ipc, inet);
Expand Down Expand Up @@ -842,6 +844,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

out:
ip_rt_put(rt);
out_free:
if (free)
kfree(ipc.opt);
if (!err) {
Expand Down
7 changes: 5 additions & 2 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,10 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
sock_tx_timestamp(sk, ipc.sockc.tsflags, &ipc.tx_flags);

if (ipc.opt && ipc.opt->opt.srr) {
if (!daddr)
return -EINVAL;
if (!daddr) {
err = -EINVAL;
goto out_free;
}
faddr = ipc.opt->opt.faddr;
connected = 0;
}
Expand Down Expand Up @@ -1087,6 +1089,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

out:
ip_rt_put(rt);
out_free:
if (free)
kfree(ipc.opt);
if (!err)
Expand Down

0 comments on commit a7aea8e

Please sign in to comment.