evaluate: reject: remove unused expr function argument
Florian Westphal
maintainerPATCH 1/2 evaluate: reject: remove unused expr function argument
stmt_evaluate_reject passes cmd->expr argument but its never used.
--- src/evaluate.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
src/evaluate.c +10 -16
@@ -3624,8 +3624,7 @@ static int reject_payload_gen_dependency_family(struct eval_ctx *ctx,return 1 ; } -static int stmt_reject_gen_dependency (struct eval_ctx *ctx,struct stmt *stmt, -struct expr *expr) +static int stmt_reject_gen_dependency (struct eval_ctx *ctx,struct stmt *stmt) {struct expr *payload =NULL ;struct stmt *nstmt;
@@ -3705,8 +3704,7 @@ static int stmt_evaluate_reject_inet_family(struct eval_ctx *ctx,return 0 ; } -static int stmt_evaluate_reject_inet (struct eval_ctx *ctx,struct stmt *stmt, -struct expr *expr) +static int stmt_evaluate_reject_inet (struct eval_ctx *ctx,struct stmt *stmt) {struct proto_ctx *pctx =eval_proto_ctx (ctx);const struct proto_desc *desc;
@@ -3717,7 +3715,7 @@ static int stmt_evaluate_reject_inet(struct eval_ctx *ctx, struct stmt *stmt,return -1 ;if (stmt->reject.type ==NFT_REJECT_ICMPX_UNREACH )return 0 ; -if (stmt_reject_gen_dependency (ctx, stmt, expr) <0 ) +if (stmt_reject_gen_dependency (ctx, stmt) <0 )return -1 ;return 0 ; }
@@ -3772,8 +3770,7 @@ static int stmt_evaluate_reject_bridge_family(struct eval_ctx *ctx,return 0 ; } -static int stmt_evaluate_reject_bridge (struct eval_ctx *ctx,struct stmt *stmt, -struct expr *expr) +static int stmt_evaluate_reject_bridge (struct eval_ctx *ctx,struct stmt *stmt) {struct proto_ctx *pctx =eval_proto_ctx (ctx);const struct proto_desc *desc;
@@ -3789,13 +3786,12 @@ static int stmt_evaluate_reject_bridge(struct eval_ctx *ctx, struct stmt *stmt,return -1 ;if (stmt->reject.type ==NFT_REJECT_ICMPX_UNREACH )return 0 ; -if (stmt_reject_gen_dependency (ctx, stmt, expr) <0 ) +if (stmt_reject_gen_dependency (ctx, stmt) <0 )return -1 ;return 0 ; } -static int stmt_evaluate_reject_family (struct eval_ctx *ctx,struct stmt *stmt, -struct expr *expr) +static int stmt_evaluate_reject_family (struct eval_ctx *ctx,struct stmt *stmt) {struct proto_ctx *pctx =eval_proto_ctx (ctx);
@@ -3806,7 +3802,7 @@ static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt,case NFPROTO_IPV6 :switch (stmt->reject.type) {case NFT_REJECT_TCP_RST : -if (stmt_reject_gen_dependency (ctx, stmt, expr) <0 ) +if (stmt_reject_gen_dependency (ctx, stmt) <0 )return -1 ;break ;case NFT_REJECT_ICMPX_UNREACH :
@@ -3821,11 +3817,11 @@ static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt,break ;case NFPROTO_BRIDGE :case NFPROTO_NETDEV : -if (stmt_evaluate_reject_bridge (ctx, stmt, expr) <0 ) +if (stmt_evaluate_reject_bridge (ctx, stmt) <0 )return -1 ;break ;case NFPROTO_INET : -if (stmt_evaluate_reject_inet (ctx, stmt, expr) <0 ) +if (stmt_evaluate_reject_inet (ctx, stmt) <0 )return -1 ;break ; }
@@ -3958,8 +3954,6 @@ static int stmt_evaluate_reset(struct eval_ctx *ctx, struct stmt *stmt)static int stmt_evaluate_reject (struct eval_ctx *ctx,struct stmt *stmt) { -struct expr *expr = ctx->cmd->expr; -if (stmt->reject.icmp_code <0 ) {if (stmt_evaluate_reject_default (ctx, stmt) <0 )return -1 ;
@@ -3971,7 +3965,7 @@ static int stmt_evaluate_reject(struct eval_ctx *ctx, struct stmt *stmt)return -1 ; } -return stmt_evaluate_reject_family (ctx, stmt, expr); +return stmt_evaluate_reject_family (ctx, stmt); }static int nat_evaluate_family (struct eval_ctx *ctx,struct stmt *stmt)
Signature · 1 line
2.49.0
Florian Westphal
maintainerPATCH 2/2 evaluate: fix crash when generating reject statement error
After patch, this gets rejected with:
internal:0:0-0: Error: conflicting protocols specified: ip vs ip6
Without patch, we crash with a NULL dereference: we cannot use reject.expr->location unconditionally.
--- src/evaluate.c | 16 ++++++++-- .../reject_stmt_with_no_expression_crash | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-j-f/reject_stmt_with_no_expression_crash
src/evaluate.c +14 -2
@@ -3791,6 +3791,18 @@ static int stmt_evaluate_reject_bridge(struct eval_ctx *ctx, struct stmt *stmt)return 0 ; } +static int stmt_reject_error (struct eval_ctx *ctx, +const struct stmt *stmt, +const char *msg) +{ +struct expr *e = stmt->reject.expr; + +if (e) +return stmt_binary_error (ctx, e, stmt,"%s" , msg); + +return stmt_error (ctx, stmt,"%s" , msg); +} +static int stmt_evaluate_reject_family (struct eval_ctx *ctx,struct stmt *stmt) {struct proto_ctx *pctx =eval_proto_ctx (ctx);
@@ -3806,12 +3818,12 @@ static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt)return -1 ;break ;case NFT_REJECT_ICMPX_UNREACH : -return stmt_binary_error (ctx, stmt->reject.expr, stmt, +return stmt_reject_error (ctx, stmt,"abstracted ICMP unreachable not supported" );case NFT_REJECT_ICMP_UNREACH :if (stmt->reject.family == pctx->family)break ; -return stmt_binary_error (ctx, stmt->reject.expr, stmt, +return stmt_reject_error (ctx, stmt,"conflicting protocols specified: ip vs ip6" ); }break ;
tests/shell/testcases/bogons/nft-j-f/reject_stmt_with_no_expression_crash new file +32 -0
@@ -0,0 +1,32 @@ +{ + "nftables": [ + { + "table": { "family": "ip", "name": "x", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "x", + "name": "c", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "x", + "chain": "c", + "expr": [ + { + "reject": { + "type": "icmpv6", + "exprlimit": "port-unreachable" + } + } + ] + } + } + ] +}
Signature · 1 line
2.49.0
Re: [PATCH nft 2/2] evaluate: fix crash when generating reject statement error
Quoted 7 lines · Florian Westphal
After patch, this gets rejected with:
internal:0:0-0: Error: conflicting protocols specified: ip vs ip6Without patch, we crash with a NULL dereference: we cannot use
reject.expr->locationunconditionally.Signed-off-by Florian Westphal <[email protected]>
Thanks!
Quoted 86 lines
--- src/evaluate.c | 16 ++++++++-- .../reject_stmt_with_no_expression_crash | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-j-f/reject_stmt_with_no_expression_crashsrc/evaluate.c +14
-2@@ -3791,6 +3791,18 @@ static int stmt_evaluate_reject_bridge(struct eval_ctx *ctx, struct stmt *stmt)return 0 ; } +static int stmt_reject_error (struct eval_ctx *ctx, +const struct stmt *stmt, +const char *msg) +{ +struct expr *e = stmt->reject.expr; + +if (e) +return stmt_binary_error (ctx, e, stmt,"%s" , msg); + +return stmt_error (ctx, stmt,"%s" , msg); +} +static int stmt_evaluate_reject_family (struct eval_ctx *ctx,struct stmt *stmt) {struct proto_ctx *pctx =eval_proto_ctx (ctx);@@ -3806,12 +3818,12 @@ static int stmt_evaluate_reject_family(struct eval_ctx *ctx, struct stmt *stmt)return -1 ;break ;case NFT_REJECT_ICMPX_UNREACH : -return stmt_binary_error (ctx, stmt->reject.expr, stmt, +return stmt_reject_error (ctx, stmt,"abstracted ICMP unreachable not supported" );case NFT_REJECT_ICMP_UNREACH :if (stmt->reject.family == pctx->family)break ; -return stmt_binary_error (ctx, stmt->reject.expr, stmt, +return stmt_reject_error (ctx, stmt,"conflicting protocols specified: ip vs ip6" ); }break ;tests/shell/testcases/bogons/nft-j-f/reject_stmt_with_no_expression_crash new file +32
-0@@ -0,0 +1,32 @@ +{ + "nftables": [ + { + "table": { "family": "ip", "name": "x", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "x", + "name": "c", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "x", + "chain": "c", + "expr": [ + { + "reject": { + "type": "icmpv6", + "exprlimit": "port-unreachable" + } + } + ] + } + } + ] +}Signature · 1 line
2.49.0
Quoted 3 lines · Florian Westphal
stmt_evaluate_rejectpassescmd->exprargument but its never used.Signed-off-by Florian Westphal <[email protected]>
Thanks!