diff --git a/go.mod b/go.mod index e3b455a..0a2aeb8 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/transparency-dev/armored-witness-common v0.0.0-20240313170947-0b19d0fb8b95 github.com/transparency-dev/merkle v0.0.2 github.com/transparency-dev/serverless-log v0.0.0-20231215122707-66f68a7705f5 - github.com/usbarmory/GoTEE v0.0.0-20240215171108-77a6b38432d5 + github.com/usbarmory/GoTEE v0.0.0-20240314122327-40179239ad36 github.com/usbarmory/armory-boot v0.0.0-20230922092524-e66d926bc36c github.com/usbarmory/crucible v0.0.0-20240221192724-1595f2219655 github.com/usbarmory/imx-usbnet v0.0.0-20240304152630-ca189bf3b3c1 diff --git a/go.sum b/go.sum index 7087809..c1e3da0 100644 --- a/go.sum +++ b/go.sum @@ -70,6 +70,8 @@ github.com/u-root/u-root v0.11.0 h1:6gCZLOeRyevw7gbTwMj3fKxnr9+yHFlgF3N7udUVNO8= github.com/u-root/u-root v0.11.0/go.mod h1:DBkDtiZyONk9hzVEdB/PWI9B4TxDkElWlVTHseglrZY= github.com/usbarmory/GoTEE v0.0.0-20240215171108-77a6b38432d5 h1:XJjhY/+my6o+h4hll02s7rMJrNtI2XqQBBcrx7Lp/2U= github.com/usbarmory/GoTEE v0.0.0-20240215171108-77a6b38432d5/go.mod h1:YlZVucqxy/z5QWKerml3Vm5T14UOzZEs2kXfS1nilx8= +github.com/usbarmory/GoTEE v0.0.0-20240314122327-40179239ad36 h1:rZfhjJpgKuwos6KBdHKouDJmYmpV/FJv4q34eIjtPjw= +github.com/usbarmory/GoTEE v0.0.0-20240314122327-40179239ad36/go.mod h1:YlZVucqxy/z5QWKerml3Vm5T14UOzZEs2kXfS1nilx8= github.com/usbarmory/armory-boot v0.0.0-20230922092524-e66d926bc36c h1:qQL3CljMNrk9TyG8EUvCAPU7/bTVitJMhqlKSNhskis= github.com/usbarmory/armory-boot v0.0.0-20230922092524-e66d926bc36c/go.mod h1:20DIzHJntbLDOptGT7TOm8DkT5mL2jRyzPzVXAYVHJ8= github.com/usbarmory/crucible v0.0.0-20240221192724-1595f2219655 h1:n3JkWqsxKsbX2SKy+ac3v2rgEmTWfA/s0SC5kHlJGBY= diff --git a/trusted_os/net.go b/trusted_os/net.go index 4ac9b16..97d92a3 100644 --- a/trusted_os/net.go +++ b/trusted_os/net.go @@ -15,7 +15,7 @@ package main import ( - "errors" + "fmt" "net" "github.com/usbarmory/tamago/soc/nxp/enet" @@ -71,36 +71,39 @@ func asyncTx() (buf []byte) { } func rxFromApplet(ctx *monitor.ExecCtx) (err error) { - var n uint - select { case buf := <-rxQueue: - off := ctx.A1() - ctx.Memory.Start() - n = uint(len(buf)) + off, n, err := ctx.TransferRegion() - if !(off >= 0 && off < (ctx.Memory.Size()-n)) { - return errors.New("invalid offset") + if err != nil { + return err } - ctx.Memory.Write(ctx.Memory.Start(), int(off), buf) + r := len(buf) + + if r > n { + return fmt.Errorf("invalid transfer size (%d > %d)", r, n) + } + + ctx.Memory.Write(ctx.Memory.Start(), off, buf) + ctx.Ret(r) default: + ctx.Ret(0) } - ctx.Ret(n) - return } func txFromApplet(ctx *monitor.ExecCtx) (err error) { - off := ctx.A1() - ctx.Memory.Start() - n := ctx.A2() - buf := make([]byte, n) + off, n, err := ctx.TransferRegion() - if !(off >= 0 && off < (ctx.Memory.Size()-uint(n))) { - return errors.New("invalid offset") + if err != nil { + return } - ctx.Memory.Read(ctx.Memory.Start(), int(off), buf) + buf := make([]byte, n) + + ctx.Memory.Read(ctx.Memory.Start(), off, buf) switch { case LAN != nil: