Blame SOURCES/0009-netlink-Fix-leaks-in-netlink_parse_cmp.patch

3730f4
From 6ecccc872b9cbed921af10e32d1a628eb6a74c01 Mon Sep 17 00:00:00 2001
3730f4
From: Phil Sutter <psutter@redhat.com>
3730f4
Date: Mon, 27 Jan 2020 16:11:41 +0100
3730f4
Subject: [PATCH] netlink: Fix leaks in netlink_parse_cmp()
3730f4
3730f4
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1793030
3730f4
Upstream Status: nftables commit e957bd9f10d5e
3730f4
3730f4
commit e957bd9f10d5e36671a0b0398e2037fc6201275b
3730f4
Author: Phil Sutter <phil@nwl.cc>
3730f4
Date:   Mon Jan 20 14:48:26 2020 +0100
3730f4
3730f4
    netlink: Fix leaks in netlink_parse_cmp()
3730f4
3730f4
    This fixes several problems at once:
3730f4
3730f4
    * Err path would leak expr 'right' in two places and 'left' in one.
3730f4
    * Concat case would leak 'right' by overwriting the pointer. Introduce a
3730f4
      temporary variable to hold the new pointer.
3730f4
3730f4
    Fixes: 6377380bc265f ("netlink_delinearize: handle relational and lookup concat expressions")
3730f4
    Signed-off-by: Phil Sutter <phil@nwl.cc>
3730f4
    Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
3730f4
---
3730f4
 src/netlink_delinearize.c | 19 +++++++++++++------
3730f4
 1 file changed, 13 insertions(+), 6 deletions(-)
3730f4
3730f4
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
3730f4
index 06a0312..88dbd5a 100644
3730f4
--- a/src/netlink_delinearize.c
3730f4
+++ b/src/netlink_delinearize.c
3730f4
@@ -274,7 +274,7 @@ static void netlink_parse_cmp(struct netlink_parse_ctx *ctx,
3730f4
 {
3730f4
 	struct nft_data_delinearize nld;
3730f4
 	enum nft_registers sreg;
3730f4
-	struct expr *expr, *left, *right;
3730f4
+	struct expr *expr, *left, *right, *tmp;
3730f4
 	enum ops op;
3730f4
 
3730f4
 	sreg = netlink_parse_register(nle, NFTNL_EXPR_CMP_SREG);
3730f4
@@ -291,19 +291,26 @@ static void netlink_parse_cmp(struct netlink_parse_ctx *ctx,
3730f4
 
3730f4
 	if (left->len > right->len &&
3730f4
 	    expr_basetype(left) != &string_type) {
3730f4
-		return netlink_error(ctx, loc, "Relational expression size mismatch");
3730f4
+		netlink_error(ctx, loc, "Relational expression size mismatch");
3730f4
+		goto err_free;
3730f4
 	} else if (left->len > 0 && left->len < right->len) {
3730f4
 		expr_free(left);
3730f4
 		left = netlink_parse_concat_expr(ctx, loc, sreg, right->len);
3730f4
 		if (left == NULL)
3730f4
-			return;
3730f4
-		right = netlink_parse_concat_data(ctx, loc, sreg, right->len, right);
3730f4
-		if (right == NULL)
3730f4
-			return;
3730f4
+			goto err_free;
3730f4
+		tmp = netlink_parse_concat_data(ctx, loc, sreg, right->len, right);
3730f4
+		if (tmp == NULL)
3730f4
+			goto err_free;
3730f4
+		expr_free(right);
3730f4
+		right = tmp;
3730f4
 	}
3730f4
 
3730f4
 	expr = relational_expr_alloc(loc, op, left, right);
3730f4
 	ctx->stmt = expr_stmt_alloc(loc, expr);
3730f4
+	return;
3730f4
+err_free:
3730f4
+	expr_free(left);
3730f4
+	expr_free(right);
3730f4
 }
3730f4
 
3730f4
 static void netlink_parse_lookup(struct netlink_parse_ctx *ctx,
3730f4
-- 
252916
2.31.1
3730f4