@@ -1668,6 +1668,28 @@ reset_failed_unit (sd_bus *bus, const char *unit)
1668
1668
return sd_err ;
1669
1669
}
1670
1670
1671
+ static int
1672
+ verify_ebpf_device_filter_installed (const char * cgroup_path , libcrun_error_t * err )
1673
+ {
1674
+ cleanup_free uint32_t * progs = NULL ;
1675
+ cleanup_free char * full_path = NULL ;
1676
+ size_t n_progs = 0 ;
1677
+ int ret ;
1678
+
1679
+ ret = append_paths (& full_path , err , CGROUP_ROOT , cgroup_path , NULL );
1680
+ if (UNLIKELY (ret < 0 ))
1681
+ return ret ;
1682
+
1683
+ ret = libcrun_ebpf_query_cgroup_progs (full_path , & progs , & n_progs , err );
1684
+ if (UNLIKELY (ret < 0 ))
1685
+ return ret ;
1686
+
1687
+ if (n_progs == 0 )
1688
+ return crun_make_error (err , 0 , "systemd failed to install eBPF device filter on cgroup `%s`" , full_path );
1689
+
1690
+ return 0 ;
1691
+ }
1692
+
1671
1693
static int
1672
1694
enter_systemd_cgroup_scope (runtime_spec_schema_config_linux_resources * resources ,
1673
1695
int cgroup_mode ,
@@ -2023,6 +2045,30 @@ libcrun_cgroup_enter_systemd (struct libcrun_cgroup_args *args,
2023
2045
if (UNLIKELY (ret < 0 ))
2024
2046
return ret ;
2025
2047
2048
+ /* Verify that systemd has actually installed the eBPF device filter if one was requested. */
2049
+ if (out -> bpf_dev_set )
2050
+ {
2051
+ cleanup_free char * scope_path = NULL ;
2052
+
2053
+ /* eBPF programs are attached to the systemd scope, not the subgroup.
2054
+ Remove the suffix that was added by systemd_finalize. */
2055
+ if (is_empty_string (suffix ))
2056
+ scope_path = xstrdup (path );
2057
+ else
2058
+ {
2059
+ size_t path_len = strlen (path );
2060
+ size_t suffix_len = strlen (suffix );
2061
+
2062
+ scope_path = strndup (path , path_len - suffix_len - 1 );
2063
+ if (UNLIKELY (scope_path == NULL ))
2064
+ OOM ();
2065
+ }
2066
+
2067
+ ret = verify_ebpf_device_filter_installed (scope_path , err );
2068
+ if (UNLIKELY (ret < 0 ))
2069
+ return ret ;
2070
+ }
2071
+
2026
2072
out -> path = path ;
2027
2073
path = NULL ;
2028
2074
0 commit comments