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