All of lore.kernel.org
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: icejl <icejl0001@gmail.com>,
	kadlec@netfilter.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] netfilter: nfnetlink: fix uninitialized local variable
Date: Thu, 15 Aug 2024 02:55:19 -0700	[thread overview]
Message-ID: <Zr3Qh5FW7PsynJ4O@gmail.com> (raw)
In-Reply-To: <Zr3LQ4hGx-sN5T8Q@calendula>

Hello Pablo,

On Thu, Aug 15, 2024 at 11:32:51AM +0200, Pablo Neira Ayuso wrote:
> On Thu, Aug 15, 2024 at 02:04:04AM -0700, Breno Leitao wrote:
> > On Thu, Aug 15, 2024 at 04:27:33PM +0800, icejl wrote:
> > > In the nfnetlink_rcv_batch function, an uninitialized local variable
> > > extack is used, which results in using random stack data as a pointer.
> > > This pointer is then used to access the data it points to and return
> > > it as the request status, leading to an information leak. If the stack
> > > data happens to be an invalid pointer, it can cause a pointer access
> > > exception, triggering a kernel crash.
> > > 
> > > Signed-off-by: icejl <icejl0001@gmail.com>
> > > ---
> > >  net/netfilter/nfnetlink.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
> > > index 4abf660c7baf..b29b281f4b2c 100644
> > > --- a/net/netfilter/nfnetlink.c
> > > +++ b/net/netfilter/nfnetlink.c
> > > @@ -427,6 +427,7 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
> > >  
> > >  	nfnl_unlock(subsys_id);
> > >  
> > > +	memset(&extack, 0, sizeof(extack));
> > >  	if (nlh->nlmsg_flags & NLM_F_ACK)
> > >  		nfnl_err_add(&err_list, nlh, 0, &extack);
> > 
> > There is a memset later in that function , inside the 
> > `while (skb->len >= nlmsg_total_size(0))` loop. Should that one be
> > removed?
> 
> no, the batch contains a series of netlink message, each of them needs
> a fresh extack area which is zeroed.

Sorry, this is a bit unclear to me. This is the code I see in
netnext/main:


	memset(&extack, 0, sizeof(extack));   // YOUR CHANGE

        if (nlh->nlmsg_flags & NLM_F_ACK)
                nfnl_err_add(&err_list, nlh, 0, &extack);

        while (skb->len >= nlmsg_total_size(0)) {
                int msglen, type;

                if (fatal_signal_pending(current)) {
                        nfnl_err_reset(&err_list);
                        err = -EINTR;
                        status = NFNL_BATCH_FAILURE;
                        goto done;
                }

->              memset(&extack, 0, sizeof(extack));


nfnl_err_add() does not change extack. Tht said, the second memset (last
line in the snippet above), seems useless, doesn't it?

Thanks for the quick reply,
--breno


  reply	other threads:[~2024-08-15  9:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-15  8:27 [PATCH] netfilter: nfnetlink: fix uninitialized local variable icejl
2024-08-15  8:32 ` Pablo Neira Ayuso
2024-08-15  8:55   ` Pablo Neira Ayuso
2024-08-15  9:04 ` Breno Leitao
2024-08-15  9:32   ` Pablo Neira Ayuso
2024-08-15  9:55     ` Breno Leitao [this message]
2024-08-15 10:03       ` Pablo Neira Ayuso

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=Zr3Qh5FW7PsynJ4O@gmail.com \
    --to=leitao@debian.org \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=icejl0001@gmail.com \
    --cc=kadlec@netfilter.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.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 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.