Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the actual number of bytes written to through command buffer #287

Merged
merged 2 commits into from
Mar 14, 2023

Conversation

hslatman
Copy link
Contributor

The Write function returned the number of bytes written to the internal command response buffer. Depending on the type of command executed against the TPM, this would usually result in a different number of bytes being written than the original input.

The fix is useful if one wants to wrap the io.ReadWriterCloser functions with implementations that perform strict checks. An example is using an io.MultiWriter to capture the bytes sent to the TPM for debugging purposes, which will fail if the number of bytes written does not equal the original length of the input bytes.

The `Write` function returned the number of bytes written to the
internal command response buffer in the simulator. Depending on the
type of command executed against the TPM, this would usually result
in a different number of bytes being written than the original input.

The fix is useful if one wants to wrap the io.ReadWriterCloser
functions with implementations that perform strict checks. An example
is using an io.MultiWriter to capture the bytes sent to the TPM for
debugging purposes, which will fail if the number of bytes written
does not equal the original length of the input bytes.
@jkl73 jkl73 requested a review from josephlr March 9, 2023 01:06
Copy link
Member

@josephlr josephlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I'm surprised it took so long for us to catch this.

Comment on lines 113 to 118
if err != nil {
return 0, err
}
if n != len(resp) {
return 0, fmt.Errorf("expected %d bytes to be written to command response buffer, but actual number is %d", len(resp), n)
}
Copy link
Member

