Skip to contentSkip to conversation

libnftables: fix memleak when EOPNOTSUPP

PATCH New Pablo Neira Ayuso 1 participant 1 message Jun 23, 2021 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 libnftables: fix memleak when EOPNOTSUPP

The err->seqnum == batch_seqnum case results in a memleak of mnl_err objects under some scenarios such as nf_tables kernel support is not available or user runs the nft executable as non-root.

Fixes f930cc500318 ("nftables: fix supression of "permission denied" errors")
---
 src/libnftables.c | 6 ++++++
 1 file changed, 6 insertions(+)
src/libnftables.c +6 -0
index e080eb032770..2378f7dd76fb 100644
@@ -89,6 +89,12 @@ static int nft_netlink(struct nft_ctx *nft,
 			last_seqnum = UINT32_MAX;
 		}
 	}
+	/* nfnetlink uses the first netlink message header in the batch whose
+	 * sequence number is zero to report for EOPNOTSUPP and EPERM errors in
+	 * some scenarios. Now it is safe to release here.
+	 */
+	list_for_each_entry_safe(err, tmp, &err_list, head)
+		mnl_err_list_free(err);
 out:
 	mnl_batch_reset(ctx.batch);
 	return ret;
Signature · 1 line
2.30.2