netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] audit: fix memory leak in nf_tables_commit
@ 2021-07-13  9:41 Dongliang Mu
  2021-07-13 11:47 ` Lukas Bulwahn
  0 siblings, 1 reply; 4+ messages in thread
From: Dongliang Mu @ 2021-07-13  9:41 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, Jakub Kicinski, Paul Moore, Richard Guy Briggs
  Cc: Dongliang Mu, syzbot, netfilter-devel, coreteam, netdev, linux-kernel

In nf_tables_commit, if nf_tables_commit_audit_alloc fails, it does not
free the adp variable.

Fix this by freeing the linked list with head adl.

backtrace:
  kmalloc include/linux/slab.h:591 [inline]
  kzalloc include/linux/slab.h:721 [inline]
  nf_tables_commit_audit_alloc net/netfilter/nf_tables_api.c:8439 [inline]
  nf_tables_commit+0x16e/0x1760 net/netfilter/nf_tables_api.c:8508
  nfnetlink_rcv_batch+0x512/0xa80 net/netfilter/nfnetlink.c:562
  nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:634 [inline]
  nfnetlink_rcv+0x1fa/0x220 net/netfilter/nfnetlink.c:652
  netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
  netlink_unicast+0x2c7/0x3e0 net/netlink/af_netlink.c:1340
  netlink_sendmsg+0x36b/0x6b0 net/netlink/af_netlink.c:1929
  sock_sendmsg_nosec net/socket.c:702 [inline]
  sock_sendmsg+0x56/0x80 net/socket.c:722

Reported-by: syzbot <syzkaller@googlegroups.com>
Fixes: c520292f29b8 ("audit: log nftables configuration change events once per table")
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 net/netfilter/nf_tables_api.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 390d4466567f..7f45b291be13 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -8444,6 +8444,16 @@ static int nf_tables_commit_audit_alloc(struct list_head *adl,
 	return 0;
 }
 
+static void nf_tables_commit_free(struct list_head *adl)
+{
+	struct nft_audit_data *adp, *adn;
+
+	list_for_each_entry_safe(adp, adn, adl, list) {
+		list_del(&adp->list);
+		kfree(adp);
+	}
+}
+
 static void nf_tables_commit_audit_collect(struct list_head *adl,
 					   struct nft_table *table, u32 op)
 {
@@ -8508,6 +8518,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
 		ret = nf_tables_commit_audit_alloc(&adl, trans->ctx.table);
 		if (ret) {
 			nf_tables_commit_chain_prepare_cancel(net);
+			nf_tables_commit_free(adl);
 			return ret;
 		}
 		if (trans->msg_type == NFT_MSG_NEWRULE ||
@@ -8517,6 +8528,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
 			ret = nf_tables_commit_chain_prepare(net, chain);
 			if (ret < 0) {
 				nf_tables_commit_chain_prepare_cancel(net);
+				nf_tables_commit_free(adl);
 				return ret;
 			}
 		}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] audit: fix memory leak in nf_tables_commit
  2021-07-13  9:41 [PATCH] audit: fix memory leak in nf_tables_commit Dongliang Mu
@ 2021-07-13 11:47 ` Lukas Bulwahn
  2021-07-13 11:51   ` Dongliang Mu
  0 siblings, 1 reply; 4+ messages in thread
From: Lukas Bulwahn @ 2021-07-13 11:47 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, Jakub Kicinski, Paul Moore, Richard Guy Briggs,
	syzbot, netfilter-devel, coreteam, Netdev,
	Linux Kernel Mailing List

On Tue, Jul 13, 2021 at 11:42 AM Dongliang Mu <mudongliangabcd@gmail.com> wrote:
>
> In nf_tables_commit, if nf_tables_commit_audit_alloc fails, it does not
> free the adp variable.
>
> Fix this by freeing the linked list with head adl.
>
> backtrace:
>   kmalloc include/linux/slab.h:591 [inline]
>   kzalloc include/linux/slab.h:721 [inline]
>   nf_tables_commit_audit_alloc net/netfilter/nf_tables_api.c:8439 [inline]
>   nf_tables_commit+0x16e/0x1760 net/netfilter/nf_tables_api.c:8508
>   nfnetlink_rcv_batch+0x512/0xa80 net/netfilter/nfnetlink.c:562
>   nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:634 [inline]
>   nfnetlink_rcv+0x1fa/0x220 net/netfilter/nfnetlink.c:652
>   netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
>   netlink_unicast+0x2c7/0x3e0 net/netlink/af_netlink.c:1340
>   netlink_sendmsg+0x36b/0x6b0 net/netlink/af_netlink.c:1929
>   sock_sendmsg_nosec net/socket.c:702 [inline]
>   sock_sendmsg+0x56/0x80 net/socket.c:722
>
> Reported-by: syzbot <syzkaller@googlegroups.com>

As far as I see, the more default way is to reference to syzbot by:

Reported-by: syzbot+[[20-letter hex reference]]@syzkaller.appspotmail.com

as in for example:

Reported-by: syzbot+fee64147a25aecd48055@syzkaller.appspotmail.com

A rough count says that format above is used 1300 times, whereas

Reported-by: syzbot <syzkaller@googlegroups.com>

is only used about 330 times.


Lukas

> Fixes: c520292f29b8 ("audit: log nftables configuration change events once per table")
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> ---
>  net/netfilter/nf_tables_api.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index 390d4466567f..7f45b291be13 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -8444,6 +8444,16 @@ static int nf_tables_commit_audit_alloc(struct list_head *adl,
>         return 0;
>  }
>
> +static void nf_tables_commit_free(struct list_head *adl)
> +{
> +       struct nft_audit_data *adp, *adn;
> +
> +       list_for_each_entry_safe(adp, adn, adl, list) {
> +               list_del(&adp->list);
> +               kfree(adp);
> +       }
> +}
> +
>  static void nf_tables_commit_audit_collect(struct list_head *adl,
>                                            struct nft_table *table, u32 op)
>  {
> @@ -8508,6 +8518,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
>                 ret = nf_tables_commit_audit_alloc(&adl, trans->ctx.table);
>                 if (ret) {
>                         nf_tables_commit_chain_prepare_cancel(net);
> +                       nf_tables_commit_free(adl);
>                         return ret;
>                 }
>                 if (trans->msg_type == NFT_MSG_NEWRULE ||
> @@ -8517,6 +8528,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
>                         ret = nf_tables_commit_chain_prepare(net, chain);
>                         if (ret < 0) {
>                                 nf_tables_commit_chain_prepare_cancel(net);
> +                               nf_tables_commit_free(adl);
>                                 return ret;
>                         }
>                 }
> --
> 2.25.1
>
> --
> You received this message because you are subscribed to the Google Groups "syzkaller" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller/20210713094158.450434-1-mudongliangabcd%40gmail.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] audit: fix memory leak in nf_tables_commit
  2021-07-13 11:47 ` Lukas Bulwahn
