@@ -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
@@ -353,6 +358,9 @@ static void nl_parse(int fd, struct nlconfig_t *config)
353358 case SETGROUP_ATTR :
354359 config -> is_setgroup = readint8 (current );
355360 break ;
361+ case VTPMFD_ATTR :
362+ config -> vtpmfd = readint32 (current );
363+ break ;
356364 default :
357365 bail ("unknown netlink message type %d" , nlattr -> nla_type );
358366 }
@@ -431,12 +439,22 @@ void join_namespaces(char *nslist)
431439 free (namespaces );
432440}
433441
442+ void ima_namespace_set_vtpm (int vtpmfd )
443+ {
444+ int n = ioctl (vtpmfd , VTPM_PROXY_IOC_TRANSFER_IMA );
445+ /* ENOTTY: driver too old */
446+ if (n && n != ENOTTY ) {
447+ // bail("Error transferring VTPM to IMA: %s", strerror(errno));
448+ }
449+ }
450+
434451void nsexec (void )
435452{
436453 int pipenum ;
437454 jmp_buf env ;
438455 int sync_child_pipe [2 ], sync_grandchild_pipe [2 ];
439456 struct nlconfig_t config = {0 };
457+ config .vtpmfd = -1 ;
440458
441459 /*
442460 * If we don't have an init pipe, just return to the go routine.
@@ -713,6 +731,7 @@ void nsexec(void)
713731 if (config .namespaces )
714732 join_namespaces (config .namespaces );
715733
734+
716735 /*
717736 * Unshare all of the namespaces. Now, it should be noted that this
718737 * ordering might break in the future (especially with rootless
@@ -726,6 +745,8 @@ void nsexec(void)
726745 if (unshare (config .cloneflags ) < 0 )
727746 bail ("failed to unshare namespaces" );
728747
748+ if (config .vtpmfd > 0 )
749+ ima_namespace_set_vtpm (config .vtpmfd );
729750 /*
730751 * Deal with user namespaces first. They are quite special, as they
731752 * affect our ability to unshare other namespaces and are used as
0 commit comments