From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Davide Ornaghi <d.ornaghi97@gmail.com>
Cc: netfilter-devel@vger.kernel.org, kadlec@netfilter.org,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, fw@strlen.de
Subject: Re: [PATCH nft] Check for NULL netlink attributes
Date: Wed, 5 Jun 2024 07:52:04 +0200 [thread overview]
Message-ID: <Zl_9BPZ8sKK9PzR9@calendula> (raw)
In-Reply-To: <CAHH-0UdpvNzWOD9Ef1KHF=hYsoyYGi0K=okkyJormxv=-deNbQ@mail.gmail.com>
Hi Davide,
I suggest this patch subject:
nf_tables: nft_inner: validate mandatory meta and payload netlink attributes
On Tue, Jun 04, 2024 at 11:36:21PM +0200, Davide Ornaghi wrote:
> Payload and meta nftables exprs can be embedded into inner exprs via
> nft_expr_inner_parse, which doesn't check for NULL netlink attributes,
> unlike other exprs passing through select_ops.
> Add the missing checks to nft_meta_inner_init and nft_payload_inner_init
> to prevent dereferencing NULL pointers and eventually causing UAF reads on commit_mutex.
I'd suggest this patch description:
"Check for mandatory netlink attributes in payload and meta expression
when used embedded from the inner expression, otherwise NULL pointer
dereference is possible if userspace."
And please add:
Fixes: a150d122b6bd ("netfilter: nft_meta: add inner match support")
Fixes: 3a07327d10a0 ("netfilter: nft_inner: support for inner tunnel header matching")
Thanks a lot for submitting your fix.
> Signed-off-by: Davide Ornaghi <d.ornaghi97@gmail.com>
> ---
> net/netfilter/nft_meta.c | 2 ++
> net/netfilter/nft_payload.c | 3 +++
> 2 files changed, 5 insertions(+)
>
> diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
> index ba0d3683a..e2893077b 100644
> --- a/net/netfilter/nft_meta.c
> +++ b/net/netfilter/nft_meta.c
> @@ -839,6 +839,8 @@ static int nft_meta_inner_init(const struct nft_ctx
> *ctx,
> struct nft_meta *priv = nft_expr_priv(expr);
> unsigned int len;
>
> + if (!tb[NFTA_META_KEY] || !tb[NFTA_META_DREG])
> + return -EINVAL;
> priv->key = ntohl(nla_get_be32(tb[NFTA_META_KEY]));
> switch (priv->key) {
> case NFT_META_PROTOCOL:
> diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
> index 0c43d748e..4c6f15ad0 100644
> --- a/net/netfilter/nft_payload.c
> +++ b/net/netfilter/nft_payload.c
> @@ -650,6 +650,9 @@ static int nft_payload_inner_init(const struct nft_ctx
> *ctx,
> struct nft_payload *priv = nft_expr_priv(expr);
> u32 base;
>
> + if (!tb[NFTA_PAYLOAD_BASE] || !tb[NFTA_PAYLOAD_OFFSET] ||
> + !tb[NFTA_PAYLOAD_LEN] || !tb[NFTA_PAYLOAD_DREG])
> + return -EINVAL;
> base = ntohl(nla_get_be32(tb[NFTA_PAYLOAD_BASE]));
> switch (base) {
> case NFT_PAYLOAD_TUN_HEADER:
> --
> 2.34.1
next parent reply other threads:[~2024-06-05 5:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAHH-0UdpvNzWOD9Ef1KHF=hYsoyYGi0K=okkyJormxv=-deNbQ@mail.gmail.com>
2024-06-05 5:52 ` Pablo Neira Ayuso [this message]
2024-06-04 21:40 [PATCH nft] Check for NULL netlink attributes Davide Ornaghi
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=Zl_9BPZ8sKK9PzR9@calendula \
--to=pablo@netfilter.org \
--cc=d.ornaghi97@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.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 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).