|
|
86e59a1 |
From f667f577e6d29e62f55cdc4e1e39414913bf7c4c Mon Sep 17 00:00:00 2001
|
|
|
86e59a1 |
From: Phil Sutter <phil@nwl.cc>
|
|
|
86e59a1 |
Date: Tue, 28 Nov 2023 20:21:49 +0100
|
|
|
86e59a1 |
Subject: [PATCH] libxtables: xtoptions: Fix for non-CIDR-compatible hostmasks
|
|
|
86e59a1 |
|
|
|
86e59a1 |
In order to parse the mask, xtopt_parse_hostmask() calls
|
|
|
86e59a1 |
xtopt_parse_plenmask() thereby limiting netmask support to prefix
|
|
|
86e59a1 |
lengths (alternatively specified in IP address notation).
|
|
|
86e59a1 |
|
|
|
86e59a1 |
In order to lift this impractical restriction, make
|
|
|
86e59a1 |
xtopt_parse_plenmask() aware of the fact that xtopt_parse_plen() may
|
|
|
86e59a1 |
fall back to xtopt_parse_mask() which correctly initializes val.hmask
|
|
|
86e59a1 |
itself and indicates non-CIDR-compatible masks by setting val.hlen to
|
|
|
86e59a1 |
-1.
|
|
|
86e59a1 |
|
|
|
86e59a1 |
So in order to support these odd masks, it is sufficient for
|
|
|
86e59a1 |
xtopt_parse_plenmask() to skip its mask building from val.hlen value and
|
|
|
86e59a1 |
take whatever val.hmask contains.
|
|
|
86e59a1 |
|
|
|
86e59a1 |
Fixes: 66266abd17adc ("libxtables: XTTYPE_HOSTMASK support")
|
|
|
86e59a1 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
86e59a1 |
(cherry picked from commit 41139aee5e53304182a25f1e573f034b313f7232)
|
|
|
86e59a1 |
---
|
|
|
86e59a1 |
libxtables/xtoptions.c | 5 +++++
|
|
|
86e59a1 |
1 file changed, 5 insertions(+)
|
|
|
86e59a1 |
|
|
|
86e59a1 |
diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c
|
|
|
86e59a1 |
index b16bbfbe32311..d91a78f470eda 100644
|
|
|
86e59a1 |
--- a/libxtables/xtoptions.c
|
|
|
86e59a1 |
+++ b/libxtables/xtoptions.c
|
|
|
86e59a1 |
@@ -711,6 +711,10 @@ static void xtopt_parse_plenmask(struct xt_option_call *cb)
|
|
|
86e59a1 |
|
|
|
86e59a1 |
xtopt_parse_plen(cb);
|
|
|
86e59a1 |
|
|
|
86e59a1 |
+ /* may not be convertible to CIDR notation */
|
|
|
86e59a1 |
+ if (cb->val.hlen == (uint8_t)-1)
|
|
|
86e59a1 |
+ goto out_put;
|
|
|
86e59a1 |
+
|
|
|
86e59a1 |
memset(mask, 0xFF, sizeof(union nf_inet_addr));
|
|
|
86e59a1 |
/* This shifting is AF-independent. */
|
|
|
86e59a1 |
if (cb->val.hlen == 0) {
|
|
|
86e59a1 |
@@ -731,6 +735,7 @@ static void xtopt_parse_plenmask(struct xt_option_call *cb)
|
|
|
86e59a1 |
mask[1] = htonl(mask[1]);
|
|
|
86e59a1 |
mask[2] = htonl(mask[2]);
|
|
|
86e59a1 |
mask[3] = htonl(mask[3]);
|
|
|
86e59a1 |
+out_put:
|
|
|
86e59a1 |
if (entry->flags & XTOPT_PUT)
|
|
|
86e59a1 |
memcpy(XTOPT_MKPTR(cb), mask, sizeof(union nf_inet_addr));
|
|
|
86e59a1 |
}
|