Skip to content

Commit 8781b65

Browse files
rst0gitavagin
authored andcommitted
uffd: suggest vm.unprivileged_userfaultfd on EPERM
When restoring inside a user namespace on a host where userfaultfd is restricted to privileged callers, 'criu restore --lazy-pages' fails to open a userfaultfd descriptor with EPERM. This patch improves the error message to suggests how to fix this. Assisted-by: Claude Code:claude-opus-4-8 Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
1 parent 9e6a535 commit 8781b65

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

criu/uffd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ int uffd_open(int flags, unsigned long *features, int *err)
299299
int setup_uffd(int pid, struct task_restore_args *task_args)
300300
{
301301
unsigned long features = kdat.uffd_features & NEED_UFFD_API_FEATURES;
302+
int err = 0;
302303

303304
if (!opts.lazy_pages) {
304305
task_args->uffd = -1;
@@ -309,9 +310,14 @@ int setup_uffd(int pid, struct task_restore_args *task_args)
309310
* Open userfaulfd FD which is passed to the restorer blob and
310311
* to a second process handling the userfaultfd page faults.
311312
*/
312-
task_args->uffd = uffd_open(O_CLOEXEC | O_NONBLOCK, &features, NULL);
313+
task_args->uffd = uffd_open(O_CLOEXEC | O_NONBLOCK, &features, &err);
313314
if (task_args->uffd < 0) {
314-
pr_perror("Unable to open an userfaultfd descriptor");
315+
if (err)
316+
errno = err;
317+
pr_perror("Unable to open a userfaultfd descriptor");
318+
if (err == EPERM)
319+
pr_err("To use --lazy-pages, run with CAP_SYS_PTRACE in the root "
320+
"user namespace or set 'sysctl -w vm.unprivileged_userfaultfd=1'\n");
315321
return -1;
316322
}
317323

0 commit comments

Comments
 (0)