netfilter: nf_tables: fix oob access
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: nf_tables: fix oob access
BUG: KASAN: slab-out-of-bounds in nf_tables_rule_destroy+0xf1/0x130 at addr ffff88006a4c35c8 Read of size 8 by task nft/1607
When we've destroyed last valid expr, nft_expr_next() returns an invalid expr. We must not dereference it unless it passes != nft_expr_last() check.
---
I dislike nft_expr_last() naming, it doesn't return last valid expression but an invalid address...
net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -2115,7 +2115,7 @@ static void nf_tables_rule_destroy(const struct nft_ctx *ctx,* is called on error from nf_tables_newrule(). */ expr =nft_expr_first (rule); -while (expr->ops && expr !=nft_expr_last (rule)) { +while (expr !=nft_expr_last (rule) && expr->ops) {nf_tables_expr_destroy (ctx, expr); expr =nft_expr_next (expr); }
Signature · 1 line
2.7.3
Pablo Neira Ayuso
maintainerQuoted 10 lines · Florian Westphal
BUG: KASAN: slab-out-of-bounds in nf_tables_rule_destroy+0xf1/0x130 at addr ffff88006a4c35c8 Read of size 8 by task nft/1607When we've destroyed last valid expr,
nft_expr_next()returns an invalid expr. We must not dereference it unless it passes !=nft_expr_last()check.Signed-off-by Florian Westphal <[email protected]>---
I dislikenft_expr_last()naming, it doesn't return last valid expression but an invalid address...
Sure, send a patch for this, or simply update this oneliner in v2, your call. Thanks.
Quoted 23 lines
net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/netfilter/nf_tables_api.c +1
-1@@ -2115,7 +2115,7 @@ static void nf_tables_rule_destroy(const struct nft_ctx *ctx,* is called on error from nf_tables_newrule(). */ expr =nft_expr_first (rule); -while (expr->ops && expr !=nft_expr_last (rule)) { +while (expr !=nft_expr_last (rule) && expr->ops) {nf_tables_expr_destroy (ctx, expr); expr =nft_expr_next (expr); }Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Florian Westphal
maintainerQuoted 7 lines · Pablo Neira Ayuso
Quoted 6 lines · Florian Westphal
BUG: KASAN: slab-out-of-bounds in nf_tables_rule_destroy+0xf1/0x130 at addr ffff88006a4c35c8 Read of size 8 by task nft/1607When we've destroyed last valid expr,
nft_expr_next()returns an invalid expr. We must not dereference it unless it passes !=nft_expr_last()check.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Florian Westphal <[email protected]>---
I dislikenft_expr_last()naming, it doesn't return last valid expression but an invalid address...Sure, send a patch for this, or simply update this oneliner in v2, your call. Thanks.
Ok, I will try to come up with a better name and send a patch once next opens again. (what about rename to nft_expr_end()?)