[Devel] [PATCH RH8] ve/perf: forbid perf events syscall in containers

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Sep 1 18:57:34 MSK 2020


If some process has perf_event_open fd it can monitor different (kernel,
hardware, etc) perfomance counters through it. And this fd is configured
through perf_event_attr which has more than 30 fields. There is
currently no kernel interface to get the configuration of existing perf
event fd. So to dump such an fd with CRIU we should add this interface.

We have ovs-vswitchd, which opens perf event fd and does nothing with it
according to comments, it is only used in case someone will use PERF()
macros to debug some code parts which implies recompilation of ovs. But
it is still a problem on migration because CRIU detects this fd and
fails. Also ovs can handle if it can't open perf event fd and fallbacks
gracefully to work without it.

So (at least for now) we should forbid this interface, to fix problems
with ovs daemon migration.

https://jira.sw.ru/browse/PSBM-107217

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/events/core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index bb130a5cbee5..db135b096c0a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -50,6 +50,7 @@
 #include <linux/sched/mm.h>
 #include <linux/proc_ns.h>
 #include <linux/mount.h>
+#include <linux/ve.h>
 
 #include "internal.h"
 
@@ -10412,6 +10413,9 @@ SYSCALL_DEFINE5(perf_event_open,
 	if (flags & ~PERF_FLAG_ALL)
 		return -EINVAL;
 
+	if (!ve_is_super(get_exec_env()))
+		return -EACCES;
+
 	err = perf_copy_attr(attr_uptr, &attr);
 	if (err)
 		return err;
-- 
2.24.1



More information about the Devel mailing list