Skip to content

Commit 4869ec0

Browse files
committed
syscall: introduce Pointer type and use it instead of uintptr
Some syscall structures used by crypto/x509 have uintptr fields that store pointers. These pointers are set with a pointer to another Go structure. But the pointers are not visible by garbage collector, and GC does not update the fields after they were set. So when structure with invalid uintptr pointers passed to Windows, we get memory corruption. This CL introduces CertInfo, CertTrustListInfo and CertRevocationCrlInfo types. It uses pointers to new types instead of uintptr in CertContext, CertSimpleChain and CertRevocationInfo. CertRevocationInfo, CertChainPolicyPara and CertChainPolicyStatus types have uintptr field that can be pointer to many different things (according to Windows API). So this CL introduces Pointer type to be used for those cases. As suggested by Austin Clements. Fixes #21376 Updates #24820 Change-Id: If95cd9eee3c69e4cfc35b7b25b1b40c2dc8f0df7 Reviewed-on: https://go-review.googlesource.com/106275 Reviewed-by: Austin Clements <[email protected]> Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3042463 commit 4869ec0

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

api/except.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,15 @@ pkg text/template/parse, type VariableNode struct
371371
pkg text/template/parse, type VariableNode struct, Ident []string
372372
pkg text/template/parse, type VariableNode struct, embedded NodeType
373373
pkg text/template/parse, type VariableNode struct, embedded Pos
374+
pkg syscall (windows-386), type CertChainPolicyPara struct, ExtraPolicyPara uintptr
375+
pkg syscall (windows-386), type CertChainPolicyStatus struct, ExtraPolicyStatus uintptr
376+
pkg syscall (windows-386), type CertContext struct, CertInfo uintptr
377+
pkg syscall (windows-386), type CertRevocationInfo struct, CrlInfo uintptr
378+
pkg syscall (windows-386), type CertRevocationInfo struct, OidSpecificInfo uintptr
379+
pkg syscall (windows-386), type CertSimpleChain struct, TrustListInfo uintptr
380+
pkg syscall (windows-amd64), type CertChainPolicyPara struct, ExtraPolicyPara uintptr
381+
pkg syscall (windows-amd64), type CertChainPolicyStatus struct, ExtraPolicyStatus uintptr
382+
pkg syscall (windows-amd64), type CertContext struct, CertInfo uintptr
383+
pkg syscall (windows-amd64), type CertRevocationInfo struct, CrlInfo uintptr
384+
pkg syscall (windows-amd64), type CertRevocationInfo struct, OidSpecificInfo uintptr
385+
pkg syscall (windows-amd64), type CertSimpleChain struct, TrustListInfo uintptr

src/crypto/x509/root_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func checkChainSSLServerPolicy(c *Certificate, chainCtx *syscall.CertChainContex
109109
sslPara.Size = uint32(unsafe.Sizeof(*sslPara))
110110

111111
para := &syscall.CertChainPolicyPara{
112-
ExtraPolicyPara: uintptr(unsafe.Pointer(sslPara)),
112+
ExtraPolicyPara: (syscall.Pointer)(unsafe.Pointer(sslPara)),
113113
}
114114
para.Size = uint32(unsafe.Sizeof(*para))
115115

src/syscall/types_windows.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ var (
296296
OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00")
297297
)
298298

299+
// Pointer represents a pointer to an arbitrary Windows type.
300+
//
301+
// Pointer-typed fields may point to one of many different types. It's
302+
// up to the caller to provide a pointer to the appropriate type, cast
303+
// to Pointer. The caller must obey the unsafe.Pointer rules while
304+
// doing so.
305+
type Pointer *struct{}
306+
299307
// Invented values to support what package os expects.
300308
type Timeval struct {
301309
Sec int32
@@ -845,11 +853,15 @@ type MibIfRow struct {
845853
Descr [MAXLEN_IFDESCR]byte
846854
}
847855

856+
type CertInfo struct {
857+
// Not implemented
858+
}
859+
848860
type CertContext struct {
849861
EncodingType uint32
850862
EncodedCert *byte
851863
Length uint32
852-
CertInfo uintptr
864+
CertInfo *CertInfo
853865
Store Handle
854866
}
855867

@@ -864,12 +876,16 @@ type CertChainContext struct {
864876
RevocationFreshnessTime uint32
865877
}
866878

879+
type CertTrustListInfo struct {
880+
// Not implemented
881+
}
882+
867883
type CertSimpleChain struct {
868884
Size uint32
869885
TrustStatus CertTrustStatus
870886
NumElements uint32
871887
Elements **CertChainElement
872-
TrustListInfo uintptr
888+
TrustListInfo *CertTrustListInfo
873889
HasRevocationFreshnessTime uint32
874890
RevocationFreshnessTime uint32
875891
}
@@ -884,14 +900,18 @@ type CertChainElement struct {
884900
ExtendedErrorInfo *uint16
885901
}
886902

903+
type CertRevocationCrlInfo struct {
904+
// Not implemented
905+
}
906+
887907
type CertRevocationInfo struct {
888908
Size uint32
889909
RevocationResult uint32
890910
RevocationOid *byte
891-
OidSpecificInfo uintptr
911+
OidSpecificInfo Pointer
892912
HasFreshnessTime uint32
893913
FreshnessTime uint32
894-
CrlInfo uintptr // *CertRevocationCrlInfo
914+
CrlInfo *CertRevocationCrlInfo
895915
}
896916

897917
type CertTrustStatus struct {
@@ -922,7 +942,7 @@ type CertChainPara struct {
922942
type CertChainPolicyPara struct {
923943
Size uint32
924944
Flags uint32
925-
ExtraPolicyPara uintptr
945+
ExtraPolicyPara Pointer
926946
}
927947

928948
type SSLExtraCertChainPolicyPara struct {
@@ -937,7 +957,7 @@ type CertChainPolicyStatus struct {
937957
Error uint32
938958
ChainIndex uint32
939959
ElementIndex uint32
940-
ExtraPolicyStatus uintptr
960+
ExtraPolicyStatus Pointer
941961
}
942962

943963
const (

0 commit comments

Comments
 (0)