Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions utils/oscap-xccdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,43 @@ int xccdf_set_profile_or_report_bad_id(struct xccdf_session *session, const char
return return_code;
}


static bool _system_is_in_bootc_mode(void)
{
#ifdef OS_WINDOWS
return false;
#else
#define BOOTC_PATH "/usr/bin/bootc"
#define CHUNK_SIZE 1024
struct stat statbuf;
if (stat(BOOTC_PATH, &statbuf) == -1) {
return false;
}
FILE *output = popen(BOOTC_PATH " status --format json 2>/dev/null", "r");
if (output == NULL) {
return false;
}
size_t buf_size = CHUNK_SIZE;
char *buf = calloc(buf_size, sizeof(char));
Comment thread
matusmarhefka marked this conversation as resolved.
int c;
size_t i = 0;
while ((c = fgetc(output)) != EOF) {
if (i >= buf_size) {
buf_size += CHUNK_SIZE;
char *new_buf = realloc(buf, buf_size);
if (new_buf == NULL) {
pclose(output);
return false;
}
buf = new_buf;
}
buf[i++] = c;
}
pclose(output);
return *buf != '\0' && strstr(buf, "\"booted\":null") == NULL;
Comment thread
matusmarhefka marked this conversation as resolved.
Outdated
#endif
}

/**
* XCCDF Processing fucntion
* @param action OSCAP Action structure
Expand All @@ -596,6 +633,16 @@ int app_evaluate_xccdf(const struct oscap_action *action)
struct xccdf_session *session = NULL;

int result = OSCAP_ERROR;

if (action->remediate && _system_is_in_bootc_mode()) {
fprintf(stderr,
"Detected running Image Mode operating system. OpenSCAP can't "
"perform remediation of this system because majority of the "
"system is read-only. Please apply remediation during bootable "
"container image build using 'oscap-im' instead.\n");
return result;
}

#if defined(HAVE_SYSLOG_H)
int priority = LOG_NOTICE;

Expand Down Expand Up @@ -797,6 +844,14 @@ int app_xccdf_remediate(const struct oscap_action *action)
{
struct xccdf_session *session = NULL;
int result = OSCAP_ERROR;
if (_system_is_in_bootc_mode()) {
fprintf(stderr,
"Detected running Image Mode operating system. OpenSCAP can't "
"perform remediation of this system because majority of the "
"system is read-only. Please apply remediation during bootable "
"container image build using 'oscap-im' instead.\n");
return result;
}
session = xccdf_session_new(action->f_xccdf);
if (session == NULL)
goto cleanup;
Expand Down