]> git.baikalelectronics.ru Git - kernel.git/commitdiff
Revert "ipv4: fix memory leaks in ip_cmsg_send() callers"
authorYajun Deng <yajun.deng@linux.dev>
Mon, 13 Sep 2021 04:04:42 +0000 (12:04 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 13 Sep 2021 11:37:04 +0000 (12:37 +0100)
This reverts commit 49587447b55d63cd1e97ce4a70011e2a512ead98.

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

Fixes: 49587447b55d ("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>
net/ipv4/ip_sockglue.c
net/ipv4/ping.c
net/ipv4/raw.c
net/ipv4/udp.c

index b297bb28556ec5cf383068f67ee910af38591cc3..7cef9987ab4ace4444c4b470a3393ce50219a69a 100644 (file)
@@ -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);
index 1e44a43acfe2dfe57efdc64479c2d18402881d73..c588f9f2f46c2b91fc9424ecfc0590b2b63a3470 100644 (file)
@@ -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;
        }
index bb446e60cf58057b448f094b4d6f48d6e91d113c..1c98063a3ae816ecfd7135b0168fea5a9380676f 100644 (file)
@@ -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;
        }
index 8851c9463b4b62c9017565f545250c4ffe22927c..d5f5981d7a43244cace63653b790a34174364e3e 100644 (file)
@@ -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;