All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: xiyou.wangcong@gmail.com
Cc: netdev@vger.kernel.org,
	syzbot+21f04f481f449c8db840@syzkaller.appspotmail.com,
	Jason@zx2c4.com, fw@strlen.de, pablo@netfilter.org,
	jiri@mellanox.com, yuehaibing@huawei.com, cscnull@gmail.com
Subject: Re: [Patch net v2] genetlink: fix memory leaks in genl_family_rcv_msg_dumpit()
Date: Thu, 04 Jun 2020 15:36:53 -0700 (PDT)	[thread overview]
Message-ID: <20200604.153653.1843003918166065022.davem@davemloft.net> (raw)
In-Reply-To: <20200603044910.27259-1-xiyou.wangcong@gmail.com>

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Tue,  2 Jun 2020 21:49:10 -0700

> There are two kinds of memory leaks in genl_family_rcv_msg_dumpit():
> 
> 1. Before we call ops->start(), whenever an error happens, we forget
>    to free the memory allocated in genl_family_rcv_msg_dumpit().
> 
> 2. When ops->start() fails, the 'info' has been already installed on
>    the per socket control block, so we should not free it here. More
>    importantly, nlk->cb_running is still false at this point, so
>    netlink_sock_destruct() cannot free it either.
> 
> The first kind of memory leaks is easier to resolve, but the second
> one requires some deeper thoughts.
> 
> After reviewing how netfilter handles this, the most elegant solution
> I find is just to use a similar way to allocate the memory, that is,
> moving memory allocations from caller into ops->start(). With this,
> we can solve both kinds of memory leaks: for 1), no memory allocation
> happens before ops->start(); for 2), ops->start() handles its own
> failures and 'info' is installed to the socket control block only
> when success. The only ugliness here is we have to pass all local
> variables on stack via a struct, but this is not hard to understand.
> 
> Alternatively, we can introduce a ops->free() to solve this too,
> but it is overkill as only genetlink has this problem so far.
> 
> Fixes: 1927f41a22a0 ("net: genetlink: introduce dump info struct to be available during dumpit op")
> Reported-by: syzbot+21f04f481f449c8db840@syzkaller.appspotmail.com
> Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
> Cc: Florian Westphal <fw@strlen.de>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Cc: Jiri Pirko <jiri@mellanox.com>
> Cc: YueHaibing <yuehaibing@huawei.com>
> Cc: Shaochun Chen <cscnull@gmail.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied and queued up for -stable, thanks.

  reply	other threads:[~2020-06-04 22:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03  4:49 [Patch net v2] genetlink: fix memory leaks in genl_family_rcv_msg_dumpit() Cong Wang
2020-06-04 22:36 ` David Miller [this message]
2020-06-10 14:27 ` Ido Schimmel
2020-06-11  4:14   ` Cong Wang

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=20200604.153653.1843003918166065022.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=Jason@zx2c4.com \
    --cc=cscnull@gmail.com \
    --cc=fw@strlen.de \
    --cc=jiri@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=syzbot+21f04f481f449c8db840@syzkaller.appspotmail.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yuehaibing@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.