2b9a8c6c49
* Read total cert counts with atomic.LoadUint32(...) When generating the tidy status, we read the values of two backend atomics, b.certCount and b.revokedCertCount, without using the atomic load operation. This resulted in a data race when the status was read at the same time as an on-going tidy operation: WARNING: DATA RACE Write at 0x00c00c77680c by goroutine 90522: sync/atomic.AddInt32() /usr/local/go/src/runtime/race_amd64.s:281 +0xb sync/atomic.AddUint32() <autogenerated>:1 +0x1a github.com/hashicorp/vault/builtin/logical/pki.(*backend).tidyStatusIncRevokedCertCount() /home/circleci/go/src/github.com/hashicorp/vault/builtin/logical/pki/path_tidy.go:1236 +0x107 github.com/hashicorp/vault/builtin/logical/pki.(*backend).doTidyRevocationStore() /home/circleci/go/src/github.com/hashicorp/vault/builtin/logical/pki/path_tidy.go:525 +0x1404 github.com/hashicorp/vault/builtin/logical/pki.(*backend).startTidyOperation.func1.1() /home/circleci/go/src/github.com/hashicorp/vault/builtin/logical/pki/path_tidy.go:290 +0x1a4 github.com/hashicorp/vault/builtin/logical/pki.(*backend).startTidyOperation.func1() /home/circleci/go/src/github.com/hashicorp/vault/builtin/logical/pki/path_tidy.go:342 +0x278 Previous read at 0x00c00c77680c by goroutine 90528: reflect.Value.Uint() /usr/local/go/src/reflect/value.go:2584 +0x195 encoding/json.uintEncoder() /usr/local/go/src/encoding/json/encode.go:562 +0x45 encoding/json.ptrEncoder.encode() /usr/local/go/src/encoding/json/encode.go:944 +0x3c2 encoding/json.ptrEncoder.encode-fm() <autogenerated>:1 +0x90 encoding/json.(*encodeState).reflectValue() /usr/local/go/src/encoding/json/encode.go:359 +0x88 encoding/json.interfaceEncoder() /usr/local/go/src/encoding/json/encode.go:715 +0x17b encoding/json.mapEncoder.encode() /usr/local/go/src/encoding/json/encode.go:813 +0x854 ... more stack trace pointing into JSON encoding and http handler... In particular, because the tidy status was directly reading the uint value without resorting to the atomic side, the JSON serialization could race with a later atomic update. Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> * Also use atomic load in tests Because no tidy operation is running here, it should be safe to read the pointed value directly, but use the safer atomic.Load for consistency. Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> * Add changelog entry Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> --------- Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> |
||
---|---|---|
.. | ||
cmd/pki | ||
backend.go | ||
backend_test.go | ||
ca_test.go | ||
ca_util.go | ||
cert_util.go | ||
cert_util_test.go | ||
chain_test.go | ||
chain_util.go | ||
config_util.go | ||
crl_test.go | ||
crl_util.go | ||
fields.go | ||
integration_test.go | ||
key_util.go | ||
managed_key_util.go | ||
ocsp.go | ||
ocsp_test.go | ||
path_config_ca.go | ||
path_config_cluster.go | ||
path_config_crl.go | ||
path_config_urls.go | ||
path_fetch.go | ||
path_fetch_issuers.go | ||
path_fetch_keys.go | ||
path_intermediate.go | ||
path_issue_sign.go | ||
path_manage_issuers.go | ||
path_manage_keys.go | ||
path_manage_keys_test.go | ||
path_resign_crls.go | ||
path_resign_crls_test.go | ||
path_revoke.go | ||
path_roles.go | ||
path_roles_test.go | ||
path_root.go | ||
path_sign_issuers.go | ||
path_tidy.go | ||
path_tidy_test.go | ||
periodic.go | ||
secret_certs.go | ||
storage.go | ||
storage_migrations.go | ||
storage_migrations_test.go | ||
storage_test.go | ||
storage_unified.go | ||
test_helpers.go | ||
util.go |