@@ -75,8 +75,12 @@ struct nlconfig_t {
7575 uint8_t is_rootless ;
7676 char * oom_score_adj ;
7777 size_t oom_score_adj_len ;
78+ int32_t vtpmfd ;
7879};
7980
81+ /* ioctl for vtpm proxy device */
82+ #define VTPM_PROXY_IOC_TRANSFER_IMA _IO(0xa1, 0x10)
83+
8084/*
8185 * List of netlink message types sent to us as part of bootstrapping the init.
8286 * These constants are defined in libcontainer/message_linux.go.
@@ -89,6 +93,7 @@ struct nlconfig_t {
8993#define SETGROUP_ATTR 27285
9094#define OOM_SCORE_ADJ_ATTR 27286
9195#define ROOTLESS_ATTR 27287
96+ #define VTPMFD_ATTR 27288
9297
9398/*
9499 * Use the raw syscall for versions of glibc which don't include a function for
@@ -354,6 +359,9 @@ static void nl_parse(int fd, struct nlconfig_t *config)
354359 case SETGROUP_ATTR :
355360 config -> is_setgroup = readint8 (current );
356361 break ;
362+ case VTPMFD_ATTR :
363+ config -> vtpmfd = readint32 (current );
364+ break ;
357365 default :
358366 bail ("unknown netlink message type %d" , nlattr -> nla_type );
359367 }
@@ -432,12 +440,22 @@ void join_namespaces(char *nslist)
432440 free (namespaces );
433441}
434442
443+ void ima_namespace_set_vtpm (int vtpmfd )
444+ {
445+ int n = ioctl (vtpmfd , VTPM_PROXY_IOC_TRANSFER_IMA );
446+ /* ENOTTY: driver too old */
447+ if (n && n != ENOTTY ) {
448+ // bail("Error transferring VTPM to IMA: %s", strerror(errno));
449+ }
450+ }
451+
435452void nsexec (void )
436453{
437454 int pipenum ;
438455 jmp_buf env ;
439456 int sync_child_pipe [2 ], sync_grandchild_pipe [2 ];
440457 struct nlconfig_t config = {0 };
458+ config .vtpmfd = -1 ;
441459
442460 /*
443461 * If we don't have an init pipe, just return to the go routine.
@@ -709,6 +727,7 @@ void nsexec(void)
709727 if (config .namespaces )
710728 join_namespaces (config .namespaces );
711729
730+
712731 /*
713732 * Unshare all of the namespaces. Now, it should be noted that this
714733 * ordering might break in the future (especially with rootless
@@ -722,6 +741,8 @@ void nsexec(void)
722741 if (unshare (config .cloneflags ) < 0 )
723742 bail ("failed to unshare namespaces" );
724743
744+ if (config .vtpmfd > 0 )
745+ ima_namespace_set_vtpm (config .vtpmfd );
725746 /*
726747 * Deal with user namespaces first. They are quite special, as they
727748 * affect our ability to unshare other namespaces and are used as
0 commit comments