Blame SOURCES/0023-netlink-fix-use-after-free-in-netlink_run_handler.patch

3259a4
From ef1675823905ff09cb5e551700a124d0133648b7 Mon Sep 17 00:00:00 2001
3259a4
From: Michal Kubecek <mkubecek@suse.cz>
3259a4
Date: Mon, 9 Nov 2020 13:30:54 +0100
3259a4
Subject: [PATCH 23/26] netlink: fix use after free in netlink_run_handler()
3259a4
3259a4
Valgrind detected use after free in netlink_run_handler(): some members of
3259a4
struct nl_context are accessed after the netlink context is freed by
3259a4
netlink_done(). Use local variables to store the two flags and check them
3259a4
instead.
3259a4
3259a4
Fixes: 6c19c0d559c8 ("netlink: use genetlink ops information to decide about fallback")
3259a4
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
3259a4
(cherry picked from commit 29b38ea218bd978d1950e12cc24da98215a1eeef)
3259a4
---
3259a4
 netlink/netlink.c | 10 +++++++---
3259a4
 1 file changed, 7 insertions(+), 3 deletions(-)
3259a4
3259a4
diff --git a/netlink/netlink.c b/netlink/netlink.c
3259a4
index 86dc1efdf5ce..2a12bb8b1759 100644
3259a4
--- a/netlink/netlink.c
3259a4
+++ b/netlink/netlink.c
3259a4
@@ -303,6 +303,7 @@ void netlink_run_handler(struct cmd_context *ctx, nl_func_t nlfunc,
3259a4
 			 bool no_fallback)
3259a4
 {
3259a4
 	bool wildcard = ctx->devname && !strcmp(ctx->devname, WILDCARD_DEVNAME);
3259a4
+	bool wildcard_unsupported, ioctl_fallback;
3259a4
 	struct nl_context *nlctx;
3259a4
 	const char *reason;
3259a4
 	int ret;
3259a4
@@ -324,14 +325,17 @@ void netlink_run_handler(struct cmd_context *ctx, nl_func_t nlfunc,
3259a4
 	nlctx = ctx->nlctx;
3259a4
 
3259a4
 	ret = nlfunc(ctx);
3259a4
+	wildcard_unsupported = nlctx->wildcard_unsupported;
3259a4
+	ioctl_fallback = nlctx->ioctl_fallback;
3259a4
 	netlink_done(ctx);
3259a4
-	if (no_fallback || ret != -EOPNOTSUPP || !nlctx->ioctl_fallback) {
3259a4
-		if (nlctx->wildcard_unsupported)
3259a4
+
3259a4
+	if (no_fallback || ret != -EOPNOTSUPP || !ioctl_fallback) {
3259a4
+		if (wildcard_unsupported)
3259a4
 			fprintf(stderr, "%s\n",
3259a4
 				"subcommand does not support wildcard dump");
3259a4
 		exit(ret >= 0 ? ret : 1);
3259a4
 	}
3259a4
-	if (nlctx->wildcard_unsupported)
3259a4
+	if (wildcard_unsupported)
3259a4
 		reason = "subcommand does not support wildcard dump";
3259a4
 	else
3259a4
 		reason = "kernel netlink support for subcommand missing";
3259a4
-- 
3259a4
2.26.2
3259a4