From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] mnl: handle singleton element in netdevice set
Date: Tue, 25 Apr 2023 16:54:07 +0200 [thread overview]
Message-ID: <20230425145407.2802-1-pablo@netfilter.org> (raw)
expr_evaluate_set() turns sets with singleton element into value,
nft_dev_add() expects a list of expression, so it crashes.
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1676
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/mnl.c | 46 +++++++++++++------
.../testcases/chains/0042chain_variable_0 | 4 ++
.../chains/dumps/0042chain_variable_0.nft | 4 ++
3 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/src/mnl.c b/src/mnl.c
index c590c9554e0c..5dcfd9a04c4b 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -720,31 +720,49 @@ err:
*/
struct nft_dev {
- const char *ifname;
- struct location *location;
+ const char *ifname;
+ const struct location *location;
};
-static struct nft_dev *nft_dev_array(const struct expr *dev_expr, int *num_devs)
+static void nft_dev_add(struct nft_dev *dev_array, const struct expr *expr, int i)
{
- struct nft_dev *dev_array;
unsigned int ifname_len;
char ifname[IFNAMSIZ];
+
+ ifname_len = div_round_up(expr->len, BITS_PER_BYTE);
+ memset(ifname, 0, sizeof(ifname));
+ mpz_export_data(ifname, expr->value, BYTEORDER_HOST_ENDIAN, ifname_len);
+ dev_array[i].ifname = xstrdup(ifname);
+ dev_array[i].location = &expr->location;
+}
+
+static struct nft_dev *nft_dev_array(const struct expr *dev_expr, int *num_devs)
+{
+ struct nft_dev *dev_array;
int i = 0, len = 1;
struct expr *expr;
- list_for_each_entry(expr, &dev_expr->expressions, list)
- len++;
+ switch (dev_expr->etype) {
+ case EXPR_SET:
+ case EXPR_LIST:
+ list_for_each_entry(expr, &dev_expr->expressions, list)
+ len++;
- dev_array = xmalloc(sizeof(struct nft_dev) * len);
+ dev_array = xmalloc(sizeof(struct nft_dev) * len);
- list_for_each_entry(expr, &dev_expr->expressions, list) {
- ifname_len = div_round_up(expr->len, BITS_PER_BYTE);
- memset(ifname, 0, sizeof(ifname));
- mpz_export_data(ifname, expr->value, BYTEORDER_HOST_ENDIAN,
- ifname_len);
- dev_array[i].ifname = xstrdup(ifname);
- dev_array[i].location = &expr->location;
+ list_for_each_entry(expr, &dev_expr->expressions, list) {
+ nft_dev_add(dev_array, expr, i);
+ i++;
+ }
+ break;
+ case EXPR_VALUE:
+ len++;
+ dev_array = xmalloc(sizeof(struct nft_dev) * len);
+ nft_dev_add(dev_array, dev_expr, i);
i++;
+ break;
+ default:
+ assert(0);
}
dev_array[i].ifname = NULL;
diff --git a/tests/shell/testcases/chains/0042chain_variable_0 b/tests/shell/testcases/chains/0042chain_variable_0
index 58535f76cc32..f71b04155e44 100755
--- a/tests/shell/testcases/chains/0042chain_variable_0
+++ b/tests/shell/testcases/chains/0042chain_variable_0
@@ -25,11 +25,15 @@ table netdev filter2 {
$NFT -f - <<< $EXPECTED
EXPECTED="define if_main = { lo, dummy0 }
+define lan_interfaces = { lo }
table netdev filter3 {
chain Main_Ingress3 {
type filter hook ingress devices = \$if_main priority -500; policy accept;
}
+ chain Main_Egress3 {
+ type filter hook egress devices = \$lan_interfaces priority -500; policy accept;
+ }
}"
$NFT -f - <<< $EXPECTED
diff --git a/tests/shell/testcases/chains/dumps/0042chain_variable_0.nft b/tests/shell/testcases/chains/dumps/0042chain_variable_0.nft
index 12931aadb39f..5ec230d0bcfa 100644
--- a/tests/shell/testcases/chains/dumps/0042chain_variable_0.nft
+++ b/tests/shell/testcases/chains/dumps/0042chain_variable_0.nft
@@ -12,4 +12,8 @@ table netdev filter3 {
chain Main_Ingress3 {
type filter hook ingress devices = { dummy0, lo } priority -500; policy accept;
}
+
+ chain Main_Egress3 {
+ type filter hook egress device "lo" priority -500; policy accept;
+ }
}
--
2.30.2
reply other threads:[~2023-04-25 14:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230425145407.2802-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--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