From: Serhei Makarov Date: Mon, 26 Oct 2020 17:41:04 +0000 (-0400) Subject: stapconf: adapt to kernel_read_file_from_path API change for v5.10-rc1 X-Git-Tag: release-4.4~41 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=c71391b24c518c58cdec30a71a121f51c13b3f55;p=systemtap.git stapconf: adapt to kernel_read_file_from_path API change for v5.10-rc1 The following kernel commit changed the get_user_pages_remote() function signature: commit 0fa8e084648779eeb8929ae004301b3acf3bad84 Author: Kees Cook Date: Fri Oct 2 10:38:25 2020 -0700 fs/kernel_file_read: Add "offset" arg for partial reads To perform partial reads, callers of kernel_read_file*() must have a non-NULL file_size argument and a preallocated buffer. The new "offset" argument can then be used to seek to specific locations in the file to fill the buffer to, at most, "buf_size" per call. Where possible, the LSM hooks can report whether a full file has been read or not so that the contents can be reasoned about. This and the preceding commits changed the function signature from: int kernel_read_file_from_path(const char *path, void **buf, loff_t *size, loff_t max_size, enum kernel_read_file_id id); to: int kernel_read_file_from_path(const char *path, loff_t offset, void **buf, size_t buf_size, size_t *file_size, enum kernel_read_file_id id); === XXX kernel commit b89999d004931ab2e51236 also split kernel_read_file_* functions into a separate header. As both changes were merged for v5.10-rc1 within the same day, we detect them with the same autoconf program. --- diff --git a/buildrun.cxx b/buildrun.cxx index 468139c91..7c5298682 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -421,6 +421,7 @@ compile_pass (systemtap_session& s) output_exportconf(s, o2, "PDE_DATA", "STAPCONF_PDE_DATA"); output_autoconf(s, o, cs, "autoconf-module-sect-attrs.c", "STAPCONF_MODULE_SECT_ATTRS", NULL); output_exportconf(s, o2, "kernel_read_file_from_path", "STAPCONF_KERNEL_READ_FILE_FROM_PATH"); + output_autoconf(s, o, cs, "autoconf-kernel_read_file_from_path-offset.c", "STAPCONF_KERNEL_READ_FILE_FROM_PATH_OFFSET", NULL); output_autoconf(s, o, cs, "autoconf-utrace-via-tracepoints.c", "STAPCONF_UTRACE_VIA_TRACEPOINTS", NULL); output_autoconf(s, o, cs, "autoconf-task_work-struct.c", "STAPCONF_TASK_WORK_STRUCT", NULL); output_autoconf(s, o, cs, "autoconf-vm-area-pte.c", "STAPCONF_VM_AREA_PTE", NULL); diff --git a/runtime/linux/autoconf-kernel_read_file_from_path-offset.c b/runtime/linux/autoconf-kernel_read_file_from_path-offset.c new file mode 100644 index 000000000..052e3305d --- /dev/null +++ b/runtime/linux/autoconf-kernel_read_file_from_path-offset.c @@ -0,0 +1,46 @@ +// +// The following kernel commit changed the get_user_pages_remote() +// function signature: +// +// commit 0fa8e084648779eeb8929ae004301b3acf3bad84 +// Author: Kees Cook +// Date: Fri Oct 2 10:38:25 2020 -0700 +// +// fs/kernel_file_read: Add "offset" arg for partial reads +// +// To perform partial reads, callers of kernel_read_file*() must have a +// non-NULL file_size argument and a preallocated buffer. The new "offset" +// argument can then be used to seek to specific locations in the file to +// fill the buffer to, at most, "buf_size" per call. +// +// Where possible, the LSM hooks can report whether a full file has been +// read or not so that the contents can be reasoned about. +// +// This and the preceding commits changed the function signature from: +// +// int kernel_read_file_from_path(const char *path, +// void **buf, loff_t *size, loff_t max_size, +// enum kernel_read_file_id id); +// +// to: +// +// int kernel_read_file_from_path(const char *path, loff_t offset, +// void **buf, size_t buf_size, +// size_t *file_size, +// enum kernel_read_file_id id); +// + +// XXX kernel commit b89999d004931ab2e51236 also split +// kernel_read_file_* functions into a separate header. +// +// As both changes were merged for v5.10-rc1 within the same day, +// we detect them with the same autoconf program: +#include + +int krffp_wrapper(const char *path, loff_t offset, + void **buf, size_t buf_size, + size_t *file_size, + enum kernel_read_file_id id) +{ + return kernel_read_file_from_path(path, offset, buf, buf_size, file_size, id); +} diff --git a/runtime/transport/symbols.c b/runtime/transport/symbols.c index db69f2b09..91102fcaf 100644 --- a/runtime/transport/symbols.c +++ b/runtime/transport/symbols.c @@ -14,6 +14,12 @@ #include "../sym.h" #include "relay_compat.h" +#ifdef STAPCONF_KERNEL_READ_FILE_FROM_PATH_OFFSET +// XXX kernel commit b89999d004931ab2e51236 for v5.10-rc1 split +// kernel_read_file_* functions into a separate header. +#include +#endif + #ifndef KERN_CONT #define KERN_CONT "" #endif @@ -158,15 +164,26 @@ read_sect_sysfs(const char* module, const char *section) int rc; unsigned long addr = 0; void *buffer = NULL; +#ifdef STAPCONF_KERNEL_READ_FILE_FROM_PATH_OFFSET + size_t size; +#else loff_t size; - +#endif + if (pathname == 0) goto out; rc = snprintf(pathname, PATH_MAX, "/sys/module/%s/sections/%s", module, section); if (rc >= PATH_MAX) goto out1; +#ifdef STAPCONF_KERNEL_READ_FILE_FROM_PATH_OFFSET + rc = kernel_read_file_from_path(pathname, 0 /* offset */, + &buffer, 64 /* max. bytes expected */, + &size /* file_size */, + READING_UNKNOWN); +#else rc = kernel_read_file_from_path(pathname, &buffer, &size, 64 /* max. bytes expected */, READING_UNKNOWN); +#endif if (rc <= 0) goto out1; rc = kstrtoul(buffer, 0, &addr);