Skip to content

Commit c604266

Browse files
[AUTO-CHERRYPICK] Patch avahi to fix CVE-2024-52616 [Medium] - branch main (#12376)
Co-authored-by: Kanishk Bansal <103916909+Kanishk-Bansal@users.noreply.github.com>
1 parent 71714ee commit c604266

2 files changed

Lines changed: 108 additions & 1 deletion

File tree

SPECS/avahi/CVE-2024-52616.patch

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
From 6b7bf204cdb5f19798b6237324a3ce797f24359b Mon Sep 17 00:00:00 2001
2+
From: Kanishk-Bansal <kbkanishk975@gmail.com>
3+
Date: Thu, 13 Feb 2025 04:41:42 +0000
4+
Subject: [PATCH] Fix CVE-2024-52616
5+
Upstream Patch Reference https://github.com/avahi/avahi/pull/659/commits/f8710bdc8b29ee1176fe3bfaeabebbda1b7a79f7
6+
7+
---
8+
avahi-core/wide-area.c | 36 ++++++++++++++++++++++++++++--------
9+
configure.ac | 3 ++-
10+
2 files changed, 30 insertions(+), 9 deletions(-)
11+
12+
diff --git a/avahi-core/wide-area.c b/avahi-core/wide-area.c
13+
index d5e64e5..4cbba6c 100644
14+
--- a/avahi-core/wide-area.c
15+
+++ b/avahi-core/wide-area.c
16+
@@ -40,6 +40,13 @@
17+
#include "addr-util.h"
18+
#include "rr-util.h"
19+
20+
+#ifdef HAVE_SYS_RANDOM_H
21+
+#include <sys/random.h>
22+
+#endif
23+
+#ifndef HAVE_GETRANDOM
24+
+# define getrandom(d, len, flags) (-1)
25+
+#endif
26+
+
27+
#define CACHE_ENTRIES_MAX 500
28+
29+
typedef struct AvahiWideAreaCacheEntry AvahiWideAreaCacheEntry;
30+
@@ -84,8 +91,6 @@ struct AvahiWideAreaLookupEngine {
31+
int fd_ipv4, fd_ipv6;
32+
AvahiWatch *watch_ipv4, *watch_ipv6;
33+
34+
- uint16_t next_id;
35+
-
36+
/* Cache */
37+
AVAHI_LLIST_HEAD(AvahiWideAreaCacheEntry, cache);
38+
AvahiHashmap *cache_by_key;
39+
@@ -201,6 +206,26 @@ static void sender_timeout_callback(AvahiTimeEvent *e, void *userdata) {
40+
avahi_time_event_update(e, avahi_elapse_time(&tv, 1000, 0));
41+
}
42+
43+
+static uint16_t get_random_uint16(void) {
44+
+ uint16_t next_id;
45+
+
46+
+ if (getrandom(&next_id, sizeof(next_id), 0) == -1)
47+
+ next_id = (uint16_t) rand();
48+
+ return next_id;
49+
+}
50+
+
51+
+static uint16_t avahi_wide_area_next_id(AvahiWideAreaLookupEngine *e) {
52+
+ uint16_t next_id;
53+
+
54+
+ next_id = get_random_uint16();
55+
+ while (find_lookup(e, next_id)) {
56+
+ /* This ID is already used, get new. */
57+
+ next_id = get_random_uint16();
58+
+ }
59+
+ return next_id;
60+
+}
61+
+
62+
+
63+
AvahiWideAreaLookup *avahi_wide_area_lookup_new(
64+
AvahiWideAreaLookupEngine *e,
65+
AvahiKey *key,
66+
@@ -227,11 +252,7 @@ AvahiWideAreaLookup *avahi_wide_area_lookup_new(
67+
/* If more than 65K wide area quries are issued simultaneously,
68+
* this will break. This should be limited by some higher level */
69+
70+
- for (;; e->next_id++)
71+
- if (!find_lookup(e, e->next_id))
72+
- break; /* This ID is not yet used. */
73+
-
74+
- l->id = e->next_id++;
75+
+ l->id = avahi_wide_area_next_id(e);
76+
77+
/* We keep the packet around in case we need to repeat our query */
78+
l->packet = avahi_dns_packet_new(0);
79+
@@ -603,7 +624,6 @@ AvahiWideAreaLookupEngine *avahi_wide_area_engine_new(AvahiServer *s) {
80+
e->watch_ipv6 = s->poll_api->watch_new(e->server->poll_api, e->fd_ipv6, AVAHI_WATCH_IN, socket_event, e);
81+
82+
e->n_dns_servers = e->current_dns_server = 0;
83+
- e->next_id = (uint16_t) rand();
84+
85+
/* Initialize cache */
86+
AVAHI_LLIST_HEAD_INIT(AvahiWideAreaCacheEntry, e->cache);
87+
diff --git a/configure.ac b/configure.ac
88+
index 58db8c7..ae297a9 100644
89+
--- a/configure.ac
90+
+++ b/configure.ac
91+
@@ -368,7 +368,8 @@ AC_FUNC_SELECT_ARGTYPES
92+
# whether libc's malloc does too. (Same for realloc.)
93+
#AC_FUNC_MALLOC
94+
#AC_FUNC_REALLOC
95+
-AC_CHECK_FUNCS([gethostname memchr memmove memset mkdir select socket strchr strcspn strdup strerror strrchr strspn strstr uname setresuid setreuid setresgid setregid strcasecmp gettimeofday putenv strncasecmp strlcpy gethostbyname seteuid setegid setproctitle getprogname])
96+
+AC_CHECK_FUNCS([gethostname memchr memmove memset mkdir select socket strchr strcspn strdup strerror strrchr strspn strstr uname setresuid setreuid setresgid setregid strcasecmp gettimeofday putenv strncasecmp strlcpy gethostbyname seteuid setegid setproctitle getprogname getrandom])
97+
+AC_CHECK_HEADERS([sys/random.h])
98+
99+
AC_FUNC_CHOWN
100+
AC_FUNC_STAT
101+
--
102+
2.45.2
103+

SPECS/avahi/avahi.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Summary: Local network service discovery
44
Name: avahi
55
Version: 0.8
6-
Release: 3%{?dist}
6+
Release: 4%{?dist}
77
License: LGPLv2+
88
Vendor: Microsoft Corporation
99
Distribution: Mariner
@@ -18,6 +18,7 @@ Patch5: CVE-2023-38471.patch
1818
Patch6: CVE-2023-38472.patch
1919
Patch7: CVE-2023-38473.patch
2020
Patch8: CVE-2023-38469.patch
21+
Patch9: CVE-2024-52616.patch
2122
BuildRequires: automake
2223
BuildRequires: dbus-devel >= 0.90
2324
BuildRequires: dbus-glib-devel >= 0.70
@@ -411,6 +412,9 @@ exit 0
411412
%endif
412413

413414
%changelog
415+
* Thu Feb 13 2024 Kanishk Bansal <kanbansal@microsoft.com> - 0.8-4
416+
- Fix CVE-2024-52616 with an upstream patch
417+
414418
* Mon Dec 02 2024 Kanishk Bansal <kanbansal@microsoft.com> - 0.8-3
415419
- Fix CVE-2023-38473 wih an upstream patch
416420
- Fix CVE-2023-38472 wih an upstream patch

0 commit comments

Comments
 (0)