@josephlr josephlr Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this error checking here, bytes.Buffer will always return a nil error and a length of the input buffer (see https://pkg.go.dev/bytes#Buffer.Write).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice 😄 Fixed in 63181f2.

@josephlr
Copy link
Member

josephlr commented Mar 9, 2023

/gcbrun

@hslatman hslatman requested a review from josephlr March 13, 2023 11:08
@josephlr josephlr merged commit 9e791b1 into google:master Mar 14, 2023
alexmwu added a commit to alexmwu/go-tpm-tools that referenced this pull request Apr 7, 2023
Use region in spec to create attestation service rest client google#281
Parse EFI App state from the TCG event log google#277

Increase default systemd wait timeout to 900s google#276
Use same env var formatting logic on the launcher as server google#253
Fix image pulling in launcher google#282
Bump version and fix a kernel cmd issue google#291
Return the actual number of bytes written to through command buffer google#287
Fix lint issues after using golangci-lint-1.52.2 google#296

Add image tests and test automation google#275
Update go-sev-guest to v0.4.2 google#278
Update to go-sev-guest v0.4.5 google#279
Add proper debug license and logging to launcher google#280
Upgrade to go-sev-guest v0.5.0 google#283
Import go-sev-guest v0.5.2 google#284
Add override test for workload env vars and cmd google#286
Add test workload code, check OIDC claims, and validate launch policy checks google#288
Bump golang.org/x/net in /launcher google#290
Add RELEASING instructions google#187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
alexmwu added a commit to alexmwu/go-tpm-tools that referenced this pull request Apr 7, 2023
Breaking Changes:

New Features:
Use region in spec to create attestation service rest client google#281
Parse EFI App state from the TCG event log google#277

Bug Fixes:
Increase default systemd wait timeout to 900s google#276
Use same env var formatting logic on the launcher as server google#253
Fix image pulling in launcher google#282
Bump version and fix a kernel cmd issue google#291
Return the actual number of bytes written to through command buffer google#287
Fix lint issues after using golangci-lint-1.52.2 google#296

Other Changes:
Add image tests and test automation google#275
Update go-sev-guest to v0.4.2 google#278
Update to go-sev-guest v0.4.5 google#279
Add proper debug license and logging to launcher google#280
Upgrade to go-sev-guest v0.5.0 google#283
Import go-sev-guest v0.5.2 google#284
Add override test for workload env vars and cmd google#286
Add test workload code, check OIDC claims, and validate launch policy checks google#288
Bump golang.org/x/net in /launcher google#290
Add RELEASING instructions google#187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
@alexmwu alexmwu mentioned this pull request Apr 7, 2023
alexmwu added a commit that referenced this pull request Apr 7, 2023
Breaking Changes:

New Features:
Use region in spec to create attestation service rest client #281
Parse EFI App state from the TCG event log #277

Bug Fixes:
Increase default systemd wait timeout to 900s #276
Use same env var formatting logic on the launcher as server #253
Fix image pulling in launcher #282
Bump version and fix a kernel cmd issue #291
Return the actual number of bytes written to through command buffer #287
Fix lint issues after using golangci-lint-1.52.2 #296

Other Changes:
Add image tests and test automation #275
Update go-sev-guest to v0.4.2 #278
Update to go-sev-guest v0.4.5 #279
Add proper debug license and logging to launcher #280
Upgrade to go-sev-guest v0.5.0 #283
Import go-sev-guest v0.5.2 #284
Add override test for workload env vars and cmd #286
Add test workload code, check OIDC claims, and validate launch policy checks #288
Bump golang.org/x/net in /launcher #290
Add RELEASING instructions #187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
alexmwu added a commit to alexmwu/go-tpm-tools that referenced this pull request Apr 7, 2023
Breaking Changes:

New Features:
Use region in spec to create attestation service rest client google#281
Parse EFI App state from the TCG event log google#277

Bug Fixes:
Increase default systemd wait timeout to 900s google#276
Use same env var formatting logic on the launcher as server google#253
Fix image pulling in launcher google#282
Bump version and fix a kernel cmd issue google#291
Return the actual number of bytes written to through command buffer google#287
Fix lint issues after using golangci-lint-1.52.2 google#296

Other Changes:
Add image tests and test automation google#275
Update go-sev-guest to v0.4.2 google#278
Update to go-sev-guest v0.4.5 google#279
Add proper debug license and logging to launcher google#280
Upgrade to go-sev-guest v0.5.0 google#283
Import go-sev-guest v0.5.2 google#284
Add override test for workload env vars and cmd google#286
Add test workload code, check OIDC claims, and validate launch policy checks google#288
Bump golang.org/x/net in /launcher google#290
Add RELEASING instructions google#187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
michael-pregman pushed a commit that referenced this pull request Apr 10, 2023
Breaking Changes:

New Features:
Use region in spec to create attestation service rest client #281
Parse EFI App state from the TCG event log #277

Bug Fixes:
Increase default systemd wait timeout to 900s #276
Use same env var formatting logic on the launcher as server #253
Fix image pulling in launcher #282
Bump version and fix a kernel cmd issue #291
Return the actual number of bytes written to through command buffer #287
Fix lint issues after using golangci-lint-1.52.2 #296

Other Changes:
Add image tests and test automation #275
Update go-sev-guest to v0.4.2 #278
Update to go-sev-guest v0.4.5 #279
Add proper debug license and logging to launcher #280
Upgrade to go-sev-guest v0.5.0 #283
Import go-sev-guest v0.5.2 #284
Add override test for workload env vars and cmd #286
Add test workload code, check OIDC claims, and validate launch policy checks #288
Bump golang.org/x/net in /launcher #290
Add RELEASING instructions #187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
michael-pregman pushed a commit that referenced this pull request Apr 11, 2023
Breaking Changes:

New Features:
Use region in spec to create attestation service rest client #281
Parse EFI App state from the TCG event log #277

Bug Fixes:
Increase default systemd wait timeout to 900s #276
Use same env var formatting logic on the launcher as server #253
Fix image pulling in launcher #282
Bump version and fix a kernel cmd issue #291
Return the actual number of bytes written to through command buffer #287
Fix lint issues after using golangci-lint-1.52.2 #296

Other Changes:
Add image tests and test automation #275
Update go-sev-guest to v0.4.2 #278
Update to go-sev-guest v0.4.5 #279
Add proper debug license and logging to launcher #280
Upgrade to go-sev-guest v0.5.0 #283
Import go-sev-guest v0.5.2 #284
Add override test for workload env vars and cmd #286
Add test workload code, check OIDC claims, and validate launch policy checks #288
Bump golang.org/x/net in /launcher #290
Add RELEASING instructions #187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
Pranjali-2501 pushed a commit to Pranjali-2501/go-tpm-tools that referenced this pull request Apr 13, 2023
Breaking Changes:

New Features:
Use region in spec to create attestation service rest client google#281
Parse EFI App state from the TCG event log google#277

Bug Fixes:
Increase default systemd wait timeout to 900s google#276
Use same env var formatting logic on the launcher as server google#253
Fix image pulling in launcher google#282
Bump version and fix a kernel cmd issue google#291
Return the actual number of bytes written to through command buffer google#287
Fix lint issues after using golangci-lint-1.52.2 google#296

Other Changes:
Add image tests and test automation google#275
Update go-sev-guest to v0.4.2 google#278
Update to go-sev-guest v0.4.5 google#279
Add proper debug license and logging to launcher google#280
Upgrade to go-sev-guest v0.5.0 google#283
Import go-sev-guest v0.5.2 google#284
Add override test for workload env vars and cmd google#286
Add test workload code, check OIDC claims, and validate launch policy checks google#288
Bump golang.org/x/net in /launcher google#290
Add RELEASING instructions google#187

https://github.com/google/go-tpm-tools/compare/53cab1a...5dd1056?expand=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants