diff --git a/driver/main.c b/driver/main.c index b6714887da..870fbd5c02 100644 --- a/driver/main.c +++ b/driver/main.c @@ -2628,10 +2628,38 @@ void sysdig_exit(void) #endif } +static int set_ring_buf_size(const char *val, const struct kernel_param *kp) +{ + int n = 0, ret; + + ret = kstrtoint(val, 10, &n); + if (ret != 0) + return -EINVAL; + else if (n < 2 * PAGE_SIZE) { + pr_err("Ring buffer size too small (%ld bytes, must be at least %ld bytes)\n", + (long)n, + (long)PAGE_SIZE * 2); + return -EINVAL; + } + else if (n / PAGE_SIZE * PAGE_SIZE != n) { + pr_err("Ring buffer size is not a multiple of the page size\n"); + return -EINVAL; + } + + return param_set_int(val, kp); +} + +static const struct kernel_param_ops ring_buf_size_param_ops = { + .set = set_ring_buf_size, + .get = param_get_int, +}; + module_init(sysdig_init); module_exit(sysdig_exit); module_param(max_consumers, uint, 0444); MODULE_PARM_DESC(max_consumers, "Maximum number of consumers that can simultaneously open the devices"); +module_param_cb(ring_buf_size, &ring_buf_size_param_ops, &ring_buf_size, 0660); +MODULE_PARM_DESC(ring_buf_size, "Size of the ring buffer containing syscall"); #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20) module_param(verbose, bool, 0444); #endif diff --git a/userspace/libscap/scap.c b/userspace/libscap/scap.c index 1c2857d51d..477384ce56 100644 --- a/userspace/libscap/scap.c +++ b/userspace/libscap/scap.c @@ -323,6 +323,15 @@ scap_t* scap_open_live_int(char *error, int32_t *rc, // // Allocate the device descriptors. // + + FILE * fp = fopen("/sys/module/" SYSFS_NAME "/parameters/ring_buf_size", "r"); + if (fp == NULL){ + snprintf(error, SCAP_LASTERR_SIZE, "Could not read module parameter ring_buf_size at '/sys/module/" SYSFS_NAME "/parameters/ring_buf_size'"); + *rc = SCAP_FAILURE; + return NULL; + } + fscanf(fp, "%d", &ring_buf_size); + len = ring_buf_size * 2; for(j = 0, all_scanned_devs = 0; j < handle->m_ndevs && all_scanned_devs < handle->m_ncpus; ++all_scanned_devs)