netlink: bogus concatenated set ranges with netlink message overrun
Pablo Neira Ayuso
maintainerPATCH 1/1 netlink: bogus concatenated set ranges with netlink message overrun
When building each component of the set element key, a late byteorder switch is performed to ensure that all components in the interval are represented in big endian, as required by the pipapo backend.
In case that the set element does not fit into the netlink message, the byteorder switch happens twice, leading to inserting an element with a bogus component with large sets, so instead:
"lo" . 00:11:22:33:44:55 . 10.1.2.3 comment "123456789012345678901234567890"
listing reports:
16777216 . 00:11:22:33:44:55 . 10.1.2.3 comment "123456789012345678901234567890"
Note that 16777216 is 0x1000000, which should instead be 0x00000001 to represent "lo" as u32.
Fix this by switching the value in a temporary variable and use it to set the set element key attribute in the netlink message.
Later, revisit this to perform this byteorder switch from evaluation step.
Add tests/shell unit to cover for this bug.
--- src/netlink.c | 19 +- .../shell/testcases/sets/concat_nlmsg_overrun | 734 ++++++++++++++++++ .../sets/dumps/concat_nlmsg_overrun.nft | 7 + 3 files changed, 755 insertions(+), 5 deletions(-) create mode 100755 tests/shell/testcases/sets/concat_nlmsg_overrun create mode 100644 tests/shell/testcases/sets/dumps/concat_nlmsg_overrun.nft
src/netlink.c +14 -5
@@ -268,6 +268,8 @@ static int __netlink_gen_concat_key(uint32_t flags, const struct expr *i, unsigned char *data) {struct expr *expr; +mpz_t value; +int ret;switch (i->etype) {case EXPR_RANGE :
@@ -276,9 +278,11 @@ static int __netlink_gen_concat_key(uint32_t flags, const struct expr *i,else expr = i->left; +mpz_init_set (value, expr->value); +if (expr_basetype (expr)->type ==TYPE_INTEGER && expr->byteorder ==BYTEORDER_HOST_ENDIAN ) -byteorder_switch_expr_value (expr->value, expr); +byteorder_switch_expr_value (value, expr); i = expr;break ;
@@ -299,22 +303,27 @@ static int __netlink_gen_concat_key(uint32_t flags, const struct expr *i, }return netlink_export_pad (data, i->prefix->value, i);case EXPR_VALUE : -/* Switch byteorder only once for singleton values when the set +mpz_init_set (value, i->value); + +/* Switch byteorder to big endian representation when the set * contains concatenation of intervals. */ -if (!(flags &EXPR_F_INTERVAL )) +if (!(flags & (EXPR_F_INTERVAL |EXPR_F_INTERVAL_END )))break ; expr = (struct expr *)i;if (expr_basetype (expr)->type ==TYPE_INTEGER && expr->byteorder ==BYTEORDER_HOST_ENDIAN ) -byteorder_switch_expr_value (expr->value, expr); +byteorder_switch_expr_value (value, expr);break ;default :BUG ("invalid expression type '%s' in set" ,expr_ops (i)->name); } -return netlink_export_pad (data, i->value, i); + ret =netlink_export_pad (data, value, i); +mpz_clear (value); + +return ret; } static void nft_data_memcpy(struct nft_data_linearize *nld,
tests/shell/testcases/sets/concat_nlmsg_overrun new file +734 -0
734 lines not on this page · raw message
tests/shell/testcases/sets/dumps/concat_nlmsg_overrun.nft new file +7 -0
@@ -0,0 +1,7 @@ +table ip filter { + set test_set { + type iface_index . ether_addr . ipv4_addr + flags interval + elements = { "lo" . 00:11:22:33:44:55 . 10.1.2.3 comment "123456789012345678901234567890" } + } +}
Signature · 1 line
2.30.2