Skip to content

Commit de966f3

Browse files
committed
tpm: Use the host device name inside the container
The host device name has to be used inside the container for the major and minor numbers to appear correctly. Signed-off-by: Stefan Berger <[email protected]>
1 parent a1ef4eb commit de966f3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

libcontainer/vtpm/vtpm-helper/vtpm_helper.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"github.com/opencontainers/runtime-spec/specs-go"
1515
)
1616

17-
func addVTPMDevice(spec *specs.Spec, config *configs.Config, devpath string, major, minor uint32) {
17+
func addVTPMDevice(spec *specs.Spec, config *configs.Config, hostpath string, major, minor uint32) {
1818
device := &configs.Device{
1919
Type: 'c',
20-
Path: devpath,
20+
Path: hostpath,
2121
Major: int64(major),
2222
Minor: int64(minor),
2323
Permissions: "rwm",
@@ -62,8 +62,7 @@ func CreateVTPM(spec *specs.Spec, config *configs.Config, vtpmdev *specs.VTPM, d
6262
hostdev := vtpm.GetTPMDevname()
6363
major, minor := vtpm.GetMajorMinor()
6464

65-
devpath := fmt.Sprintf("/dev/tpm%d", devnum)
66-
addVTPMDevice(spec, config, devpath, major, minor)
65+
addVTPMDevice(spec, config, hostdev, major, minor)
6766

6867
config.VTPMs = append(config.VTPMs, vtpm)
6968

@@ -80,8 +79,7 @@ func CreateVTPM(spec *specs.Spec, config *configs.Config, vtpmdev *specs.VTPM, d
8079
if fileInfo, err := os.Lstat(host_tpmrm); err == nil {
8180
if stat_t, ok := fileInfo.Sys().(*syscall.Stat_t); ok {
8281
devNumber := int(stat_t.Rdev)
83-
devpath = fmt.Sprintf("/dev/tpmrm%d", devnum)
84-
addVTPMDevice(spec, config, devpath, uint32(devices.Major(devNumber)), uint32(devices.Minor(devNumber)))
82+
addVTPMDevice(spec, config, host_tpmrm, uint32(devices.Major(devNumber)), uint32(devices.Minor(devNumber)))
8583
}
8684
if uid != 0 {
8785
// adapt ownership of the device since only root can access it

0 commit comments

Comments
 (0)