diff options
| author | Deepak Rathore <deeratho@cisco.com> | 2025-11-27 11:52:23 +0000 |
|---|---|---|
| committer | Khem Raj <raj.khem@gmail.com> | 2025-12-11 20:21:23 -0800 |
| commit | 8cbb4ae395d31c7ad178302126a497f7a1477b5b (patch) | |
| tree | 8c635f82176db27c0f2306de3a3610c40a064b83 /dynamic-layers/meta-python | |
| parent | 754ca238f354d3dd94862db734395c72e5b48088 (diff) | |
| download | meta-clang-8cbb4ae395d31c7ad178302126a497f7a1477b5b.tar.gz | |
bpftrace 0.20.1: Fix CVE-2024-2313
Upstream Repository: https://github.com/bpftrace/bpftrace.git
Bug Details: https://nvd.nist.gov/vuln/detail/CVE-2024-2313
Type: Security Fix
CVE: CVE-2024-2313
Score: 2.8
Patch: https://github.com/bpftrace/bpftrace/commit/bc73244963f2
Note:
- This CVE was initially addressed via commit 4be4b7191acb [1], which
added ownership verification for unpacked kernel headers.
- The fix was deemed insufficient and a revised comprehensive fix was
implemented in commit bc73244963f2 [2], which completely removes the
risky functionality.
- This patch applies only the revised fix (bc73244963f2) which supersedes
the initial partial fix.
Reference:
[1] https://github.com/bpftrace/bpftrace/pull/3033
[2] https://github.com/bpftrace/bpftrace/pull/3156
Signed-off-by: Deepak Rathore <deeratho@cisco.com>
Diffstat (limited to 'dynamic-layers/meta-python')
| -rw-r--r-- | dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/CVE-2024-2313.patch | 284 | ||||
| -rw-r--r-- | dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.20.1.bb | 1 |
2 files changed, 285 insertions, 0 deletions
diff --git a/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/CVE-2024-2313.patch b/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/CVE-2024-2313.patch new file mode 100644 index 0000000..2631fbc --- /dev/null +++ b/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace/CVE-2024-2313.patch | |||
| @@ -0,0 +1,284 @@ | |||
| 1 | From 18c07736fd3b87ed797eeab1e0d1fb57fd1db7ac Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Jordan Rome <jordalgo@meta.com> | ||
| 3 | Date: Wed, 15 May 2024 10:21:30 -0600 | ||
| 4 | Subject: [PATCH] Don't unpack kernel headers or look in tmp (#3156) | ||
| 5 | |||
| 6 | Looking in shared writeable locations for kernel | ||
| 7 | headers is inherently risky even bpftrace does | ||
| 8 | the unpacking. Remove this functionality and let | ||
| 9 | the user specify the path to these headers if | ||
| 10 | we can't find them in known locations. | ||
| 11 | |||
| 12 | References: | ||
| 13 | https://github.com/bpftrace/bpftrace/pull/3033 | ||
| 14 | https://github.com/bpftrace/bpftrace/pull/3154 | ||
| 15 | |||
| 16 | CVE: CVE-2024-2313 | ||
| 17 | Upstream-Status: Backport [https://github.com/bpftrace/bpftrace/commit/bc73244963f2] | ||
| 18 | |||
| 19 | Backport Changes: | ||
| 20 | - src/utils.cpp: file_exists_and_ownedby_root() was not present in | ||
| 21 | current version. Hence, changes are made accordingly. | ||
| 22 | - src/main.cpp: Upstream commit uses "/bpftrace/include/" CLANG_WORKAROUNDS_H | ||
| 23 | but current codebase uses CLANG_WORKAROUNDS_H without the path prefix. | ||
| 24 | Changes are made as per current codebase. | ||
| 25 | - tests/utils.cpp: Test case changes for file_exists_and_ownedby_root() | ||
| 26 | function are not included as the function itself was not present in | ||
| 27 | current version. | ||
| 28 | |||
| 29 | Co-authored-by: Jordan Rome <jordalgo@fedoraproject.org> | ||
| 30 | (cherry picked from commit bc73244963f206814ae45ec78ebe52cd389f6381) | ||
| 31 | Signed-off-by: Deepak Rathore <deeratho@cisco.com> | ||
| 32 | --- | ||
| 33 | src/clang_parser.cpp | 2 - | ||
| 34 | src/fuzz_main.cpp | 2 +- | ||
| 35 | src/main.cpp | 62 +++++++++++++++------------- | ||
| 36 | src/utils.cpp | 98 ++++---------------------------------------- | ||
| 37 | src/utils.h | 3 +- | ||
| 38 | 5 files changed, 45 insertions(+), 122 deletions(-) | ||
| 39 | |||
| 40 | diff --git a/src/clang_parser.cpp b/src/clang_parser.cpp | ||
| 41 | index 2b50e931..667a833f 100644 | ||
| 42 | --- a/src/clang_parser.cpp | ||
| 43 | +++ b/src/clang_parser.cpp | ||
| 44 | @@ -660,8 +660,6 @@ bool ClangParser::parse(ast::Program *program, | ||
| 45 | StderrSilencer silencer; | ||
| 46 | silencer.silence(); | ||
| 47 | #endif | ||
| 48 | - if (program->c_definitions.empty() && bpftrace.btf_set_.empty()) | ||
| 49 | - return true; | ||
| 50 | |||
| 51 | input = "#include <__btf_generated_header.h>\n" + program->c_definitions; | ||
| 52 | |||
| 53 | diff --git a/src/fuzz_main.cpp b/src/fuzz_main.cpp | ||
| 54 | index 35455c03..1d4c4806 100644 | ||
| 55 | --- a/src/fuzz_main.cpp | ||
| 56 | +++ b/src/fuzz_main.cpp | ||
| 57 | @@ -132,7 +132,7 @@ int fuzz_main(const char* data, size_t sz) | ||
| 58 | struct utsname utsname; | ||
| 59 | uname(&utsname); | ||
| 60 | std::string ksrc, kobj; | ||
| 61 | - auto kdirs = get_kernel_dirs(utsname, !bpftrace.feature_->has_btf()); | ||
| 62 | + auto kdirs = get_kernel_dirs(utsname); | ||
| 63 | ksrc = std::get<0>(kdirs); | ||
| 64 | kobj = std::get<1>(kdirs); | ||
| 65 | |||
| 66 | diff --git a/src/main.cpp b/src/main.cpp | ||
| 67 | index c3700d93..831976b9 100644 | ||
| 68 | --- a/src/main.cpp | ||
| 69 | +++ b/src/main.cpp | ||
| 70 | @@ -405,32 +405,6 @@ static std::optional<struct timespec> get_delta_taitime() | ||
| 71 | if (TracepointFormatParser::parse(driver.root.get(), bpftrace) == false) | ||
| 72 | return nullptr; | ||
| 73 | |||
| 74 | - ClangParser clang; | ||
| 75 | - std::vector<std::string> extra_flags; | ||
| 76 | - { | ||
| 77 | - struct utsname utsname; | ||
| 78 | - uname(&utsname); | ||
| 79 | - std::string ksrc, kobj; | ||
| 80 | - auto kdirs = get_kernel_dirs(utsname); | ||
| 81 | - ksrc = std::get<0>(kdirs); | ||
| 82 | - kobj = std::get<1>(kdirs); | ||
| 83 | - | ||
| 84 | - if (ksrc != "") | ||
| 85 | - extra_flags = get_kernel_cflags( | ||
| 86 | - utsname.machine, ksrc, kobj, bpftrace.kconfig); | ||
| 87 | - } | ||
| 88 | - extra_flags.push_back("-include"); | ||
| 89 | - extra_flags.push_back(CLANG_WORKAROUNDS_H); | ||
| 90 | - | ||
| 91 | - for (auto dir : include_dirs) { | ||
| 92 | - extra_flags.push_back("-I"); | ||
| 93 | - extra_flags.push_back(dir); | ||
| 94 | - } | ||
| 95 | - for (auto file : include_files) { | ||
| 96 | - extra_flags.push_back("-include"); | ||
| 97 | - extra_flags.push_back(file); | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | // NOTE(mmarchini): if there are no C definitions, clang parser won't run to | ||
| 101 | // avoid issues in some versions. Since we're including files in the command | ||
| 102 | // line, we want to force parsing, so we make sure C definitions are not | ||
| 103 | @@ -438,8 +412,40 @@ static std::optional<struct timespec> get_delta_taitime() | ||
| 104 | if (!include_files.empty() && driver.root->c_definitions.empty()) | ||
| 105 | driver.root->c_definitions = "#define __BPFTRACE_DUMMY__"; | ||
| 106 | |||
| 107 | - if (!clang.parse(driver.root.get(), bpftrace, extra_flags)) | ||
| 108 | - return nullptr; | ||
| 109 | + bool should_clang_parse = !(driver.root.get()->c_definitions.empty() && | ||
| 110 | + bpftrace.btf_set_.empty()); | ||
| 111 | + | ||
| 112 | + if (should_clang_parse) { | ||
| 113 | + ClangParser clang; | ||
| 114 | + std::vector<std::string> extra_flags; | ||
| 115 | + { | ||
| 116 | + struct utsname utsname; | ||
| 117 | + uname(&utsname); | ||
| 118 | + std::string ksrc, kobj; | ||
| 119 | + auto kdirs = get_kernel_dirs(utsname); | ||
| 120 | + ksrc = std::get<0>(kdirs); | ||
| 121 | + kobj = std::get<1>(kdirs); | ||
| 122 | + | ||
| 123 | + if (ksrc != "") { | ||
| 124 | + extra_flags = get_kernel_cflags( | ||
| 125 | + utsname.machine, ksrc, kobj, bpftrace.kconfig); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + extra_flags.push_back("-include"); | ||
| 129 | + extra_flags.push_back(CLANG_WORKAROUNDS_H); | ||
| 130 | + | ||
| 131 | + for (auto dir : include_dirs) { | ||
| 132 | + extra_flags.push_back("-I"); | ||
| 133 | + extra_flags.push_back(dir); | ||
| 134 | + } | ||
| 135 | + for (auto file : include_files) { | ||
| 136 | + extra_flags.push_back("-include"); | ||
| 137 | + extra_flags.push_back(file); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + if (!clang.parse(driver.root.get(), bpftrace, extra_flags)) | ||
| 141 | + return nullptr; | ||
| 142 | + } | ||
| 143 | |||
| 144 | err = driver.parse(); | ||
| 145 | if (err) | ||
| 146 | diff --git a/src/utils.cpp b/src/utils.cpp | ||
| 147 | index 0a3af640..4844780c 100644 | ||
| 148 | --- a/src/utils.cpp | ||
| 149 | +++ b/src/utils.cpp | ||
| 150 | @@ -683,88 +683,6 @@ bool is_dir(const std::string &path) | ||
| 151 | return std_filesystem::is_directory(buf, ec); | ||
| 152 | } | ||
| 153 | |||
| 154 | -namespace { | ||
| 155 | -struct KernelHeaderTmpDir { | ||
| 156 | - KernelHeaderTmpDir(const std::string &prefix) : path{ prefix + "XXXXXX" } | ||
| 157 | - { | ||
| 158 | - if (::mkdtemp(&path[0]) == nullptr) { | ||
| 159 | - throw std::runtime_error( | ||
| 160 | - "creating temporary path for kheaders.tar.xz failed"); | ||
| 161 | - } | ||
| 162 | - } | ||
| 163 | - | ||
| 164 | - ~KernelHeaderTmpDir() | ||
| 165 | - { | ||
| 166 | - if (path.size() > 0) { | ||
| 167 | - // move_to either did not succeed or did not run, so clean up after | ||
| 168 | - // ourselves | ||
| 169 | - exec_system(("rm -rf " + path).c_str()); | ||
| 170 | - } | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - void move_to(const std::string &new_path) | ||
| 174 | - { | ||
| 175 | - int err = ::rename(path.c_str(), new_path.c_str()); | ||
| 176 | - if (err == 0) { | ||
| 177 | - path = ""; | ||
| 178 | - } | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - std::string path; | ||
| 182 | -}; | ||
| 183 | - | ||
| 184 | -std::string unpack_kheaders_tar_xz(const struct utsname &utsname) | ||
| 185 | -{ | ||
| 186 | - std::error_code ec; | ||
| 187 | -#if defined(__ANDROID__) | ||
| 188 | - std_filesystem::path path_prefix{ "/data/local/tmp" }; | ||
| 189 | -#else | ||
| 190 | - std_filesystem::path path_prefix{ "/tmp" }; | ||
| 191 | -#endif | ||
| 192 | - std_filesystem::path path_kheaders{ "/sys/kernel/kheaders.tar.xz" }; | ||
| 193 | - if (const char *tmpdir = ::getenv("TMPDIR")) { | ||
| 194 | - path_prefix = tmpdir; | ||
| 195 | - } | ||
| 196 | - path_prefix /= "kheaders-"; | ||
| 197 | - std_filesystem::path shared_path{ path_prefix.string() + utsname.release }; | ||
| 198 | - | ||
| 199 | - if (std_filesystem::exists(shared_path, ec)) { | ||
| 200 | - // already unpacked | ||
| 201 | - return shared_path.string(); | ||
| 202 | - } | ||
| 203 | - | ||
| 204 | - if (!std_filesystem::exists(path_kheaders, ec)) { | ||
| 205 | - StderrSilencer silencer; | ||
| 206 | - silencer.silence(); | ||
| 207 | - | ||
| 208 | - FILE *modprobe = ::popen("modprobe kheaders", "w"); | ||
| 209 | - if (modprobe == nullptr || pclose(modprobe) != 0) { | ||
| 210 | - return ""; | ||
| 211 | - } | ||
| 212 | - | ||
| 213 | - if (!std_filesystem::exists(path_kheaders, ec)) { | ||
| 214 | - return ""; | ||
| 215 | - } | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - KernelHeaderTmpDir tmpdir{ path_prefix }; | ||
| 219 | - | ||
| 220 | - FILE *tar = ::popen( | ||
| 221 | - ("tar xf /sys/kernel/kheaders.tar.xz -C " + tmpdir.path).c_str(), "w"); | ||
| 222 | - if (!tar) { | ||
| 223 | - return ""; | ||
| 224 | - } | ||
| 225 | - | ||
| 226 | - int rc = ::pclose(tar); | ||
| 227 | - if (rc == 0) { | ||
| 228 | - tmpdir.move_to(shared_path); | ||
| 229 | - return shared_path; | ||
| 230 | - } | ||
| 231 | - | ||
| 232 | - return ""; | ||
| 233 | -} | ||
| 234 | -} // namespace | ||
| 235 | - | ||
| 236 | // get_kernel_dirs returns {ksrc, kobj} - directories for pristine and | ||
| 237 | // generated kernel sources. | ||
| 238 | // | ||
| 239 | @@ -783,8 +701,7 @@ std::string unpack_kheaders_tar_xz(const struct utsname &utsname) | ||
| 240 | // Both ksrc and kobj are guaranteed to be != "", if at least some trace of | ||
| 241 | // kernel sources was found. | ||
| 242 | std::tuple<std::string, std::string> get_kernel_dirs( | ||
| 243 | - const struct utsname &utsname, | ||
| 244 | - bool unpack_kheaders) | ||
| 245 | + const struct utsname &utsname) | ||
| 246 | { | ||
| 247 | #ifdef KERNEL_HEADERS_DIR | ||
| 248 | return { KERNEL_HEADERS_DIR, KERNEL_HEADERS_DIR }; | ||
| 249 | @@ -812,11 +729,14 @@ std::tuple<std::string, std::string> get_kernel_dirs( | ||
| 250 | kobj = ""; | ||
| 251 | } | ||
| 252 | if (ksrc.empty() && kobj.empty()) { | ||
| 253 | - if (unpack_kheaders) { | ||
| 254 | - const auto kheaders_tar_xz_path = unpack_kheaders_tar_xz(utsname); | ||
| 255 | - if (kheaders_tar_xz_path.size() > 0) | ||
| 256 | - return std::make_tuple(kheaders_tar_xz_path, kheaders_tar_xz_path); | ||
| 257 | - } | ||
| 258 | + LOG(WARNING) << "Could not find kernel headers in " << ksrc << " or " | ||
| 259 | + << kobj | ||
| 260 | + << ". To specify a particular path to kernel headers, set the " | ||
| 261 | + "env variables BPFTRACE_KERNEL_SOURCE and, optionally, " | ||
| 262 | + "BPFTRACE_KERNEL_BUILD if the kernel was built in a " | ||
| 263 | + "different directory than its source. To create kernel " | ||
| 264 | + "headers run 'modprobe kheaders', which will create a tar " | ||
| 265 | + "file at /sys/kernel/kheaders.tar.xz"; | ||
| 266 | return std::make_tuple("", ""); | ||
| 267 | } | ||
| 268 | if (ksrc.empty()) { | ||
| 269 | diff --git a/src/utils.h b/src/utils.h | ||
| 270 | index 25dfa44b..9fa478fc 100644 | ||
| 271 | --- a/src/utils.h | ||
| 272 | +++ b/src/utils.h | ||
| 273 | @@ -175,8 +175,7 @@ std::vector<int> get_online_cpus(); | ||
| 274 | std::vector<int> get_possible_cpus(); | ||
| 275 | bool is_dir(const std::string &path); | ||
| 276 | std::tuple<std::string, std::string> get_kernel_dirs( | ||
| 277 | - const struct utsname &utsname, | ||
| 278 | - bool unpack_kheaders = true); | ||
| 279 | + const struct utsname &utsname); | ||
| 280 | std::vector<std::string> get_kernel_cflags(const char *uname_machine, | ||
| 281 | const std::string &ksrc, | ||
| 282 | const std::string &kobj, | ||
| 283 | -- | ||
| 284 | 2.44.1 | ||
diff --git a/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.20.1.bb b/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.20.1.bb index f0c29f4..37bf553 100644 --- a/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.20.1.bb +++ b/dynamic-layers/meta-python/recipes-devtools/bpftrace/bpftrace_0.20.1.bb | |||
| @@ -26,6 +26,7 @@ SRC_URI = "git://github.com/iovisor/bpftrace;branch=master;protocol=https \ | |||
| 26 | file://0001-use-64bit-alignment-for-map-counter-atomic-add.patch \ | 26 | file://0001-use-64bit-alignment-for-map-counter-atomic-add.patch \ |
| 27 | file://run-ptest \ | 27 | file://run-ptest \ |
| 28 | file://0001-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch \ | 28 | file://0001-CMakeLists.txt-allow-to-set-BISON_FLAGS-like-l.patch \ |
| 29 | file://CVE-2024-2313.patch \ | ||
| 29 | " | 30 | " |
| 30 | SRCREV = "fe6362b4e2c1b9d0833c7d3f308c1d4006b54723" | 31 | SRCREV = "fe6362b4e2c1b9d0833c7d3f308c1d4006b54723" |
| 31 | 32 | ||
