فهرست منبع

main: Check memlock rlimit

Don't lock all current and future memory if can't
increase memlock rlimit.

If we fail to increase our RLIMIT_MEMLOCK, then locking all our current
and future memory is extremely dangerous; once our memory use reaches
our RLIMIT_MEMLOCK, memory allocations will start failing, very likely
leading to our entire process crashing.

This can happen if we aren't a privileged process, for example if
running as non-root user, or inside an unprivileged container.

Signed-off-by: Dan Streetman <ddstreet@canonical.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
Dan Streetman 5 سال پیش
والد
کامیت
2d29f68e66
1فایلهای تغییر یافته به همراه6 افزوده شده و 1 حذف شده
  1. 6 1
      exec/main.c

+ 6 - 1
exec/main.c

@@ -475,7 +475,12 @@ static void corosync_mlockall (void)
 #define RLIMIT_MEMLOCK RLIMIT_VMEM
 #define RLIMIT_MEMLOCK RLIMIT_VMEM
 #endif
 #endif
 
 
-	setrlimit (RLIMIT_MEMLOCK, &rlimit);
+	res = setrlimit (RLIMIT_MEMLOCK, &rlimit);
+	if (res == -1) {
+		LOGSYS_PERROR (errno, LOGSYS_LEVEL_WARNING,
+			"Could not increase RLIMIT_MEMLOCK, not locking memory");
+		return;
+	}
 
 
 	res = mlockall (MCL_CURRENT | MCL_FUTURE);
 	res = mlockall (MCL_CURRENT | MCL_FUTURE);
 	if (res == -1) {
 	if (res == -1) {