Summery

Opportunistic Lock (oplock) is a Windows file-sharing mechanism that lets a client cache file data locally to improve performance, while allowing the server to notify it when another client needs conflicting access.

In essence, this is how it works:

  1. A client opens a file over SMB and receives an oplock.
  2. The client caches file data or operations locally, reducing network requests.
  3. Another client requests access that conflicts with the oplock.
  4. The server asks the first client to break or downgrade its oplock so cached data can be synchronized.

Oplocks are relevant to SMB race conditions and file-operation attacks. For example, an attacker may exploit timing between file access and another process’s file operation. Oplocks can help control that timing in certain Windows exploitation techniques.

Applications can also request oplocks when opening files. You can set it yourself too. The easiest way is to run SetOpLock.exe as it was shown in the CVE-2023-49147 exploit.

SMB2 and later also used leases, which provide related caching functionality and are more flexible than traditional oplocks.