From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft 4/6] parser: reject zero-length interface names
Date: Tue, 20 Jun 2023 18:02:36 +0200 [thread overview]
Message-ID: <ZJHNnJVsLZL3AmH3@calendula> (raw)
In-Reply-To: <20230619204306.11785-5-fw@strlen.de>
On Mon, Jun 19, 2023 at 10:43:04PM +0200, Florian Westphal wrote:
> device "" results in an assertion during evaluation.
> Before:
> nft: expression.c:426: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
> After:
> zero_length_devicename_assert:3:42-49: Error: you cannot set an empty interface name
> type filter hook ingress device""lo" priority -1
> ^^^^^^^^
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> src/parser_bison.y | 36 ++++++++++++++++---
> .../nft-f/zero_length_devicename_assert | 5 +++
> 2 files changed, 36 insertions(+), 5 deletions(-)
> create mode 100644 tests/shell/testcases/bogons/nft-f/zero_length_devicename_assert
>
> diff --git a/src/parser_bison.y b/src/parser_bison.y
> index f5f6bf04d064..d5a2f85387cb 100644
> --- a/src/parser_bison.y
> +++ b/src/parser_bison.y
> @@ -144,6 +144,33 @@ static bool already_set(const void *attr, const struct location *loc,
> return true;
> }
>
> +static struct expr* ifname_expr_alloc(const struct location *location,
Nitpick:
static struct expr *ifname_expr_alloc(const struct location *location,
^
> + struct list_head *queue,
> + const char *name)
> +{
> + unsigned int length = strlen(name);
> + struct expr *expr;
> +
> + if (length == 0) {
> + xfree(name);
> + erec_queue(error(location, "empty interface name"), queue);
> + return NULL;
> + }
> +
> + if (length > 16) {
IFNAMSIZ instead of 16?
> + xfree(name);
> + erec_queue(error(location, "interface name too long"), queue);
> + return NULL;
> + }
> +
> + expr = constant_expr_alloc(location, &ifname_type, BYTEORDER_HOST_ENDIAN,
> + length * BITS_PER_BYTE, name);
> +
> + xfree(name);
> +
> + return expr;
> +}
> +
> #define YYLLOC_DEFAULT(Current, Rhs, N) location_update(&Current, Rhs, N)
>
> #define symbol_value(loc, str) \
> @@ -2664,12 +2691,11 @@ int_num : NUM { $$ = $1; }
>
> dev_spec : DEVICE string
> {
> - struct expr *expr;
> + struct expr *expr = ifname_expr_alloc(&@$, state->msgs, $2);
> +
> + if (!expr)
> + YYERROR;
>
> - expr = constant_expr_alloc(&@$, &string_type,
> - BYTEORDER_HOST_ENDIAN,
> - strlen($2) * BITS_PER_BYTE, $2);
> - xfree($2);
> $$ = compound_expr_alloc(&@$, EXPR_LIST);
> compound_expr_add($$, expr);
>
> diff --git a/tests/shell/testcases/bogons/nft-f/zero_length_devicename_assert b/tests/shell/testcases/bogons/nft-f/zero_length_devicename_assert
> new file mode 100644
> index 000000000000..84f330730fce
> --- /dev/null
> +++ b/tests/shell/testcases/bogons/nft-f/zero_length_devicename_assert
> @@ -0,0 +1,5 @@
> +table ip x {
> + chain Main_Ingress1 {
> + type filter hook ingress device""lo" priority -1
> + }
> +}
> --
> 2.39.3
>
next prev parent reply other threads:[~2023-06-20 16:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 20:43 [PATCH nft 0/6] Misc parser fixes Florian Westphal
2023-06-19 20:43 ` [PATCH nft 1/6] json: dccp: remove erroneous const qualifier Florian Westphal
2023-06-19 20:43 ` [PATCH nft 2/6] evaluate: do not abort when prefix map has non-map element Florian Westphal
2023-06-19 20:43 ` [PATCH nft 3/6] parser: don't assert on scope underflows Florian Westphal
2023-06-19 20:43 ` [PATCH nft 4/6] parser: reject zero-length interface names Florian Westphal
2023-06-20 16:02 ` Pablo Neira Ayuso [this message]
2023-06-19 20:43 ` [PATCH nft 5/6] parser: reject zero-length interface names in flowtables Florian Westphal
2023-06-19 20:43 ` [PATCH nft 6/6] ct timeout: fix 'list object x' vs. 'list objects in table' confusion Florian Westphal
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=ZJHNnJVsLZL3AmH3@calendula \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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).