Skip to content

Commit

Permalink
Revert "ipv4: fix memory leaks in ip_cmsg_send() callers"
Browse files Browse the repository at this point in the history
This reverts commit 9194830.

There is only when ip_options_get() return zero need to free.
It already called kfree() when return error.

Fixes: 9194830 ("ipv4: fix memory leaks in ip_cmsg_send() callers")
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Yajun Deng authored and David S. Miller committed Sep 13, 2021
1 parent 2049eb0 commit d7807a9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
case IP_RETOPTS:
err = cmsg->cmsg_len - sizeof(struct cmsghdr);

/* Our caller is responsible for freeing ipc->opt */
/* Our caller is responsible for freeing ipc->opt when err = 0 */
err = ip_options_get(net, &ipc->opt,
KERNEL_SOCKPTR(CMSG_DATA(cmsg)),
err < 40 ? err : 40);
Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,9 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

if (msg->msg_controllen) {
err = ip_cmsg_send(sk, msg, &ipc, false);
if (unlikely(err)) {
kfree(ipc.opt);
if (unlikely(err))
return err;
}

if (ipc.opt)
free = 1;
}
Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,9 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

if (msg->msg_controllen) {
err = ip_cmsg_send(sk, msg, &ipc, false);
if (unlikely(err)) {
kfree(ipc.opt);
if (unlikely(err))
goto out;
}

if (ipc.opt)
free = 1;
}
Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,10 +1122,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (err > 0)
err = ip_cmsg_send(sk, msg, &ipc,
sk->sk_family == AF_INET6);
if (unlikely(err < 0)) {
kfree(ipc.opt);
if (unlikely(err < 0))
return err;
}

if (ipc.opt)
free = 1;
connected = 0;
Expand Down

0 comments on commit d7807a9

Please sign in to comment.