Skip to contentSkip to conversation

libpcap: Security fix for CVE-2023-7256 & CVE-2024-8006

PATCH New [email protected] 1 participant 1 message Sep 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libpcap: Security fix for CVE-2023-7256 & CVE-2024-8006

From: Vijay Anusuri <[email protected]>

Reference:
https://security-tracker.debian.org/tracker/CVE-2023-7256
https://security-tracker.debian.org/tracker/CVE-2024-8006

Upstream commits:
https://github.com/the-tcpdump-group/libpcap/commit/ba493d37d418b126d7357df553bd065cbc99384e
https://github.com/the-tcpdump-group/libpcap/commit/f72f48a26abdd2eb11a4a8fb3596ee67b8f8cbe6
https://github.com/the-tcpdump-group/libpcap/commit/c1ceab8f191031a81996035af20685e6f9b7f1b7
https://github.com/the-tcpdump-group/libpcap/commit/73da0d4d65ef0925772b7b7f82a5fbb3ff2c5e4f
https://github.com/the-tcpdump-group/libpcap/commit/2aa69b04d8173b18a0e3492e0c8f2f7fabdf642d
https://github.com/the-tcpdump-group/libpcap/commit/8a633ee5b9ecd9d38a587ac9b204e2380713b0d6

---
 .../libpcap/libpcap/CVE-2023-7256-pre1.patch  |  99 +++++
 .../libpcap/libpcap/CVE-2023-7256-pre2.patch  | 131 +++++++
 .../libpcap/libpcap/CVE-2023-7256-pre3.patch  |  67 ++++
 .../libpcap/libpcap/CVE-2023-7256-pre4.patch  |  37 ++
 .../libpcap/libpcap/CVE-2023-7256.patch       | 368 ++++++++++++++++++
 .../libpcap/libpcap/CVE-2024-8006.patch       |  42 ++
 .../libpcap/libpcap_1.10.1.bb                 |  10 +-
 7 files changed, 753 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre1.patch
 create mode 100644 meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre2.patch
 create mode 100644 meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre3.patch
 create mode 100644 meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre4.patch
 create mode 100644 meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256.patch
 create mode 100644 meta/recipes-connectivity/libpcap/libpcap/CVE-2024-8006.patch
meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre1.patch new file +99 -0
new file mode 100644
index 0000000000..6965034656
@@ -0,0 +1,99 @@
+From f72f48a26abdd2eb11a4a8fb3596ee67b8f8cbe6 Mon Sep 17 00:00:00 2001
+From: Guy Harris <[email protected]>
+Date: Wed, 21 Jul 2021 23:50:32 -0700
+Subject: [PATCH] rpcap: don't do pointless integer->string and then
+ string->integer conversions.
+
+The string->integer conversion was also broken, as it passed a pointer
+to a 16-bit integer to a sscanf() call that used %d rather than %hd.
+It'd overwrite 2 bytes past the 16-bit integer; it may set the integer
+"correctly" on a little-endian, but wouldn't even do *that* on a
+big-endian machine.
+
+(cherry picked from commit efaddfe8eae4dab252bb2d35e004a40e4b72db24)
+
+Upstream-Status: Backport [https://github.com/the-tcpdump-group/libpcap/commit/f72f48a26abdd2eb11a4a8fb3596ee67b8f8cbe6]
+CVE: CVE-2023-7256 #Dependency Patch1
+Signed-off-by: Vijay Anusuri <[email protected]>
+---
+ pcap-rpcap.c | 34 ++++++++++++++++++++++++----------
+ 1 file changed, 24 insertions(+), 10 deletions(-)
+
+diff --git a/pcap-rpcap.c b/pcap-rpcap.c
+index 225b420904..f5c126dbc1 100644
+--- a/pcap-rpcap.c
++++ b/pcap-rpcap.c
+@@ -1060,7 +1060,7 @@ static int pcap_startcapture_remote(pcap_t *fp)
+ 	struct pcap_rpcap *pr = fp->priv;	/* structure used when doing a remote live capture */
+ 	char sendbuf[RPCAP_NETBUF_SIZE];	/* temporary buffer in which data to be sent is buffered */
+ 	int sendbufidx = 0;			/* index which keeps the number of bytes currently buffered */
+-	char portdata[PCAP_BUF_SIZE];		/* temp variable needed to keep the network port for the data connection */
++	uint16 portdata = 0;			/* temp variable needed to keep the network port for the data connection */
+ 	uint32 plen;
+ 	int active = 0;				/* '1' if we're in active mode */
+ 	struct activehosts *temp;		/* temp var needed to scan the host list chain, to detect if we're in active mode */
+@@ -1073,6 +1073,8 @@ static int pcap_startcapture_remote(pcap_t *fp)
+ 	struct sockaddr_storage saddr;		/* temp, needed to retrieve the network data port chosen on the local machine */
+ 	socklen_t saddrlen;			/* temp, needed to retrieve the network data port chosen on the local machine */
+ 	int ai_family;				/* temp, keeps the address family used by the control connection */
++	struct sockaddr_in *sin4;
++	struct sockaddr_in6 *sin6;
+ 
+ 	/* RPCAP-related variables*/
+ 	struct rpcap_header header;			/* header of the RPCAP packet */
+@@ -1171,11 +1173,22 @@ static int pcap_startcapture_remote(pcap_t *fp)
+ 			goto error_nodiscard;
+ 		}
+ 
+-		/* Get the local port the system picked up */
+-		if (getnameinfo((struct sockaddr *) &saddr, saddrlen, NULL,
+-			0, portdata, sizeof(portdata), NI_NUMERICSERV))
+-		{
+-			sock_geterror("getnameinfo()", fp->errbuf, PCAP_ERRBUF_SIZE);
++		switch (saddr.ss_family) {
++
++		case AF_INET:
++			sin4 = (struct sockaddr_in *)&saddr;
++			portdata = sin4->sin_port;
++			break;
++
++		case AF_INET6:
++			sin6 = (struct sockaddr_in6 *)&saddr;
++			portdata = sin6->sin6_port;
++			break;
++
++		default:
++			snprintf(fp->errbuf, PCAP_ERRBUF_SIZE,
++			    "Local address has unknown address family %u",
++			    saddr.ss_family);
+ 			goto error_nodiscard;
+ 		}
+ 	}
+@@ -1208,8 +1221,7 @@ static int pcap_startcapture_remote(pcap_t *fp)
+ 	/* portdata on the openreq is meaningful only if we're in active mode */
+ 	if ((active) || (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP))
+ 	{
+-		sscanf(portdata, "%d", (int *)&(startcapreq->portdata));	/* cast to avoid a compiler warning */
+-		startcapreq->portdata = htons(startcapreq->portdata);
++		startcapreq->portdata = portdata;
+ 	}
+ 
+ 	startcapreq->snaplen = htonl(fp->snapshot);
+@@ -1258,13 +1270,15 @@ static int pcap_startcapture_remote(pcap_t *fp)
+ 	{
+ 		if (!active)
+ 		{
++			char portstring[PCAP_BUF_SIZE];
++
+ 			memset(&hints, 0, sizeof(struct addrinfo));
+ 			hints.ai_family = ai_family;		/* Use the same address family of the control socket */
+ 			hints.ai_socktype = (pr->rmt_flags & PCAP_OPENFLAG_DATATX_UDP) ? SOCK_DGRAM : SOCK_STREAM;
+-			snprintf(portdata, PCAP_BUF_SIZE, "%d", ntohs(startcapreply.portdata));
++			snprintf(portstring, PCAP_BUF_SIZE, "%d", ntohs(startcapreply.portdata));
+ 
+ 			/* Let's the server pick up a free network port for us */
+-			if (sock_initaddress(host, portdata, &hints, &addrinfo, fp->errbuf, PCAP_ERRBUF_SIZE) == -1)
++			if (sock_initaddress(host, portstring, &hints, &addrinfo, fp->errbuf, PCAP_ERRBUF_SIZE) == -1)
+ 				goto error;
+ 
+ 			if ((sockdata = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, fp->errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre2.patch new file +131 -0

131 lines not on this page · raw message

meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre3.patch new file +67 -0

67 lines not on this page · raw message

meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256-pre4.patch new file +37 -0
new file mode 100644
index 0000000000..dcf203f754
@@ -0,0 +1,37 @@
+From 73da0d4d65ef0925772b7b7f82a5fbb3ff2c5e4f Mon Sep 17 00:00:00 2001
+From: Rose <[email protected]>
+Date: Tue, 16 May 2023 12:37:11 -0400
+Subject: [PATCH] Remove unused variable retval in sock_present2network
+
+This quiets the compiler since it is not even returned anyway, and is a misleading variable name.
+
+(cherry picked from commit c7b90298984c46d820d3cee79a96d24870b5f200)
+
+Upstream-Status: Backport [https://github.com/the-tcpdump-group/libpcap/commit/73da0d4d65ef0925772b7b7f82a5fbb3ff2c5e4f]
+CVE: CVE-2023-7256 #Dependency Patch4
+Signed-off-by: Vijay Anusuri <[email protected]>
+---
+ sockutils.c | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/sockutils.c b/sockutils.c
+index 1c07f76fd1..6752f296af 100644
+--- a/sockutils.c
++++ b/sockutils.c
+@@ -2082,7 +2082,6 @@ int sock_getascii_addrport(const struct sockaddr_storage *sockaddr, char *addres
+  */
+ int sock_present2network(const char *address, struct sockaddr_storage *sockaddr, int addr_family, char *errbuf, int errbuflen)
+ {
+-	int retval;
+ 	struct addrinfo *addrinfo;
+ 	struct addrinfo hints;
+ 
+@@ -2090,7 +2089,7 @@ int sock_present2network(const char *address, struct sockaddr_storage *sockaddr,
+ 
+ 	hints.ai_family = addr_family;
+ 
+-	if ((retval = sock_initaddress(address, "22222" /* fake port */, &hints, &addrinfo, errbuf, errbuflen)) == -1)
++	if (sock_initaddress(address, "22222" /* fake port */, &hints, &addrinfo, errbuf, errbuflen) == -1)
+ 		return 0;
+ 
+ 	if (addrinfo->ai_family == PF_INET)
meta/recipes-connectivity/libpcap/libpcap/CVE-2023-7256.patch new file +368 -0

368 lines not on this page · raw message

meta/recipes-connectivity/libpcap/libpcap/CVE-2024-8006.patch new file +42 -0

42 lines not on this page · raw message

meta/recipes-connectivity/libpcap/libpcap_1.10.1.bb +9 -1
index dbe2fd8157..584e98c76d 100644
@@ -10,7 +10,15 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=5eb289217c160e2920d2e35bddc36453 \
                     file://pcap.h;beginline=1;endline=32;md5=39af3510e011f34b8872f120b1dc31d2"
 DEPENDS = "flex-native bison-native"
 
-SRC_URI = "https://www.tcpdump.org/release/${BP}.tar.gz"
+SRC_URI = "https://www.tcpdump.org/release/${BP}.tar.gz \
+           file://CVE-2023-7256-pre1.patch \
+           file://CVE-2023-7256-pre2.patch \
+           file://CVE-2023-7256-pre3.patch \
+           file://CVE-2023-7256-pre4.patch \
+           file://CVE-2023-7256.patch \
+           file://CVE-2024-8006.patch \
+          "
+
 SRC_URI[sha256sum] = "ed285f4accaf05344f90975757b3dbfe772ba41d1c401c2648b7fa45b711bdd4"
 
 inherit autotools binconfig-disabled pkgconfig
Signature · 1 line
2.25.1