Skip to content

Commit 8aa7545

Browse files
committed
krun: avoid failing if sev/nitro are not available
It's possible for a user to accidentally install the sev or nitro flavors of libkrun even if their system doesn't actually support those features. Before this change, having them installed on a system that doesn't support them would cause krun to stop working. Let's do the right thing and, if the bindings for "/dev/sev" or "/dev/nitro_enclaves" can't be created, close the handles to those library flavors and keep running with the generic one. If sev or nitro where really needed by the workload, it'll fail gracefully in "libkrun_configure_flavor". Fixes: #1120 #1300 Signed-off-by: Sergio Lopez <[email protected]>
1 parent 666ac73 commit 8aa7545

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libcrun/handlers/krun.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,24 @@ libkrun_configure_container (void *cookie, enum handler_configure_phase phase,
578578
{
579579
ret = libcrun_create_dev (container, devfd, -1, &sev_device, is_user_ns, true, err);
580580
if (UNLIKELY (ret < 0))
581-
return ret;
581+
{
582+
ret = dlclose (kconf->handle_sev);
583+
if (UNLIKELY (ret < 0))
584+
return ret;
585+
kconf->handle_sev = NULL;
586+
}
582587
}
583588

584589
if (create_nitro)
585590
{
586591
ret = libcrun_create_dev (container, devfd, -1, &nitro_device, is_user_ns, true, err);
587592
if (UNLIKELY (ret < 0))
588-
return ret;
593+
{
594+
ret = dlclose (kconf->handle_nitro);
595+
if (UNLIKELY (ret < 0))
596+
return ret;
597+
kconf->handle_nitro = NULL;
598+
}
589599
}
590600

591601
return 0;

0 commit comments

Comments
 (0)