diff mbox series

[nf] netfilter/xt_u32: validate user space input

Message ID 20230828132107.18376-1-wander@redhat.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [nf] netfilter/xt_u32: validate user space input | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Wander Lairson Costa Aug. 28, 2023, 1:21 p.m. UTC
The xt_u32 module doesn't validate the fields in the xt_u32 structure.
An attacker may take advantage of this to trigger an OOB read by setting
the size fields with a value beyond the arrays boundaries.

Add a checkentry function to validate the structure.

This was originally reported by the ZDI project (ZDI-CAN-18408).

Fixes: 1b50b8a371e9 ("[NETFILTER]: Add u32 match")
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
 net/netfilter/xt_u32.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Wander Lairson Costa Aug. 28, 2023, 1:25 p.m. UTC | #1
+stable as I forgot to add it in the Cc section.

On Mon, Aug 28, 2023 at 10:21 AM Wander Lairson Costa <wander@redhat.com> wrote:
>
> The xt_u32 module doesn't validate the fields in the xt_u32 structure.
> An attacker may take advantage of this to trigger an OOB read by setting
> the size fields with a value beyond the arrays boundaries.
>
> Add a checkentry function to validate the structure.
>
> This was originally reported by the ZDI project (ZDI-CAN-18408).
>
> Fixes: 1b50b8a371e9 ("[NETFILTER]: Add u32 match")
> Signed-off-by: Wander Lairson Costa <wander@redhat.com>
> ---
>  net/netfilter/xt_u32.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/net/netfilter/xt_u32.c b/net/netfilter/xt_u32.c
> index 177b40d08098..117d4615d668 100644
> --- a/net/netfilter/xt_u32.c
> +++ b/net/netfilter/xt_u32.c
> @@ -96,11 +96,32 @@ static bool u32_mt(const struct sk_buff *skb, struct xt_action_param *par)
>         return ret ^ data->invert;
>  }
>
> +static int u32_mt_checkentry(const struct xt_mtchk_param *par)
> +{
> +       const struct xt_u32 *data = par->matchinfo;
> +       const struct xt_u32_test *ct;
> +       unsigned int i;
> +
> +       if (data->ntests > ARRAY_SIZE(data->tests))
> +               return -EINVAL;
> +
> +       for (i = 0; i < data->ntests; ++i) {
> +               ct = &data->tests[i];
> +
> +               if (ct->nnums > ARRAY_SIZE(ct->location) ||
> +                   ct->nvalues > ARRAY_SIZE(ct->value))
> +                       return -EINVAL;
> +       }
> +
> +       return 0;
> +}
> +
>  static struct xt_match xt_u32_mt_reg __read_mostly = {
>         .name       = "u32",
>         .revision   = 0,
>         .family     = NFPROTO_UNSPEC,
>         .match      = u32_mt,
> +       .checkentry = u32_mt_checkentry,
>         .matchsize  = sizeof(struct xt_u32),
>         .me         = THIS_MODULE,
>  };
> --
> 2.41.0
>
Pablo Neira Ayuso Aug. 30, 2023, 3:18 p.m. UTC | #2
On Mon, Aug 28, 2023 at 10:21:07AM -0300, Wander Lairson Costa wrote:
> The xt_u32 module doesn't validate the fields in the xt_u32 structure.
> An attacker may take advantage of this to trigger an OOB read by setting
> the size fields with a value beyond the arrays boundaries.
> 
> Add a checkentry function to validate the structure.
> 
> This was originally reported by the ZDI project (ZDI-CAN-18408).

Applied to nf, thanks
diff mbox series

Patch

diff --git a/net/netfilter/xt_u32.c b/net/netfilter/xt_u32.c
index 177b40d08098..117d4615d668 100644
--- a/net/netfilter/xt_u32.c
+++ b/net/netfilter/xt_u32.c
@@ -96,11 +96,32 @@  static bool u32_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	return ret ^ data->invert;
 }
 
+static int u32_mt_checkentry(const struct xt_mtchk_param *par)
+{
+	const struct xt_u32 *data = par->matchinfo;
+	const struct xt_u32_test *ct;
+	unsigned int i;
+
+	if (data->ntests > ARRAY_SIZE(data->tests))
+		return -EINVAL;
+
+	for (i = 0; i < data->ntests; ++i) {
+		ct = &data->tests[i];
+
+		if (ct->nnums > ARRAY_SIZE(ct->location) ||
+		    ct->nvalues > ARRAY_SIZE(ct->value))
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
 static struct xt_match xt_u32_mt_reg __read_mostly = {
 	.name       = "u32",
 	.revision   = 0,
 	.family     = NFPROTO_UNSPEC,
 	.match      = u32_mt,
+	.checkentry = u32_mt_checkentry,
 	.matchsize  = sizeof(struct xt_u32),
 	.me         = THIS_MODULE,
 };