netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>,
	Florian Westphal <fw@strlen.de>,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] netfilter: nf_tables: prevent shift wrap in nft_chain_parse_hook()
Date: Fri, 5 Apr 2019 11:34:37 +0300	[thread overview]
Message-ID: <20190405083436.GT32613@kadam> (raw)
In-Reply-To: <20190402133038.GA18575@kadam>

On Tue, Apr 02, 2019 at 04:30:38PM +0300, Dan Carpenter wrote:
> I believe that "hook->num" can be up to UINT_MAX so the shift has to
> be unsigned or shifting more than 31 is undefined.  It's possible that
> this leads to array overflow in nf_tables_addchain():
> 
> 	ops->hook	= hook.type->hooks[ops->hooknum];
> 
> Fixes: fe19c04ca137 ("netfilter: nf_tables: remove nhooks field from struct nft_af_info")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  net/netfilter/nf_tables_api.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index ef7772e976cc..b6e48fe7c776 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -1545,7 +1545,7 @@ static int nft_chain_parse_hook(struct net *net,
>  		if (IS_ERR(type))
>  			return PTR_ERR(type);
>  	}
> -	if (!(type->hook_mask & (1 << hook->num)))
> +	if (!(type->hook_mask & (1U << hook->num)))

Ugh...  No this doesn't work.  It's still undefined behavoir even if we
make it unsigned.  It has to be:

	if (hook->num > 31 || !(type->hook_mask & (1 << hook->num)))

which seems like a slightly ugly magic number but it fixes the buffer
overflow.

regards,
dan carpenter


  reply	other threads:[~2019-04-05  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 13:30 [PATCH] netfilter: nf_tables: prevent shift wrap in nft_chain_parse_hook() Dan Carpenter
2019-04-05  8:34 ` Dan Carpenter [this message]
2019-04-05 10:01   ` Florian Westphal
2019-04-06  5:26 ` [PATCH v2] " Dan Carpenter
2019-04-13 12:58   ` 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=20190405083436.GT32613@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=coreteam@netfilter.org \
    --cc=fw@strlen.de \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --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 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).