Skip to content

Commit

Permalink
krun: fix CVE-2025-24965
Browse files Browse the repository at this point in the history
make sure the opened .krun_config.json is below the rootfs directory
and we don't follow any symlink.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 4, 2025
1 parent 793188c commit 0aec82c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/libcrun/handlers/krun.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
/* libkrun has a hard-limit of 8 vCPUs per microVM. */
#define LIBKRUN_MAX_VCPUS 8

#define KRUN_CONFIG_FILE ".krun_config.json"

struct krun_config
{
void *handle;
Expand Down Expand Up @@ -208,7 +210,13 @@ libkrun_configure_container (void *cookie, enum handler_configure_phase phase,
if (UNLIKELY (ret < 0))
return ret;

ret = write_file_at (rootfsfd, ".krun_config.json", config, config_size, err);
/* CVE-2025-24965: the content below rootfs cannot be trusted because it is controlled by the user. We
must ensure the file is opened below the rootfs directory. */
fd = safe_openat (rootfsfd, rootfs, KRUN_CONFIG_FILE, WRITE_FILE_DEFAULT_FLAGS | O_NOFOLLOW, 0700, err);
if (UNLIKELY (fd < 0))
return fd;

ret = safe_write (fd, KRUN_CONFIG_FILE, config, config_size, err);
if (UNLIKELY (ret < 0))
return ret;
}
Expand Down

3 comments on commit 0aec82c

@fossdd
Copy link

@fossdd fossdd commented on 0aec82c Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any public information about this CVE. E.g. https://www.cve.org/CVERecord?id=CVE-2025-24965

Where can I learn more about the CVE?

@giuseppe
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

details are not public yet.

I'll publish the Security Advisory once distros had enough time to upgrade the package

@giuseppe
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it affects only krun though (crun must be compiled with ./configure --with-libkrun). AFAICS, that is not present on Alpine so shouldn't be affected

Please sign in to comment.