From 69f09335d7c5912e2bfeab08fdeced5ab7083cf4 Mon Sep 17 00:00:00 2001 From: woody2918 Date: Mon, 11 Mar 2024 09:53:30 +0800 Subject: [PATCH 1/2] FIX CVE-2024-2314 --- ...24-2314-clang-check-header-ownership.patch | 65 +++++++++++++++++++ bcc.spec | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 0001-CVE-2024-2314-clang-check-header-ownership.patch diff --git a/0001-CVE-2024-2314-clang-check-header-ownership.patch b/0001-CVE-2024-2314-clang-check-header-ownership.patch new file mode 100644 index 0000000..62ce65a --- /dev/null +++ b/0001-CVE-2024-2314-clang-check-header-ownership.patch @@ -0,0 +1,65 @@ +From 008ea09e891194c072f2a9305a3c872a241dc342 Mon Sep 17 00:00:00 2001 +From: Brendan Gregg +Date: Thu, 7 Mar 2024 05:27:14 +1100 +Subject: [PATCH] clang: check header ownership (#4928) + +Example testing with a brendan-owned /tmp/kheaders file (note the "ERROR:" message): + +~/bcc/build$ sudo /usr/share/bcc/tools/biosnoop +ERROR: header file ownership unexpected: /tmp/kheaders-5.15.47-internal +:1:10: fatal error: './include/linux/kconfig.h' file not found +#include "./include/linux/kconfig.h" + ^~~~~~~~~~~~~~~~~~~~~~~~~~~ +1 error generated. +Traceback (most recent call last): + File "/usr/share/bcc/tools/biosnoop", line 335, in + b = BPF(text=bpf_text) + File "/usr/lib/python3/dist-packages/bcc-0.1.5+6cd27218-py3.10.egg/bcc/__init__.py", line 479, in __init__ +Exception: Failed to compile BPF module +~/bcc/build$ ls -lhd /tmp/kheaders-5.15.47-internal +drwxrwxr-x 2 brendan dev 4.0K Mar 6 02:50 /tmp/kheaders-5.15.47-internal + +No error when chown'd back to root. +--- + src/cc/frontends/clang/kbuild_helper.cc | 15 +++++++++++---- + 1 file changed, 11 insertions(+), 4 deletions(-) + +diff --git a/src/cc/frontends/clang/kbuild_helper.cc b/src/cc/frontends/clang/kbuild_helper.cc +index 50e2da9a7bc..d4b9d3e61c7 100644 +--- a/src/cc/frontends/clang/kbuild_helper.cc ++++ b/src/cc/frontends/clang/kbuild_helper.cc +@@ -140,15 +140,22 @@ int KBuildHelper::get_flags(const char *uname_machine, vector *cflags) { + return 0; + } + +-static inline int file_exists(const char *f) ++static inline int file_exists_and_ownedby(const char *f, uid_t uid) + { + struct stat buffer; +- return (stat(f, &buffer) == 0); ++ int ret; ++ if ((ret = stat(f, &buffer)) == 0) { ++ if (buffer.st_uid != uid) { ++ std::cout << "ERROR: header file ownership unexpected: " << std::string(f) << "\n"; ++ return -1; ++ } ++ } ++ return ret; + } + + static inline int proc_kheaders_exists(void) + { +- return file_exists(PROC_KHEADERS_PATH); ++ return file_exists_and_ownedby(PROC_KHEADERS_PATH, 0); + } + + static inline const char *get_tmp_dir() { +@@ -224,7 +231,7 @@ int get_proc_kheaders(std::string &dirpath) + uname_data.release); + dirpath = std::string(dirpath_tmp); + +- if (file_exists(dirpath_tmp)) ++ if (file_exists_and_ownedby(dirpath_tmp, 0)) + return 0; + + // First time so extract it diff --git a/bcc.spec b/bcc.spec index c9396d6..41f4ecf 100644 --- a/bcc.spec +++ b/bcc.spec @@ -8,7 +8,7 @@ License: ASL 2.0 URL: https://github.com/iovisor/bcc # Upstream now provides a release with the git submodule embedded in it Source0: %{url}/releases/download/v%{version}/%{name}-src-with-submodule.tar.gz - +Patch001: 0001-CVE-2024-2314-clang-check-header-ownership.patch # Arches will be included as upstream support is added and dependencies are # satisfied in the respective arches -- Gitee From eeae0ab4943a7f994bf7ee1d3038066198df05b2 Mon Sep 17 00:00:00 2001 From: woody2918 Date: Mon, 18 Mar 2024 03:20:22 +0000 Subject: [PATCH 2/2] =?UTF-8?q?update=20bcc.spec.=20=E4=BF=AE=E5=A4=8DCVE?= =?UTF-8?q?=EF=BC=8C=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0changelog=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: woody2918 --- bcc.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bcc.spec b/bcc.spec index 41f4ecf..37163f7 100644 --- a/bcc.spec +++ b/bcc.spec @@ -2,7 +2,7 @@ Name: bcc Version: 0.29.1 -Release: 1 +Release: 2 Summary: BPF Compiler Collection (BCC) License: ASL 2.0 URL: https://github.com/iovisor/bcc @@ -163,6 +163,9 @@ rm -rf %{buildroot}%{_datadir}/%{name}/tools/old/ %changelog +* Mon Mar 18 2024 woody2918 - 0.29.1-2 +- Fix CVE-2024-2314 + * Mon Feb 19 2024 liweigang - 0.29.1-1 - update to version 0.29.1 -- Gitee