Skip to content

Commit 3be4922

Browse files
committed
tpm: ima: Implement vTPM connect to IMA
Signed-off-by: Stefan Berger <[email protected]>
1 parent e2e79b7 commit 3be4922

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
@@ -1640,6 +1640,15 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na
16401640
Value: uint32(cloneFlags),
16411641
})
16421642

1643+
// write vTPM file descriptor
1644+
if len(c.config.VTPMs) > 0 {
1645+
vtpmfd := c.config.VTPMs[0].GetAnonFD()
1646+
r.AddData(&Int32msg{
1647+
Type: VTpmFDAttr,
1648+
Value: uint32(vtpmfd),
1649+
})
1650+
}
1651+
16431652
// write custom namespace paths
16441653
if len(nsMaps) > 0 {
16451654
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
@@ -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+
434451
void 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

Comments
 (0)