@ 2021-07-13 11:51   ` Dongliang Mu
  2021-07-13 12:04     ` Lukas Bulwahn
  0 siblings, 1 reply; 4+ messages in thread
From: Dongliang Mu @ 2021-07-13 11:51 UTC (permalink / raw)
  To: Lukas Bulwahn
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, Jakub Kicinski, Paul Moore, Richard Guy Briggs,
	syzbot, netfilter-devel, coreteam, Netdev,
	Linux Kernel Mailing List

On Tue, Jul 13, 2021 at 7:47 PM Lukas Bulwahn <lukas.bulwahn@gmail.com> wrote:
>
> On Tue, Jul 13, 2021 at 11:42 AM Dongliang Mu <mudongliangabcd@gmail.com> wrote:
> >
> > In nf_tables_commit, if nf_tables_commit_audit_alloc fails, it does not
> > free the adp variable.
> >
> > Fix this by freeing the linked list with head adl.
> >
> > backtrace:
> >   kmalloc include/linux/slab.h:591 [inline]
> >   kzalloc include/linux/slab.h:721 [inline]
> >   nf_tables_commit_audit_alloc net/netfilter/nf_tables_api.c:8439 [inline]
> >   nf_tables_commit+0x16e/0x1760 net/netfilter/nf_tables_api.c:8508
> >   nfnetlink_rcv_batch+0x512/0xa80 net/netfilter/nfnetlink.c:562
> >   nfnetlink_rcv_skb_batch net/netfilter/nfnetlink.c:634 [inline]
> >   nfnetlink_rcv+0x1fa/0x220 net/netfilter/nfnetlink.c:652
> >   netlink_unicast_kernel net/netlink/af_netlink.c:1314 [inline]
> >   netlink_unicast+0x2c7/0x3e0 net/netlink/af_netlink.c:1340
> >   netlink_sendmsg+0x36b/0x6b0 net/netlink/af_netlink.c:1929
> >   sock_sendmsg_nosec net/socket.c:702 [inline]
> >   sock_sendmsg+0x56/0x80 net/socket.c:722
> >
> > Reported-by: syzbot <syzkaller@googlegroups.com>
>
> As far as I see, the more default way is to reference to syzbot by:
>
> Reported-by: syzbot+[[20-letter hex reference]]@syzkaller.appspotmail.com
>

