summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/libcap/files/CVE-2023-2603.patch
blob: cf86ac2a469a45b60608a5c896f922f71f8abcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Backport of:

From 422bec25ae4a1ab03fd4d6f728695ed279173b18 Mon Sep 17 00:00:00 2001
From: "Andrew G. Morgan" <morgan@kernel.org>
Date: Wed, 3 May 2023 19:44:22 -0700
Subject: Large strings can confuse libcap's internal strdup code.

Avoid something subtle with really long strings: 1073741823 should
be enough for anybody. This is an improved fix over something attempted
in libcap-2.55 to address some static analysis findings.

Reviewing the library, cap_proc_root() and cap_launcher_set_chroot()
are the only two calls where the library is potentially exposed to a
user controlled string input.

Credit for finding this bug in libcap goes to Richard Weinberger of
X41 D-Sec GmbH (https://x41-dsec.de/) who performed a security audit
of the libcap source code in April of 2023. The audit was sponsored
by the Open Source Technology Improvement Fund (https://ostif.org/).

Audit ref: LCAP-CR-23-02 (CVE-2023-2603)

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>

Upstream-Status: Backport [import from ubuntu https://git.launchpad.net/ubuntu/+source/libcap2/tree/debian/patches/CVE-2023-2603.patch?h=ubuntu/focal-security
Upstream commit https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=422bec25ae4a1ab03fd4d6f728695ed279173b18]
CVE: CVE-2023-2603
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
---
 libcap/cap_alloc.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

--- a/libcap/cap_alloc.c
+++ b/libcap/cap_alloc.c
@@ -76,13 +76,22 @@ cap_t cap_init(void)
 char *_libcap_strdup(const char *old)
 {
     __u32 *raw_data;
+    size_t len;
 
     if (old == NULL) {
 	errno = EINVAL;
 	return NULL;
     }
 
-    raw_data = malloc( sizeof(__u32) + strlen(old) + 1 );
+    len = strlen(old);
+    if ((len & 0x3fffffff) != len) {
+	_cap_debug("len is too long for libcap to manage");
+	errno = EINVAL;
+	return NULL;
+    }
+    len += sizeof(__u32) + 1;
+
+    raw_data = malloc(len);
     if (raw_data == NULL) {
 	errno = ENOMEM;
 	return NULL;