Fix unsafe access to perf standby status from systemview (#17186)

Ensure that we don't try to access Core.perfStandby or Core.PerfStandby() from dynamicSystemView, which might be accessed with or without stateLock held.
This commit is contained in:
Nick Cabatoff 2022-10-05 08:56:36 -04:00 committed by GitHub
parent 3aa2fe8d8f
commit d5e0353696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 7 deletions

3
changelog/17186.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
core: fix race when using SystemView.ReplicationState outside of a request context
```

View File

@ -23,8 +23,9 @@ func (c ctxKeyForwardedRequestMountAccessor) String() string {
}
type dynamicSystemView struct {
core *Core
mountEntry *MountEntry
core *Core
mountEntry *MountEntry
perfStandby bool
}
type extendedSystemView interface {
@ -178,7 +179,7 @@ func (d dynamicSystemView) LocalMount() bool {
// in read mode.
func (d dynamicSystemView) ReplicationState() consts.ReplicationState {
state := d.core.ReplicationState()
if d.core.perfStandby {
if d.perfStandby {
state |= consts.ReplicationPerformanceStandby
}
return state

View File

@ -49,8 +49,9 @@ func verifyNamespace(*Core, *namespace.Namespace, *MountEntry) error { return ni
func (c *Core) mountEntrySysView(entry *MountEntry) extendedSystemView {
return extendedSystemViewImpl{
dynamicSystemView{
core: c,
mountEntry: entry,
core: c,
mountEntry: entry,
perfStandby: c.perfStandby,
},
}
}

View File

@ -251,7 +251,7 @@ func NewPolicyStore(ctx context.Context, core *Core, baseView *BarrierView, syst
func (c *Core) setupPolicyStore(ctx context.Context) error {
// Create the policy store
var err error
sysView := &dynamicSystemView{core: c}
sysView := &dynamicSystemView{core: c, perfStandby: c.perfStandby}
psLogger := c.baseLogger.Named("policy")
c.AddLogger(psLogger)
c.policyStore, err = NewPolicyStore(ctx, c, c.systemBarrierView, sysView, psLogger)

View File

@ -508,7 +508,7 @@ func TestDynamicSystemView(c *Core, ns *namespace.Namespace) *dynamicSystemView
me.namespace = ns
}
return &dynamicSystemView{c, me}
return &dynamicSystemView{c, me, c.perfStandby}
}
// TestAddTestPlugin registers the testFunc as part of the plugin command to the