Hi Lukas,

this bug is not listed on the syzbot dashboard. I found this bug by
setting up a local syzkaller instance, so I only list syzbot other
than concrete syzbot id.

best regards,
Dongliang Mu

> as in for example:
>
> Reported-by: syzbot+fee64147a25aecd48055@syzkaller.appspotmail.com
>
> A rough count says that format above is used 1300 times, whereas
>
> Reported-by: syzbot <syzkaller@googlegroups.com>
>
> is only used about 330 times.
>
>
> Lukas
>
> > Fixes: c520292f29b8 ("audit: log nftables configuration change events once per table")
> > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > ---
> >  net/netfilter/nf_tables_api.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> > index 390d4466567f..7f45b291be13 100644
> > --- a/net/netfilter/nf_tables_api.c
> > +++ b/net/netfilter/nf_tables_api.c
> > @@ -8444,6 +8444,16 @@ static int nf_tables_commit_audit_alloc(struct list_head *adl,
> >         return 0;
> >  }
> >
> > +static void nf_tables_commit_free(struct list_head *adl)
> > +{
> > +       struct nft_audit_data *adp, *adn;
> > +
> > +       list_for_each_entry_safe(adp, adn, adl, list) {
> > +               list_del(&adp->list);
> > +               kfree(adp);
> > +       }
> > +}
> > +
> >  static void nf_tables_commit_audit_collect(struct list_head *adl,
> >                                            struct nft_table *table, u32 op)
> >  {
> > @@ -8508,6 +8518,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
> >                 ret = nf_tables_commit_audit_alloc(&adl, trans->ctx.table);
> >                 if (ret) {
> >                         nf_tables_commit_chain_prepare_cancel(net);
> > +                       nf_tables_commit_free(adl);
> >                         return ret;
> >                 }
> >                 if (trans->msg_type == NFT_MSG_NEWRULE ||
> > @@ -8517,6 +8528,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
> >                         ret = nf_tables_commit_chain_prepare(net, chain);
> >                         if (ret < 0) {
> >                                 nf_tables_commit_chain_prepare_cancel(net);
> > +                               nf_tables_commit_free(adl);
> >                                 return ret;
> >                         }
> >                 }
> > --
> > 2.25.1
> >
> > --
> > You received this message because you are subscribed to the Google Groups "syzkaller" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller/20210713094158.450434-1-mudongliangabcd%40gmail.com.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] audit: fix memory leak in nf_tables_commit
  2021-07-13 11:51   ` Dongliang Mu
@ 2021-07-13 12:04     ` Lukas Bulwahn
  0 siblings, 0 replies; 4+ messages in thread
From: Lukas Bulwahn @ 2021-07-13 12:04 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, Jakub Kicinski, Paul Moore, Richard Guy Briggs,
	syzbot, netfilter-devel, coreteam, Netdev,
	Linux Kernel Mailing List

On Tue, Jul 13, 2021 at 1:52 PM Dongliang Mu <mudongliangabcd@gmail.com> wrote:
>
> On Tue, Jul 13, 2021 at 7:47 PM Lukas Bulwahn <lukas.bulwahn@gmail.com> wrote:
> >
> > On Tue, Jul 13, 2021 at 11:42 AM Dongliang Mu <mudongliangabcd@gmail.com> wrote:
> > >

> > >
> > > Reported-by: syzbot <syzkaller@googlegroups.com>
> >
> > As far as I see, the more default way is to reference to syzbot by:
> >
> > Reported-by: syzbot+[[20-letter hex reference]]@syzkaller.appspotmail.com
> >
>
> Hi Lukas,
>
> this bug is not listed on the syzbot dashboard. I found this bug by
> setting up a local syzkaller instance, so I only list syzbot other
> than concrete syzbot id.
>

I see. Thanks for your explanation.

Lukas

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-13 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13  9:41 [PATCH] audit: fix memory leak in nf_tables_commit Dongliang Mu
2021-07-13 11:47 ` Lukas Bulwahn
2021-07-13 11:51   ` Dongliang Mu
2021-07-13 12:04     ` Lukas Bulwahn

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).