Abstract:
According to a first aspect of the present invention there is provided a method of scanning a computer system for malware. The method includes determining when an application being executed on the computer system is attempting to open a file, adding data written to the open file by the application into a malware scanner queue, and ensuring that the application has been notified that the file has been closed before scanning the queued file data to determine if it relates to potential malware.

Description:
TECHNICAL FIELD 
       [0001]    The present invention relates to a method and apparatus for performing malware scanning. In particular, the present invention relates to a method and apparatus for optimising the performance of a computer system that performs on-access malware scanning. 
       BACKGROUND 
       [0002]    Malware is short for malicious software and is used as a term to refer to any software designed to infiltrate or damage a computer system without the owner&#39;s informed consent. Malware can include computer viruses, worms, trojan horses, rootkits, adware, spyware and any other malicious or unwanted software. 
         [0003]    Many end users make use of anti-virus software to detect and possibly remove malware. In order to detect a malware file, the anti-virus software must have some way of identifying it amongst all the other files present on a device. Typically, this requires that the anti-virus software has a database containing the “signatures” or “fingerprints” that are characteristic of individual malware program files. When the supplier of the anti-virus software identifies a new malware threat, the threat is analysed and its signature is generated. The malware is then “known” and its signature can be distributed to end users as updates to their local anti-virus software databases. 
         [0004]    Using approaches that solely rely on signature scanning to detect malware still leaves computers vulnerable to “unknown” or “zero day” malware programs/applications that have not yet been analysed for their signature. To address this issue, in addition to scanning for malware signatures, most anti-virus applications additionally employ heuristic analysis. This approach involves the application of general rules intended to distinguish the behaviour of any malware from that of clean/legitimate programs. For example, the behaviour of all programs/applications on a PC may be monitored and if a program/application attempts to write data to an executable file, the anti-virus software can flag this as suspicious behaviour. 
         [0005]    Anti-virus applications typically provide on-demand scanning in which the user of a computer system determines when the files on the computer system should be scanned for the presence of malware. In on-demand scanning the user can activate the scanning process manually, or can configure the scanning process to start in certain circumstances. For example, the user could configure the anti-virus program to scan particular folders on a weekly basis, and to scan all the files on a computer system once a month. In addition, these anti-virus programs usually also provide real-time protection against malware by performing on-access scanning. In on-access scanning the computer system is monitored for the presence of malware by scanning files automatically in the background as and when the files are accessed. 
         [0006]    When an application requires that some operation is performed on a file (e.g. that a file be opened, closed, or some data be written to the file etc), the application sends an input/output (I/O) request to the I/O system. The I/O system consists of a set of layered drivers whose actions are coordinated by the I/O manager. 
         [0007]    The I/O manager manages communication between drivers. All drivers supply a standard set of services that the I/O manager can call. This uniform interface allows the I/O manager to communicate with all drivers in the same way. Drivers communicate with each other using data structures called I/O request packets (IRP). The drivers do not pass IRPs to each other directly. Instead, they pass the packets to the I/O manager, which delivers them to the appropriate destination drivers. The I/O manager therefore:
       accepts I/O requests, which usually originate from user-mode applications;   creates IRPs to represent the I/O requests.   routes the IRPs to the appropriate drivers;   tracks the IRPs until they are completed; and   returns the status to the original requester of each I/O operation.       
 
         [0013]    The I/O system allows separate drivers to implement each logically distinct layer of I/O processing. For example, drivers in the lowest layer manipulate the computer&#39;s physical devices (these are called device drivers). Other drivers are then layered on top of the device drivers in a driver stack. 
         [0014]    On-access scanning is therefore typically implemented using a filter driver of some form, or a minifilter implemented by a filter manager. A filter driver or minifilter can fit in at any layer of the driver stack and filters/intercepts IRPs passed to it from the next-higher or next-lower driver. Anti-virus programs therefore typically use a filter driver or minifilter to intercept requests to access a file, made by or on behalf of an application to the file system. An anti-virus program then intercepts any data that the application attempts to write to the file, and performs a scan of that data. However, the scanning of the file by the anti-virus program is performed synchronously, such that the operation of writing the data to the file cannot be completed whilst the anti-virus program is scanning the data. As such, the application&#39;s execution is blocked/prevented from progressing until the scan has been completed. 
         [0015]      FIG. 1  illustrates the typical process implemented by a computer system when an anti-virus program performs synchronous on-access scanning. The steps performed are as follows:
       A 1 . As part of its execution, an application requires that some data is written to a file. The application therefore requires that a new file or an existing file be opened. In Microsoft® Windows® the application calls a CreateFile function in order to create a new file or open an existing file. The CreateFile function returns a file handle that is associated with the file until either the process terminates or the handle is closed using the CloseHandle function. Any subsequent requests to open the file with the CreateFile function might fail until the handle is closed.   A 2 . The CreateFile function in turn calls the I/O manager that generates an I/O Request Packet (IRP) on behalf of the user-mode application, the IRP having the IRP_MJ_CREATE function code.   A 3 . The anti-virus program providing the on-access scanning functionality intercepts the IRP_MJ_CREATE request sent to the file system by the I/O manager. In doing so, the anti-virus program can identify when a new file is created or an existing file opened. The filter driver then sends the request on to its intended target, the computer&#39;s file system.   A 4 . The file system returns the IRP with a status indicating that the operation was successful, including the file handle of the file, completing the IRP.   A 5 . The filter driver intercepts the IRP returned in response in order to learn the file handle returned by the file system.   A 6 . The I/O manager then notifies the application that the CreateFile function was successful.   A 7 . Once the file has been created and/or opened the application then begins writing data to the file. In Microsoft® Windows® the application generates a WriteFile function call in order to write data to the open file specified by the file handle.   A 8 . The WriteFile function in turn calls the I/O manager that generates an IRP on behalf of the user-mode application, the IRP having the IRP_MJ_WRITE function code and identifying/pointing to the data to be written.   A 9 . The file system writes the identified data to the file and returns the IRP with a status indicating that the operation was successful, completing the IRP.   A 10 . The I/O manager then notifies the application that the WriteFile function was successful.   A 11 . Once the application has received the notification that the WriteFile function has been successful, it then calls a CloseHandle function in order to close the open file handle for the file.   A 12 . The CloseHandle function in turn calls the I/O manager that generates an IRP on behalf of the user-mode application, the IRP having either the IRP_MJ_CLEANUP or IRP_MJ_CLOSE function code.   A 13 . The filter driver intercepts the IRP_MJ_CLEANUP or IRP_MJ_CLOSE request made using the file handle and requests that a malware scanner of the anti-virus program scan the file identified by the file handle.   A 14 . The malware scanner then scans the file. If the result of the scan indicates that the file is clean (i.e. the file is not identified as being related to some form of malware), the malware scanner notifies the filter driver.   A 15 . The filter driver then forwards the intercepted IRP_MJ_CLEANUP or IRP_MJ_CLOSE request on to the file system.   A 16 . The file system closes the file and returns the IRP with a status indicating that the operation was successful, completing the IRP.   A 17 . The I/O manager then notifies the application that the CloseHandle function was successful.   A 18 . Only once the application has received a notification that the CloseHandle function has been successful will it then be able to continue with its execution by writing data to another file.       
 
         [0034]    In preventing the closure of the file handle until the file has been scanned for malware, this synchronous process of on-access scanning blocks the application from writing data to any other file until the malware scan has been completed. In other words, the application must wait until the malware scan has been completed before it can continue processing the file. As such, the anti-virus program prevents the execution of the application from progressing, slowing the rate at which it can complete its tasks, and therefore impacts on the performance of the computer system. 
       SUMMARY 
       [0035]    It is an object of the present invention to provide a method of performing on-access malware scanning on a computer system that minimises the delay introduced into the execution of applications running on the computer system, therefore optimising the performance of the computer system. 
         [0036]    According to a first aspect of the present invention there is provided a method of scanning a computer system for malware. The method comprises determining when an application being executed on the computer system is attempting to open a file, adding data written to the open file by the application into a malware scanner queue, and ensuring that the application has been notified that the file has been closed before scanning the queued file data to determine if it relates to potential malware. 
         [0037]    Embodiments of the invention provide that an anti-virus program can perform on-access scanning of a file without the need to block the execution of the application accessing the file until the malware scan has been completed. 
         [0038]    The step of determining when an application being executed on the computer system is attempting to open a file may comprise intercepting messages that request the creation of a new file or opening of an existing file. The method may further comprise intercepting a response to any detected file open request messages in order to obtain a handle assigned to the file. The file open request messages may be I/O Request Packets, IRP, containing an IRP_MJ_CREATE function code. 
         [0039]    The step of adding data written to the open file by the application into a malware scanner queue may comprise copying the data as it is written to the open file by the application, and adding the copied file data into the malware scanner queue. The data may be copied by intercepting messages that request data be written to the file, and copying the data identified in the request. The write data request messages may be IRPs containing an IRP_MJ_CREATE function code, and the data may be copied into a cache memory of the computer system. 
         [0040]    The method may further comprise determining if the application has initiated closure of the file before adding the copied file data the malware scanner queue. The step of determining if the application has initiated closure may comprise intercepting messages that request the file be closed. These file close request messages may be IRPs containing an IRP_MJ_CLEANUP or IRP_MJ_CLOSE function code. 
         [0041]    The step of adding data written to the open file by the application into a malware scanner queue may comprise recording a location of the file, and adding the recorded file location into the malware scanner queue. The scanning of the queued file data may then comprise scanning the file data from the recorded file location. 
         [0042]    The step of recording a location of the file may comprise intercepting messages that request data be written to the file, and recording the file location identified in the request. The file location may be recorded in a cache memory of the computer system. The write data request messages may be IRPs containing an IRP_MJ_CREATE function code. 
         [0043]    The method may further comprise determining if the application has initiated closure of the file before adding the file location into the malware scanner queue. The step of determining if the application has initiated closure may comprise intercepting messages that request the file be closed. The file close request messages may be IRPs containing an IRP_MJ_CLEANUP or IRP_MJ_CLOSE function code. 
         [0044]    After the application has initiated closure of the file, the queued file data may only be scanned when the amount of data in the queue exceeds a threshold. Alternatively, after the application has initiated closure of the file, the queued file data may only scanned when the age of the file data exceeds a threshold. The method may then further comprise, when adding data written to the open file by the application into a malware scanner queue, recording the time at which the file data was written to the file. 
         [0045]    The interception of messages may be implemented using a filter unit. The scanning of the queued file data may be implemented using a malware scanner. The filter unit and malware scanner may be components of an anti-virus program. 
         [0046]    According to a second aspect of the present invention there is provided a computer program comprising computer program code means adapted to perform the following steps:
       determine when an application being executed on the computer system is attempting to open a file;   add data written to the open file by the application into a malware scanner queue; and   ensure that the application has been notified that the file has been closed before scanning the queued file data to determine if it relates to potential malware.       
 
         [0050]    According to a third aspect of the present invention there is provided a computer program as outlined above embodied on a computer readable medium. 
         [0051]    According to a fourth aspect of the present invention there is provided a computer system configured to scan files for malware. The computer system comprises a filter unit for determining when an application being executed on the computer system is attempting to open a file, adding data written to the open file by the application into a malware scanner queue, and ensuring that the application has been notified that the file has been closed before the queued file data is scanned to determine if it relates to potential malware. The computer system may further comprise a malware scanner for scanning the queued file data. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0052]      FIG. 1  is a flow diagram illustrating a process of performing on-access malware scanning; 
           [0053]      FIG. 2  illustrates schematically a computer system according to an embodiment of the present invention; and 
           [0054]      FIG. 3  is a flow diagram illustrating a process of performing on-access malware scanning according to an embodiment of the present invention. 
       
    
    
     DETAILED DESCRIPTION 
       [0055]    In order to at least partially overcome the problems described above, it is proposed here to improve the performance of a computer system by performing asynchronous on-access malware scanning, in which the application&#39;s execution is not blocked while the operation is being performed. This asynchronous scanning is achieved by making a copy of any data that is being written to a file by an application, and storing the copy of the file data in a memory cache. The writing of this data to the file can then continue without the need to wait until after the malware scan is performed. The data in the cache can then be scanned for malware when appropriate. By providing that the application&#39;s execution is not blocked while the malware scanning operation is being performed, the anti-virus program minimises the delay introduced by the on-access malware scanning, thereby optimising the performance of the computer system. 
         [0056]      FIG. 2  illustrates schematically a computer system  1  according to an embodiment of the present invention. The computer system  1  can be implemented as a combination of computer hardware and software. The computer system  1  comprises a memory  2 , a cache  3 , a processor  4  and a transceiver  5 . The memory  2  stores all of the files required by the computer system  1 . The files stored in the memory  2  include the various programs/executable files that are implemented by the processor  3 , as well as any data files  6 . The programs/executable files stored in the memory  2 , and implemented by the processor  4 , include a filter unit  7  and a malware scanner unit  8 , each of which can be sub-units of an anti-virus unit  9 , as well as the file system  10  and any other programs/applications  11 . The data files  6  stored in the memory  2  can include application data files, malware definition data files, files containing heuristic analysis rules, white lists, black lists etc. The cache  3  provides a temporary storage unit for storing data that is to be scanned by the malware scanner unit  8 . The transceiver  5  is used to communicate with a central anti-virus server  12  over a network  13  such as the Internet or a LAN. 
         [0057]    The central anti-virus server  12  is typically operated by the provider of the anti-virus unit  8  that is run on the computer  1 . Alternatively, the central anti-virus server  12  may be that of a network administrator or supervisor, the computer  1  being part of the network for which the supervisor is responsible. The central anti-virus server  12  can be implemented as a combination of computer hardware and software. The central anti-virus server  12  comprises a memory  14 , a processor  15 , a transceiver  16  and a database  17 . The memory  14  stores the various programs/executable files that are implemented by the processor  15 . The transceiver  16  is used to communicate with the computer system  1  over the network  13 . The database  17  stores the latest malware definition data, heuristic analysis rules, white lists, black lists etc. 
         [0058]      FIG. 3  is a flow diagram further illustrating the process of performing on-access malware scanning according to an embodiment of the present invention. The steps performed are as follows:
       B 1 . As part of its execution, an application requires that data be written to a new file or an existing file. In order to create a new file or open an existing file, the application calls the CreateFile function.   B 2 . The CreateFile function in turn calls the I/O manager that generates an IRP on behalf of the user-mode application, the IRP having the IRP_MJ_CREATE function code.   B 3 . The filter unit associated with the anti-virus program intercepts the IRP_MJ_CREATE request made to the file system, and thereby determines that a new file is to be created or an existing file opened. The filter unit then sends the request on to the computer&#39;s file system.   B 4 . The file system returns the IRP with a status indicating that the operation was successful, and including the file handle of the file, completing the IRP.   B 5 . The filter unit intercepts the IRP returned in response in order to learn the file handle returned by the file system before sending the response on to the application.   B 6 . The I/O manager then notifies the application that the CreateFile function was successful.   B 7 . Once a file has been created and/or opened, the application then begins writing data to the file, calls a WriteFile function using the file handle.   B 8 . The WriteFile function in turn calls the I/O manager that generates an IRP on behalf of the user-mode application, the IRP having the IRP_MJ_WRITE function code and indicating/identifying the data to be written.   B 9 . The filter unit intercepts the IRP_MJ_WRITE request made using the file handle and copies the data to be written to the file into the cache. The filter unit then forwards the intercepted request on to the file system such that the data can be written to the specified file.   B 10 . The file system writes the identified data to the file and returns the IRP with a status indicating that the operation was successful, completing the IRP.   B 11 . The I/O manager then notifies the application that the WriteFile function was successful.   B 12 . Once the application has received the notification that the WriteFile function has been successful, it then calls a CloseHandle function to close the open file handle for the file.   B 13 . The CloseHandle function in turn calls the I/O manager that generates an IRP on behalf of the user-mode application, the IRP having either the IRP_MJ_CLEANUP or IRP_MJ_CLOSE function code.   B 14 . The filter unit intercepts the IRP_MJ_CLEANUP or IRP_MJ_CLOSE request made using the file handle and adds the cached file data to a queue of data that is due to be scanned for malware. The malware scanner queue comprises the file data that has been cached and is ready to be scanned. In order to add the file data to the queue, the filter driver registers the file handle for asynchronous processing. The filter unit then forwards the intercepted IRP_MJ_CLEANUP or IRP_MJ_CLOSE request on to the file system.   B 15 . The file system closes the file and returns the IRP with a status indicating that the operation was successful, completing the IRP.   B 16 . The I/O manager then notifies the application that the CloseHandle function was successful.   B 17 . Once the application has received a notification that the CloseHandle function has been successful it is then able to continue with its execution by writing data to another file or performing any other actions. If the application continues by writing data to another file or to the same file then steps B 1  to B 16  are repeated.   B 18 . Once the amount of data in the queue reaches a predefined maximum threshold, or the oldest item of data in the queue reaches a predefined maximum age, the filter unit requests that the malware scanner performs a scan of that file data stored in the cache that is currently in the malware scanner queue.   B 19 . The malware scanner then scans the queued file data stored in the cache.   B 20 . If the amount of data in the queue has not yet reached the predefined maximum threshold, nor the oldest item of data in the queue reached the predefined maximum age, then the filter continues to store data that is written to files by the application and adds this file data to the malware scanner queue.       
 
         [0079]    Alternatively, instead of hooking into the process of writing data to the file and copying the file data to the cache, the filter unit could be configured to simply capture information about the file, such as the file handle and the path to the file, by intercepting the various requests and responses sent from or to the application whilst the file is open. Then, once the file is closed, the file handle released, and the IRP_MJ_CLEANUP or IRP_MJ_CLOSE request is completed, the file path can be added to the malware scanner queue by the filter unit such that the malware scanner can then scan the actual file data from the location at which it is stored. 
         [0080]    As a further alternative, when the filter unit receives the IRP_MJ_CLEANUP request, the filter unit could be configured not to pass the IRP on toward the file system, but to mark the IRP as STATUS_PENDING, store the pointer to IRP and complete the current processing. The application would then be notified that the CloseHandle function has been completed and would therefore able to continue its execution. However, as the file system has not received the IRP_MJ_CLEANUP file, the file object associated with the file handle remains valid such that the file system is able to read the data from the file. Subsequently, when the malware scanner requires the file data in order to perform the asynchronous scan, it sends a request for the data to the filter unit. The filter unit then generates an IRP_MJ_READ request using parameters from the IRP_MJ_CLEANUP. When the malware scan has been completed, the original IRP_MJ_CLEANUP is sent on to the file system to be completed and the file handle is closed. 
         [0081]    The filter unit should record an indication of the time at which the file data was written to the file. The filter unit can then use the time information to determine if the age of the oldest file data within the malware scanner queue has exceeded a predefined time limit, and therefore when the queued file data should be scanned by the malware scanner. For example, this time limit could vary between one second and ten seconds. In addition, the filter unit could record the path of the file as this could be used by the malware scanner during the scanning procedure (e.g. as the location of a file may be indicative as to whether a file may or may not be malware). Furthermore, the anti-virus program can also make use of the file location information if and when a file has been identified as relating to potential malware by the malware scanner, in order to perform any disinfection and/or quarantine operations. 
         [0082]    Optionally, the anti-virus program could be configured to limit the maximum amount of data that can be stored in the queue by the filter driver. Once the amount of data within the queue reaches this maximum limit, the filter unit would be configured to send a request to the malware scanner requesting that the queued file data is scanned. In addition, if amount of data written to a single file exceeds the maximum size of the cache and/or queue then the filter unit could be configured to request that the malware scanner perform a synchronous scan of the new data. The malware scanner could then scan the data as it is written to the file, whilst the execution of the application is prevented from progressing until the scan has been completed. 
         [0083]    The filter unit would also be configured to determine if the application is attempting to modify, overwrite or delete the data currently written to a particular file, and which has been added to the malware scanner queue. The filter unit would then be configured to take any action deemed appropriate. For example, if the filter unit were to determine that an application is attempting to write new data to an existing file, whilst the data currently written to that file is waiting to be scanned by the malware scanner, then the filter unit could be configured to remove the current file data from the queue (and, if required, from the cache) and request that the malware scanner perform a synchronous scan of the new data. The malware scanner would then scan the new data as it is written to the file, whilst the execution of the application is prevented from progressing until the scan has been completed. Furthermore, if the filter unit were to determine that an application is attempting to delete a file whilst the data currently written to that file is waiting to be scanned, then the filter unit can be configured to remove that file&#39;s data from the queue (and, if required, from the cache). 
         [0084]    Alternatively, if the filter unit has made a copy of the file data into a cache, and the filter unit determines that the application is attempting to modify, overwrite or delete that data, then the filter unit could be configured to either:
       Retain the current file data from the both the cache and the queue, and add the newly written file data to the cache and the queue as appropriate. The malware scanner would then scan both the most recent file data and the data that preceded it.   Remove the current file data from the both the cache and the queue, and add the newly written file data to the cache and the queue as appropriate. The malware scanner would then only scan the most recent file data.       
 
         [0087]    Similarly, if an application continues writing data files such that the amount of data in the malware scanning queue reaches the threshold maximum size before the malware scanner has completed the scanning of the data in the preceding malware scanning queue, then the filter unit could be configured to either:
       Block any further execution of the application until the malware scanner has completed the scanning of the data in the preceding malware scanning queue, such that the file data currently in the malware scanning queue can then be passed to the malware scanner for scanning, freeing the malware scanner queue to accept more file data.   Request synchronous malware scanning of any succeeding file data until there is sufficient space within the malware scanner queue to accept more file data       
 
         [0090]    The methods described above provide that an anti-virus program can perform on-access scanning of a file without the need to block the application accessing the file from progressing until the malware scan has been completed. This method therefore optimises the performance of a computer system that is configured to perform on-access malware scanning of files. In addition, when storing the file data within a cache, the methods described above provide that the file data can be accessed quicker than is possible from the computers persistent memory, such as the computers hard disk. Furthermore, the methods of performing asynchronous malware scanning described above do not introduce any additional risk to the security of the computer system when compared with conventional synchronous malware scanning methods, as neither synchronous nor asynchronous malware scanning enable the filter unit to prevent the data from being written to the file nor prevent the file handle from subsequently being closed. In addition, the methods described above can exploit the multi-processor, multi-tasking, multi-threading and hyper-threading capabilities of modern computer systems (see Intel® Hyper-Threading Technology, Technical User&#39;s Guide, January 2003) to further improve the performance of a computer system when implementing on-access malware scanning, by allowing the scanning of file data to occur in parallel with the operations of the application that is writing data to files. 
         [0091]    It will be appreciated by the person of skill in the art that various modifications may be made to the above described embodiments without departing from the scope of the present invention.