netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>,
	David Miller <davem@davemloft.net>,
	netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net] ipv4: fix memory leaks in ip_cmsg_send() callers
Date: Mon, 15 Feb 2016 12:11:34 -0800	[thread overview]
Message-ID: <CAM_iQpWq2=Z70Qxh=WFgsPer7XwDo9T7P0ZhCDbk2zaBr3ZmWQ@mail.gmail.com> (raw)
In-Reply-To: <1454595808.7627.296.camel@edumazet-glaptop2.roam.corp.google.com>

On Thu, Feb 4, 2016 at 6:23 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> Dmitry reported memory leaks of IP options allocated in
> ip_cmsg_send() when/if this function returns an error.
>
> Callers are responsible for the freeing.

Right, because there is a loop in ip_cmsg_send(), so the callers
are easier to free it than the callee.

The other thing is we perhaps have another leak in the following code:

        if (ipc.opt && ipc.opt->opt.srr) {
                if (!daddr)
                        return -EINVAL;
                faddr = ipc.opt->opt.faddr;
        }

since ipc.opt could be allocated on heap... We need something like:

@@ -770,8 +770,11 @@ 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)
+               if (!daddr) {
+                       if (free)
+                               kfree(ipc.opt);
                        return -EINVAL;
+               }
                faddr = ipc.opt->opt.faddr;
        }
        tos = get_rttos(&ipc, inet);

      parent reply	other threads:[~2016-02-15 20:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-04  9:47 net: memory leak in ip_cmsg_send Dmitry Vyukov
2016-02-04 14:04 ` Eric Dumazet
2016-02-04 14:23   ` [PATCH net] ipv4: fix memory leaks in ip_cmsg_send() callers Eric Dumazet
2016-02-13 10:59     ` David Miller
2016-02-15 20:11     ` Cong Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAM_iQpWq2=Z70Qxh=WFgsPer7XwDo9T7P0ZhCDbk2zaBr3ZmWQ@mail.gmail.com' \
    --to=xiyou.wangcong@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dvyukov@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).