Skip to content

Commit cc9d191

Browse files
committed
refactor: remove drop_privileges() and capability management from main.c
dvledtx delegates all VFIO and hugepage operations to mtl_init() inside the MTL library. Whether those operations require elevated privileges is purely a system configuration concern, not an application concern. With the recommended pre-configuration on the host: - udev rule granting the service user ownership of /dev/vfio/<group> - LimitMEMLOCK=infinity in the systemd unit (or /etc/security/limits.conf) mtl_init() succeeds without any elevated capabilities. The application should run as a plain unprivileged service user with no capability management needed. Removes: - drop_privileges() function and its E-1 comment block - #include <linux/capability.h> - #include <sys/prctl.h> - #include <sys/syscall.h> - #include <sys/mman.h> (unused after removal)
1 parent 7a366c2 commit cc9d191

1 file changed

Lines changed: 0 additions & 46 deletions

File tree

src/main.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
#include <stdio.h>
1111
#include <stdlib.h>
1212
#include <string.h>
13-
#include <sys/mman.h>
1413
#include <sys/stat.h>
1514
#include <unistd.h>
16-
#include <sys/prctl.h>
17-
#include <linux/capability.h>
18-
#include <sys/syscall.h>
1915
#include <limits.h>
2016

2117
/* libavdevice is only needed for the FFmpeg mtl_st20p muxer TX path */
@@ -52,44 +48,6 @@ static void dvledtx_apply_pending_signal_exit(void) {
5248
if (g_app_ptr != NULL) g_app_ptr->exit = true;
5349
}
5450

55-
/* =========================================================================
56-
* E-1: Privilege drop — reduce capabilities after DPDK/MTL initialisation.
57-
*
58-
* dvledtx requires CAP_SYS_ADMIN (VFIO) and CAP_IPC_LOCK (hugepages) during
59-
* mtl_init / session_manager_init. Once the NIC is bound and hugepages are
60-
* locked, drop to the minimal set so that any subsequent exploit (e.g. via
61-
* libavcodec) does not grant kernel-level access.
62-
* ========================================================================= */
63-
static void drop_privileges(void) {
64-
/* Keep only CAP_IPC_LOCK (for hugepages) and CAP_NET_ADMIN (NIC control).
65-
* Use the raw syscall interface to avoid linking libcap. */
66-
struct __user_cap_header_struct hdr = {
67-
.version = _LINUX_CAPABILITY_VERSION_3,
68-
.pid = 0 /* current process */
69-
};
70-
struct __user_cap_data_struct data[2];
71-
memset(data, 0, sizeof(data));
72-
73-
/* CAP_IPC_LOCK = 14, CAP_NET_ADMIN = 12 */
74-
uint32_t caps = (1U << 14) | (1U << 12);
75-
data[0].effective = caps;
76-
data[0].permitted = caps;
77-
data[0].inheritable = 0;
78-
data[1].effective = 0;
79-
data[1].permitted = 0;
80-
data[1].inheritable = 0;
81-
82-
/* Prevent regaining caps via execve */
83-
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
84-
85-
if (syscall(SYS_capset, &hdr, data) < 0) {
86-
LOG_WARN("drop_privileges: capset failed (errno=%d) — "
87-
"running with elevated privileges", errno);
88-
} else {
89-
LOG_INFO("Privileges dropped to CAP_NET_ADMIN+CAP_IPC_LOCK");
90-
}
91-
}
92-
9351
/* =========================================================================
9452
* E-5: Log file path validation — restrict to safe directories.
9553
*
@@ -333,10 +291,6 @@ int main(int argc, char** argv) {
333291
goto cleanup_logger;
334292
}
335293

336-
/* E-1: Drop elevated privileges — DPDK/MTL initialization is complete,
337-
* hugepages are locked, VFIO group is open. No longer need CAP_SYS_ADMIN. */
338-
drop_privileges();
339-
340294
/* Start transmission sessions */
341295
if (session_manager_start(&session_manager) < 0) {
342296
LOG_ERROR("Failed to start sessions");

0 commit comments

Comments
 (0)