@@ -26,15 +26,22 @@ use crate::guest_restore::GuestRestoreRecord;
2626 feature = "cli" ,
2727 all( feature = "guest" , target_os = "linux" , target_arch = "x86_64" )
2828) ) ]
29- use self :: workload:: WorkloadIdentity ;
29+ use self :: workload:: { WORKLOAD_IDS , WorkloadIdentity } ;
3030
3131/// Shared identity data.
3232#[ cfg( any(
3333 feature = "cli" ,
3434 all( feature = "guest" , target_os = "linux" , target_arch = "x86_64" )
3535) ) ]
3636pub ( crate ) mod workload {
37- /// The identity that workloads run as: a non-root user and group ID.
37+ use std:: ops:: RangeInclusive ;
38+
39+ /// The user and group IDs that a workload may run as: not root, and not `-1` as `(uid_t)-1`
40+ /// and `(gid_t)-1`, which `setresuid` and `setresgid` read as "leave unchanged", so that
41+ /// accepting it would leave the workload's user or group root's.
42+ pub ( crate ) const WORKLOAD_IDS : RangeInclusive < u32 > = 1 ..=u32:: MAX - 1 ;
43+
44+ /// The identity that workloads run as: a user and group ID in [`WORKLOAD_IDS`].
3845 #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
3946 pub ( crate ) struct WorkloadIdentity {
4047 /// User ID.
@@ -269,13 +276,13 @@ pub(crate) fn decode_activation_record(
269276 Ok ( ( record, workload) )
270277}
271278
272- /// Matches the guest 's non-root credential range, excluding the unchanged-ID sentinel .
279+ /// Checks that the workload 's UID and GID both lie in [`WORKLOAD_IDS`] .
273280#[ cfg( any(
274281 feature = "cli" ,
275282 all( feature = "guest" , target_os = "linux" , target_arch = "x86_64" )
276283) ) ]
277284fn check_workload_identity ( workload : & WorkloadIdentity ) -> Result < ( ) , ProtocolError > {
278- if matches ! ( workload. uid, 0 | u32 :: MAX ) || matches ! ( workload. gid, 0 | u32 :: MAX ) {
285+ if ! WORKLOAD_IDS . contains ( & workload. uid ) || ! WORKLOAD_IDS . contains ( & workload. gid ) {
279286 return Err ( violation (
280287 "activation workload requires a non-root UID and GID below u32::MAX" ,
281288 ) ) ;
0 commit comments