Browse Source

Client: Discard all unsolicited responses except OpLock break

Tal Aloni 7 years ago
parent
commit
7c31666bc3
2 changed files with 20 additions and 6 deletions
  1. 10 3
      SMBLibrary/Client/SMB1Client.cs
  2. 10 3
      SMBLibrary/Client/SMB2Client.cs

+ 10 - 3
SMBLibrary/Client/SMB1Client.cs

@@ -456,10 +456,17 @@ namespace SMBLibrary.Client
                     return;
                 }
 
-                lock (m_incomingQueueLock)
+                // [MS-CIFS] 3.2.5.1 - If the MID value is the reserved value 0xFFFF, the message can be an OpLock break
+                // sent by the server. Otherwise, if the PID and MID values of the received message are not found in the
+                // Client.Connection.PIDMIDList, the message MUST be discarded.
+                if ((message.Header.MID == 0xFFFF && message.Header.Command == CommandName.SMB_COM_LOCKING_ANDX) ||
+                    (message.Header.PID == 0 && message.Header.MID == 0))
                 {
-                    m_incomingQueue.Add(message);
-                    m_incomingQueueEventHandle.Set();
+                    lock (m_incomingQueueLock)
+                    {
+                        m_incomingQueue.Add(message);
+                        m_incomingQueueEventHandle.Set();
+                    }
                 }
             }
         }

+ 10 - 3
SMBLibrary/Client/SMB2Client.cs

@@ -340,10 +340,17 @@ namespace SMBLibrary.Client
                     return;
                 }
 
-                lock (m_incomingQueueLock)
+                // [MS-SMB2] 3.2.5.1.2 - If the MessageId is 0xFFFFFFFFFFFFFFFF, this is not a reply to a previous request,
+                // and the client MUST NOT attempt to locate the request, but instead process it as follows:
+                // If the command field in the SMB2 header is SMB2 OPLOCK_BREAK, it MUST be processed as specified in 3.2.5.19.
+                // Otherwise, the response MUST be discarded as invalid.
+                if (command.Header.MessageID != 0xFFFFFFFFFFFFFFFF || command.Header.Command == SMB2CommandName.OplockBreak)
                 {
-                    m_incomingQueue.Add(command);
-                    m_incomingQueueEventHandle.Set();
+                    lock (m_incomingQueueLock)
+                    {
+                        m_incomingQueue.Add(command);
+                        m_incomingQueueEventHandle.Set();
+                    }
                 }
             }
         }