-
Notifications
You must be signed in to change notification settings - Fork 2
Possible deadlock in jail implementation #22
Copy link
Copy link
Open
Description
Please consider this premise (which might be wrong);
If the mutex is read locked, a call to Lock is blocked**. If one or more readers hold a lock, you cannot write.
And this is where de deadlock could happen:
func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
[...]
if a.jailEnabled {
a.jailMutex.RLock()
if a.isClientInJail(clientIP) {
a.jailMutex.RUnlock()
[...]
return
}
a.jailMutex.RUnlock()
}isClientInJail has a call to releaseFromJail
func (a *Modsecurity) releaseFromJail(clientIP string) {
a.jailMutex.Lock()
defer a.jailMutex.Unlock()
delete(a.jail, clientIP)
delete(a.jailRelease, clientIP)
a.logger.Printf("client %s released from jail", clientIP)
}Here jailMutex.Lock() will be stuck forever as a previously unreleased read lock was obtained in the main ServeHTTP.
I'll investigate further to confirm/reproduce.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels