@@ -586,6 +586,49 @@ int xccdf_set_profile_or_report_bad_id(struct xccdf_session *session, const char
586586 return return_code ;
587587}
588588
589+
590+ static bool _system_is_in_bootc_mode (void )
591+ {
592+ #ifdef OS_WINDOWS
593+ return false;
594+ #else
595+ #define BOOTC_PATH "/usr/bin/bootc"
596+ #define CHUNK_SIZE 1024
597+ struct stat statbuf ;
598+ if (stat (BOOTC_PATH , & statbuf ) == -1 ) {
599+ return false;
600+ }
601+ FILE * output = popen (BOOTC_PATH " status --format json 2>/dev/null" , "r" );
602+ if (output == NULL ) {
603+ return false;
604+ }
605+ size_t buf_size = CHUNK_SIZE ;
606+ char * buf = calloc (buf_size , sizeof (char ));
607+ if (buf == NULL ) {
608+ pclose (output );
609+ return false;
610+ }
611+ int c ;
612+ size_t i = 0 ;
613+ while ((c = fgetc (output )) != EOF ) {
614+ if (i >= buf_size ) {
615+ buf_size += CHUNK_SIZE ;
616+ char * new_buf = realloc (buf , buf_size );
617+ if (new_buf == NULL ) {
618+ pclose (output );
619+ return false;
620+ }
621+ buf = new_buf ;
622+ }
623+ buf [i ++ ] = c ;
624+ }
625+ pclose (output );
626+ bool result = (* buf != '\0' && strstr (buf , "\"booted\":null" ) == NULL );
627+ free (buf );
628+ return result ;
629+ #endif
630+ }
631+
589632/**
590633 * XCCDF Processing fucntion
591634 * @param action OSCAP Action structure
@@ -596,6 +639,16 @@ int app_evaluate_xccdf(const struct oscap_action *action)
596639 struct xccdf_session * session = NULL ;
597640
598641 int result = OSCAP_ERROR ;
642+
643+ if (action -> remediate && _system_is_in_bootc_mode ()) {
644+ fprintf (stderr ,
645+ "Detected running Image Mode operating system. OpenSCAP can't "
646+ "perform remediation of this system because majority of the "
647+ "system is read-only. Please apply remediation during bootable "
648+ "container image build using 'oscap-im' instead.\n" );
649+ return result ;
650+ }
651+
599652#if defined(HAVE_SYSLOG_H )
600653 int priority = LOG_NOTICE ;
601654
@@ -797,6 +850,14 @@ int app_xccdf_remediate(const struct oscap_action *action)
797850{
798851 struct xccdf_session * session = NULL ;
799852 int result = OSCAP_ERROR ;
853+ if (_system_is_in_bootc_mode ()) {
854+ fprintf (stderr ,
855+ "Detected running Image Mode operating system. OpenSCAP can't "
856+ "perform remediation of this system because majority of the "
857+ "system is read-only. Please apply remediation during bootable "
858+ "container image build using 'oscap-im' instead.\n" );
859+ return result ;
860+ }
800861 session = xccdf_session_new (action -> f_xccdf );
801862 if (session == NULL )
802863 goto cleanup ;
0 commit comments