Skip to content

Commit

Permalink
syscall: introduce Pointer type and use it instead of uintptr
Browse files Browse the repository at this point in the history
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 <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
alexbrainman committed Apr 18, 2018
1 parent 3042463 commit 4869ec0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
12 changes: 12 additions & 0 deletions api/except.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,15 @@ pkg text/template/parse, type VariableNode struct
pkg text/template/parse, type VariableNode struct, Ident []string
pkg text/template/parse, type VariableNode struct, embedded NodeType
pkg text/template/parse, type VariableNode struct, embedded Pos
pkg syscall (windows-386), type CertChainPolicyPara struct, ExtraPolicyPara uintptr
pkg syscall (windows-386), type CertChainPolicyStatus struct, ExtraPolicyStatus uintptr
pkg syscall (windows-386), type CertContext struct, CertInfo uintptr
pkg syscall (windows-386), type CertRevocationInfo struct, CrlInfo uintptr
pkg syscall (windows-386), type CertRevocationInfo struct, OidSpecificInfo uintptr
pkg syscall (windows-386), type CertSimpleChain struct, TrustListInfo uintptr
pkg syscall (windows-amd64), type CertChainPolicyPara struct, ExtraPolicyPara uintptr
pkg syscall (windows-amd64), type CertChainPolicyStatus struct, ExtraPolicyStatus uintptr
pkg syscall (windows-amd64), type CertContext struct, CertInfo uintptr
pkg syscall (windows-amd64), type CertRevocationInfo struct, CrlInfo uintptr
pkg syscall (windows-amd64), type CertRevocationInfo struct, OidSpecificInfo uintptr
pkg syscall (windows-amd64), type CertSimpleChain struct, TrustListInfo uintptr
2 changes: 1 addition & 1 deletion src/crypto/x509/root_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func checkChainSSLServerPolicy(c *Certificate, chainCtx *syscall.CertChainContex
sslPara.Size = uint32(unsafe.Sizeof(*sslPara))

para := &syscall.CertChainPolicyPara{
ExtraPolicyPara: uintptr(unsafe.Pointer(sslPara)),
ExtraPolicyPara: (syscall.Pointer)(unsafe.Pointer(sslPara)),
}
para.Size = uint32(unsafe.Sizeof(*para))

Expand Down
32 changes: 26 additions & 6 deletions src/syscall/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ var (
OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00")
)

// Pointer represents a pointer to an arbitrary Windows type.
//
// Pointer-typed fields may point to one of many different types. It's
// up to the caller to provide a pointer to the appropriate type, cast
// to Pointer. The caller must obey the unsafe.Pointer rules while
// doing so.
type Pointer *struct{}

// Invented values to support what package os expects.
type Timeval struct {
Sec int32
Expand Down Expand Up @@ -845,11 +853,15 @@ type MibIfRow struct {
Descr [MAXLEN_IFDESCR]byte
}

type CertInfo struct {
// Not implemented
}

type CertContext struct {
EncodingType uint32
EncodedCert *byte
Length uint32
CertInfo uintptr
CertInfo *CertInfo
Store Handle
}

Expand All @@ -864,12 +876,16 @@ type CertChainContext struct {
RevocationFreshnessTime uint32
}

type CertTrustListInfo struct {
// Not implemented
}

type CertSimpleChain struct {
Size uint32
TrustStatus CertTrustStatus
NumElements uint32
Elements **CertChainElement
TrustListInfo uintptr
TrustListInfo *CertTrustListInfo
HasRevocationFreshnessTime uint32
RevocationFreshnessTime uint32
}
Expand All @@ -884,14 +900,18 @@ type CertChainElement struct {
ExtendedErrorInfo *uint16
}

type CertRevocationCrlInfo struct {
// Not implemented
}

type CertRevocationInfo struct {
Size uint32
RevocationResult uint32
RevocationOid *byte
OidSpecificInfo uintptr
OidSpecificInfo Pointer
HasFreshnessTime uint32
FreshnessTime uint32
CrlInfo uintptr // *CertRevocationCrlInfo
CrlInfo *CertRevocationCrlInfo
}

type CertTrustStatus struct {
Expand Down Expand Up @@ -922,7 +942,7 @@ type CertChainPara struct {
type CertChainPolicyPara struct {
Size uint32
Flags uint32
ExtraPolicyPara uintptr
ExtraPolicyPara Pointer
}

type SSLExtraCertChainPolicyPara struct {
Expand All @@ -937,7 +957,7 @@ type CertChainPolicyStatus struct {
Error uint32
ChainIndex uint32
ElementIndex uint32
ExtraPolicyStatus uintptr
ExtraPolicyStatus Pointer
}

const (
Expand Down

0 comments on commit 4869ec0

Please sign in to comment.