google / go-tpm

Apache License 2.0
553 stars 159 forks source link

reduce unnecessary overhead of Tbsi_Get_TCG_Log #325

Closed rikuks closed 1 year ago

rikuks commented 1 year ago

https://github.com/google/go-tpm/blob/3270509f088425fc9499bc9b7b8ff0811119bedb/tpmutil/tbs/tbs_windows.go#L261-L265

Overview

The following image shows the result of reverse engineering tbs.dll.

log

The context that is the argument of Tbsi_Get_TCG_Log is unnecessary because it is never used in processing.

Thus it can be written as follows.

 result, _, _ := tbsGetTCGLog.Call( 
    0, 
    sliceAddress(logBuffer), 
    uintptr(unsafe.Pointer(&logBufferLen)), 
 ) 

Conclusion

Contexts can be eliminated, thus reducing overhead.

chrisfenner commented 1 year ago

Hi, @rikuks, thanks for this pull request!

The official documentation for Tbsi_Get_TCG_Log promises to return TBS_E_INVALID_CONTEXT if passed an invalid context. I think we should avoid taking a dependency on something that might be broken without a change to the external API.