@@ -104,6 +104,10 @@ struct nlconfig_t {
104104 /* Idmap sources opened outside the container userns which will be id mapped. */
105105 char * idmapsources ;
106106 size_t idmapsources_len ;
107+
108+ /* Time NS offsets. */
109+ char * timensoffset ;
110+ size_t timensoffset_len ;
107111};
108112
109113/*
@@ -122,6 +126,8 @@ struct nlconfig_t {
122126#define GIDMAPPATH_ATTR 27289
123127#define MOUNT_SOURCES_ATTR 27290
124128#define IDMAP_SOURCES_ATTR 27291
129+ #define TIMENSOFFSET_ATTR 27292
130+
125131
126132/*
127133 * Use the raw syscall for versions of glibc which don't include a function for
@@ -351,6 +357,8 @@ static int nsflag(char *name)
351357 return CLONE_NEWUSER ;
352358 else if (!strcmp (name , "uts" ))
353359 return CLONE_NEWUTS ;
360+ else if (!strcmp (name , "time" ))
361+ return CLONE_NEWTIME ;
354362
355363 /* If we don't recognise a name, fallback to 0. */
356364 return 0 ;
@@ -444,6 +452,9 @@ static void nl_parse(int fd, struct nlconfig_t *config)
444452 case IDMAP_SOURCES_ATTR :
445453 config -> idmapsources = current ;
446454 config -> idmapsources_len = payload_len ;
455+ case TIMENSOFFSET_ATTR :
456+ config -> timensoffset = current ;
457+ config -> timensoffset_len = payload_len ;
447458 break ;
448459 default :
449460 bail ("unknown netlink message type %d" , nlattr -> nla_type );
@@ -747,6 +758,17 @@ void receive_idmapsources(int sockfd)
747758 receive_fd_sources (sockfd , "_LIBCONTAINER_IDMAP_FDS" );
748759}
749760
761+ static void update_timens (char * map , size_t map_len )
762+ {
763+ if (map == NULL || map_len == 0 )
764+ return ;
765+ write_log (DEBUG , "update /proc/self/timens_offsets to '%s'" , map );
766+ if (write_file (map , map_len , "/proc/self/timens_offsets" ) < 0 ) {
767+ if (errno != EPERM )
768+ bail ("failed to update /proc/self/timens_offsets" );
769+ }
770+ }
771+
750772void nsexec (void )
751773{
752774 int pipenum ;
@@ -1185,6 +1207,11 @@ void nsexec(void)
11851207 bail ("failed to sync with parent: SYNC_MOUNT_IDMAP_ACK: got %u" , s );
11861208 }
11871209
1210+ /*
1211+ * set boottime and monotonic timens offsets.
1212+ */
1213+ update_timens (config .timensoffset , config .timensoffset_len );
1214+
11881215 /*
11891216 * TODO: What about non-namespace clone flags that we're dropping here?
11901217 *
0 commit comments