dnsmasq/SOURCES/dnsmasq-2.87-CVE-2022-0934.patch

173 lines
6.5 KiB
Diff
Raw Normal View History

2023-04-04 08:52:53 +00:00
From 471cd540e755d2a5e92b4e8cd2ab2027beaba449 Mon Sep 17 00:00:00 2001
From: Simon Kelley <simon@thekelleys.org.uk>
Date: Thu, 31 Mar 2022 21:35:20 +0100
Subject: [PATCH] Fix write-after-free error in DHCPv6 code. CVE-2022-0934
refers.
2022-11-08 06:48:29 +00:00
---
2023-04-04 08:52:53 +00:00
src/rfc3315.c | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
2022-11-08 06:48:29 +00:00
2023-04-04 08:52:53 +00:00
diff --git a/src/rfc3315.c b/src/rfc3315.c
index 554b1fe..bc77fbf 100644
--- a/src/rfc3315.c
+++ b/src/rfc3315.c
@@ -36,9 +36,9 @@ struct state {
2022-11-08 06:48:29 +00:00
#endif
2023-04-04 08:52:53 +00:00
};
2022-11-08 06:48:29 +00:00
2023-04-04 08:52:53 +00:00
-static int dhcp6_maybe_relay(struct state *state, void *inbuff, size_t sz,
+static int dhcp6_maybe_relay(struct state *state, unsigned char *inbuff, size_t sz,
struct in6_addr *client_addr, int is_unicast, time_t now);
-static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_t sz, int is_unicast, time_t now);
+static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbuff, size_t sz, int is_unicast, time_t now);
static void log6_opts(int nest, unsigned int xid, void *start_opts, void *end_opts);
static void log6_packet(struct state *state, char *type, struct in6_addr *addr, char *string);
static void log6_quiet(struct state *state, char *type, struct in6_addr *addr, char *string);
@@ -110,12 +110,12 @@ unsigned short dhcp6_reply(struct dhcp_context *context, int interface, char *if
2022-11-08 06:48:29 +00:00
}
2023-04-04 08:52:53 +00:00
/* This cost me blood to write, it will probably cost you blood to understand - srk. */
-static int dhcp6_maybe_relay(struct state *state, void *inbuff, size_t sz,
+static int dhcp6_maybe_relay(struct state *state, unsigned char *inbuff, size_t sz,
struct in6_addr *client_addr, int is_unicast, time_t now)
{
2022-11-08 06:48:29 +00:00
void *end = inbuff + sz;
void *opts = inbuff + 34;
2023-04-04 08:52:53 +00:00
- int msg_type = *((unsigned char *)inbuff);
+ int msg_type = *inbuff;
unsigned char *outmsgtypep;
2022-11-08 06:48:29 +00:00
void *opt;
struct dhcp_vendor *vendor;
2023-04-04 08:52:53 +00:00
@@ -241,15 +241,15 @@ static int dhcp6_maybe_relay(struct state *state, void *inbuff, size_t sz,
return 1;
}
2022-11-08 06:48:29 +00:00
2023-04-04 08:52:53 +00:00
-static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_t sz, int is_unicast, time_t now)
+static int dhcp6_no_relay(struct state *state, int msg_type, unsigned char *inbuff, size_t sz, int is_unicast, time_t now)
{
void *opt;
- int i, o, o1, start_opts;
+ int i, o, o1, start_opts, start_msg;
struct dhcp_opt *opt_cfg;
2022-11-08 06:48:29 +00:00
struct dhcp_netid *tagif;
struct dhcp_config *config = NULL;
struct dhcp_netid known_id, iface_id, v6_id;
- unsigned char *outmsgtypep;
2023-04-04 08:52:53 +00:00
+ unsigned char outmsgtype;
2022-11-08 06:48:29 +00:00
struct dhcp_vendor *vendor;
struct dhcp_context *context_tmp;
struct dhcp_mac *mac_opt;
2023-04-04 08:52:53 +00:00
@@ -285,12 +285,13 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
v6_id.next = state->tags;
2022-11-08 06:48:29 +00:00
state->tags = &v6_id;
2023-04-04 08:52:53 +00:00
- /* copy over transaction-id, and save pointer to message type */
2022-11-08 06:48:29 +00:00
- if (!(outmsgtypep = put_opt6(inbuff, 4)))
2023-04-04 08:52:53 +00:00
+ start_msg = save_counter(-1);
+ /* copy over transaction-id */
+ if (!put_opt6(inbuff, 4))
2022-11-08 06:48:29 +00:00
return 0;
start_opts = save_counter(-1);
- state->xid = outmsgtypep[3] | outmsgtypep[2] << 8 | outmsgtypep[1] << 16;
2023-04-04 08:52:53 +00:00
-
+ state->xid = inbuff[3] | inbuff[2] << 8 | inbuff[1] << 16;
+
2022-11-08 06:48:29 +00:00
/* We're going to be linking tags from all context we use.
mark them as unused so we don't link one twice and break the list */
2023-04-04 08:52:53 +00:00
for (context_tmp = state->context; context_tmp; context_tmp = context_tmp->current)
@@ -336,7 +337,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
(msg_type == DHCP6REQUEST || msg_type == DHCP6RENEW || msg_type == DHCP6RELEASE || msg_type == DHCP6DECLINE))
{
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
o1 = new_opt6(OPTION6_STATUS_CODE);
put_opt6_short(DHCP6USEMULTI);
put_opt6_string("Use multicast");
2023-04-04 08:52:53 +00:00
@@ -600,11 +601,11 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
struct dhcp_netid *solicit_tags;
struct dhcp_context *c;
- *outmsgtypep = DHCP6ADVERTISE;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6ADVERTISE;
2022-11-08 06:48:29 +00:00
if (opt6_find(state->packet_options, state->end, OPTION6_RAPID_COMMIT, 0))
{
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
state->lease_allocate = 1;
o = new_opt6(OPTION6_RAPID_COMMIT);
end_opt6(o);
2023-04-04 08:52:53 +00:00
@@ -876,7 +877,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
int start = save_counter(-1);
/* set reply message type */
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
state->lease_allocate = 1;
log6_quiet(state, "DHCPREQUEST", NULL, ignore ? _("ignored") : NULL);
2023-04-04 08:52:53 +00:00
@@ -992,7 +993,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
case DHCP6RENEW:
{
/* set reply message type */
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
log6_quiet(state, "DHCPRENEW", NULL, NULL);
2023-04-04 08:52:53 +00:00
@@ -1104,7 +1105,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
int good_addr = 0;
/* set reply message type */
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
log6_quiet(state, "DHCPCONFIRM", NULL, NULL);
2023-04-04 08:52:53 +00:00
@@ -1168,7 +1169,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
log6_quiet(state, "DHCPINFORMATION-REQUEST", NULL, ignore ? _("ignored") : state->hostname);
if (ignore)
return 0;
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
tagif = add_options(state, 1);
break;
}
2023-04-04 08:52:53 +00:00
@@ -1177,7 +1178,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
case DHCP6RELEASE:
{
/* set reply message type */
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
log6_quiet(state, "DHCPRELEASE", NULL, NULL);
2023-04-04 08:52:53 +00:00
@@ -1242,7 +1243,7 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
2022-11-08 06:48:29 +00:00
case DHCP6DECLINE:
{
/* set reply message type */
- *outmsgtypep = DHCP6REPLY;
2023-04-04 08:52:53 +00:00
+ outmsgtype = DHCP6REPLY;
2022-11-08 06:48:29 +00:00
log6_quiet(state, "DHCPDECLINE", NULL, NULL);
2023-04-04 08:52:53 +00:00
@@ -1321,7 +1322,12 @@ static int dhcp6_no_relay(struct state *state, int msg_type, void *inbuff, size_
}
}
-
+
+ /* Fill in the message type. Note that we store the offset,
+ not a direct pointer, since the packet memory may have been
+ reallocated. */
+ ((unsigned char *)(daemon->outpacket.iov_base))[start_msg] = outmsgtype;
+
log_tags(tagif, state->xid);
log6_opts(0, state->xid, daemon->outpacket.iov_base + start_opts, daemon->outpacket.iov_base + save_counter(-1));
2022-11-08 06:48:29 +00:00
--
2023-04-04 08:52:53 +00:00
2.39.1
2022-11-08 06:48:29 +00:00