Repository navigation
Description
On small NethServer 8 nodes, the antivirus (ClamAV) of the Mail application takes many seconds to scan each message with attachments. Almost all of this time is spent on the TwinClams third-party signatures, which are enabled by default.
Steps to reproduce
-
Install the Mail application with default settings on a node with 2 vCPUs (virtual CPUs).
-
Wait for the first download of third-party signatures.
-
Scan a new 20 MB random file with the antivirus service (a new file ensures the result is not cached):
runagent -m mail1 podman exec clamav sh -c 'head -c 20000000 /dev/urandom > /tmp/r.bin; time clamdscan --stream --no-summary /tmp/r.bin; rm /tmp/r.bin'
Expected behavior
The scan takes a few seconds, in line with the other signature databases.
Actual behavior
The scan takes 49.3 s. With TwinClams filtered as described in the workaround below, the same test takes 5.4 s.
Scanning a ~19 MB file with one database at a time (clamscan -d <db> inside the clamav container) shows where the time goes:
| Database(s) | Signatures | Time |
|---|---|---|
eicar.ndb (baseline) |
1 | 0.5 s |
twinclams.ldb |
2968 | 22.8 s |
rfxn.yara |
3707 | 6.0 s |
| Sanesecurity + rfxn + InterServer | 180713 | 2.7 s |
| All databases | 201764 | 31.6 s |
The cost comes from the 1465 TwinClams signatures marked Target:0, which apply to any file type, so they are checked against every byte of every file, including archive contents. The other 1503 TwinClams signatures apply only to specific file types (Office documents, HTML, images…) and cost almost nothing: on a faster test machine, all TwinClams signatures take 9.7 s on a 20 MB file, and without Target:0 they take 1.1 s.
Impact: a 2 MB message with a .docx attachment becomes about 6 MB of data to scan once decoded. On the affected node this is estimated at 10–15 s per message.
Adding the signatures to an ignore list (.ign2) does not help, because ignored signatures are still loaded and checked.
Workaround
Tested on the affected node:
- Make the
clamav-unofficial-sigsconfiguration persistent, as described in the module README (CLAMAV_CUSCFG_VOLUME_FLAGS=Z). - Remove the TwinClams URLs from
additional_dbsin/etc/clamav-unofficial-sigs/user.confinside theclamavcontainer. - Download
twinclams.ldb, remove the lines containingTarget:0, and install the result as/var/lib/clamav/twinclams-filtered.ldb. Delete the originaltwinclams.ldbandtwinwave.ign2. - Reload the antivirus:
runagent -m mail1 systemctl --user reload clamav
To check it worked, run the test from "Steps to reproduce" again: on the affected node the time dropped from 49.3 s to 5.4 s. A script that automates these steps is available on request.
Proposal
Most TwinClams signatures target 2020–2022 Office macro campaigns: of those with a date in their name, about 80% are from 2020–2022 and only 46 are from 2025–2026. In order of preference:
- Disable TwinClams by default. Remove it from
additional_dbsand, on upgrade, deletetwinclams.ldbandtwinwave.ign2from/var/lib/clamav. - Keep TwinClams, but filtered, with a variable to turn it off. After each download, remove at least the
Target:0signatures. Add an environment variable, for exampleCLAMAV_TWINCLAMS_ENABLED, so administrators can turn TwinClams off completely without editinguser.confby hand.
Components
- Mail 1.9.3 (ClamAV 1.4.6)
See also
- https://mattermost.nethesis.it/nethesis/pl/rnf34ktiji858ngpbsjaesqcnc
- TwinClams signatures: https://github.com/twinwave-security/twinclams
Thanks to Luca D.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsToDo
Activity