Skip to content

Commit 04f9e62

Browse files
committed
tpm: ima: Implement vTPM connect to IMA
Signed-off-by: Stefan Berger <[email protected]>
1 parent 820cf9d commit 04f9e62

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

libcontainer/container_linux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,15 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na
15081508
Value: uint32(cloneFlags),
15091509
})
15101510

1511+
// write vTPM file descriptor
1512+
if len(c.config.VTPMs) > 0 {
1513+
vtpmfd := c.config.VTPMs[0].GetAnonFD()
1514+
r.AddData(&Int32msg{
1515+
Type: VTpmFDAttr,
1516+
Value: uint32(vtpmfd),
1517+
})
1518+
}
1519+
15111520
// write custom namespace paths
15121521
if len(nsMaps) > 0 {
15131522
nsPaths, err := c.orderNamespacePaths(nsMaps)

libcontainer/message_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
SetgroupAttr uint16 = 27285
1919
OomScoreAdjAttr uint16 = 27286
2020
RootlessAttr uint16 = 27287
21+
VTpmFDAttr uint16 = 27288
2122
)
2223

2324
type Int32msg struct {

libcontainer/nsenter/nsexec.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
435452
void 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

Comments
 (0)