Re: [ext] Scanning memory mapped file s

neel roy via clamav-users <[email protected]>
Newsgroups gmane.comp.security.virus.clamav.user
Message-ID <1733394932.S.8163.28761.f4-234-162.1733400909.4435@webmail.rediffmail.com>
Hello Ralf,

Thanks. I hope I can ask follow up questions. You wrote:

&gt; I doesn&#39;t (from the clamonacc man page):

&gt; The clamonacc daemon registers for file access notifications from the
&gt; Linux kernel and in response, submits scans to the clamd scanning
&gt; daemon for a verdict. On-Access requires a kernel version &gt;= 3.8,
&gt; because it leverages a kernel api called --&gt; fanotify &lt;-- to block
&gt; processes from attempting to access malicious files.

I have verified that a if file opened using memory mapped IO API calls is _closed_ fanotify will send notification. However could you or someone else tell me if following is possible?

- We are using clamonacc
- a file opened using memory mapped io API calls

Can this file get infected while it stays open? If yes, and if this is executable can it be executed along with it&#39;s infected code, while it&#39;s open?

Thanks in advance,
-Neel.



From: Ralf Hildebrandt via clamav-users &lt;[email protected]&gt;
Sent: Thu, 05 Dec 2024 16:05:32
To: [email protected]
Cc: Ralf Hildebrandt &lt;[email protected]&gt;
Subject: Re: [clamav-users] [ext] Scanning memory mapped files

&gt; I am not using clamonacc. I run my own program that uses fanotify, just like clamonacc does, and gets list of files that are modifedadded.
&gt; I send that list to clamscan or clamdscan.

A bit like incrond (which uses inotify() )

&gt; The problem is limitation of fanotify which is that &quot;The fanotify API does not report file accesses and modifications that may occur because of mmap(2), msync(2), and munmap(2).&quot;

Same goes for inotify() -- just checked.

So whenever a process alters a file using mmap()/munmap() or msync(),
your program (or rather inotify/fanotify) doesn&#39;t detect any change,
and thus the file wont be in the list passed to clamscan or clamdscan.

&gt; Now my assumption is mmap, msync, munmap deals with memory mapped files. So questions I have are:
&gt; &quot;does clamav scan memory mapped files?&quot;

Yes: After all, a file is just a file. In the end, it&#39;s all on disk.

&gt; Further details: If run clamscan or clamdscan on &quot;/&quot;; it would scan all files so it does not matter.
&gt; But how does clamonacc overcomes this limitation since it uses fanotify?

I doesn&#39;t (from the clamonacc man page):

The clamonacc daemon registers for file access notifications from the
Linux kernel and in response, submits scans to the clamd scanning
daemon for a verdict. On-Access requires a kernel version &gt;= 3.8,
because it leverages a kernel api called --&gt; fanotify &lt;-- to block
processes from attempting to access malicious files.

&gt; If it does, is there a way to ask clamav to scan just memory mapped files?

I&#39;m not sure if this can easily be detected.

I guess one could monitor mmap() calls via dtrace, but I&#39;m just guessing!

--
Ralf Hildebrandt
Charit&aelig;copy; - Universit&auml;tsmedizin Berlin
Gesch&auml;ftsbereich IT | Abteilung Netz | Netzwerk-Administration
Invalidenstra&szlig;e 120/121 | D-10115 Berlin

Tel. +49 30 450 570 155
[email protected]
https://www.charite.de
_______________________________________________

Manage your clamav-users mailing list subscription / unsubscribe:
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/Cisco-Talos/clamav-documentation

https://docs.clamav.net/#mailing-lists-and-chat

_______________________________________________

Manage your clamav-users mailing list subscription / unsubscribe:
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/Cisco-Talos/clamav-documentation

https://docs.clamav.net/#mailing-lists-and-chat
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.