Commit graph

11413 commits

Author SHA1 Message Date
Valerie Snyder
7bfe63f639
Extend config inline comment support to exclude leading tabs
E.g. this will also be valid:
```freshclam.conf
DatabaseMirror http://localhost:8000<tab># My private server.
```

Also:
- Fix compile warning regarding unnecessarily const string variable.
- Add parenthesis to resolve inconsistency between clang-format and
  vscode auto-format.
- Add a macro defining the max config line length.
2025-05-24 14:35:36 -04:00
Stiliyan Tonev (Bark)
f4af8b2081
Support for inline comments in clamd, freshclam, clamav-milter config files
The config parser will now treat a '#' character in a config file as an
inline comment, allowing users to write configs like this:
```freshclam.conf
DatabaseMirror http://localhost:8000  # My private server
```
2025-05-24 14:32:08 -04:00
Val S.
8ee78f8e79
Merge pull request #1495 from Cisco-Talos/CLAM-623-mydoom-fp
libclamav: Disable MyDoom heuristic by default.
2025-05-15 12:07:08 -04:00
John Humlick
eedc276b28
libclamav: Disable MyDoom heuristic by default.
The MyDoom heuristic has a track record of false positives and detection
should be handled via signatures instead.

CLAM-623
2025-05-07 14:37:11 -07:00
Val S.
66c049f27c
Merge pull request #1489 from val-ms/oss-fuzz-engine-free-certs_directory
Fix minor memory leak
2025-05-07 10:09:00 -04:00
Val S.
4bfaa20c86
Merge pull request #1491 from val-ms/CLAM-2751-openssl-sys_ubuntu-arm64
CMake/Rust openssl detection fix
2025-05-06 17:41:07 -04:00
Valerie Snyder
544fb9fef2
Codesign: fix test files & upgrade clamav-signature-util for related fix
The .sign test files have the min flevel set to 220.
It should be 230.

Also upgrade clamav-signature-util to v1.2.4 for fix so new .sign
files will have the correct min flevel.
2025-05-05 16:54:07 -04:00
Valerie Snyder
b32b85f6ac
Update Rust dependencies in Cargo.lock file to latest versions
Notably: resolve atty and openssl security warnings.
2025-05-01 13:58:48 -04:00
Valerie Snyder
3523202dd6
Fix issue when loading multiple icon (idb) signatures
The logic for loading an icon matcher assumes that only one .idb file is
loaded. If a second is loaded, the first is forgotten (memory leak).

This commit checks to see if `engine->iconcheck` is already allocated
and if so it will use that instead of allocating a new one.

I also cleaned up the error handling in this function, using goto-done
error handling.

I added proper cleanup for freeing the matcher in case of an idb
signature load error, copied from `cl_engine_free()`.
2025-05-01 13:58:43 -04:00
Valerie Snyder
b34cd8ca4e
Tests: Remove unecessary TCP options for non-Windows ClamD tests
The non-Windows ClamD tests use the LocalSocket option.
2025-05-01 10:45:39 -04:00
Valerie Snyder
8ac8f4ac8a
CMake: Improvement for CMake/Rust openssl detection
We observed build failures on Ubuntu 20.04 ARM64 because the Rust code
saw extra OpenSSL dependencies in the OPENSSL_LIBS environment variable
and was confused.

This change switches from using OPENSSL_LIBRARIES, which may have extra
dependencies for libcrypto/libssl, to only use OPENSSL_CRYPTO_LIBRARY
and OPENSSL_SSL_LIBRARY.
2025-04-30 12:35:19 -04:00
Valerie Snyder
0c9bccab31
Fix minor memory leak
The memory allocated for certs_directory in the ClamAV engine is not
free'd when the engine is free'd. This isn't readily apparent when using
a mempool because the mempool itself is free'd and the issue is masked.

Also: I found that the location in `cl_engine_free()` where we estimate
the number of tasks incorrectly placed the fuzzy_hashmap free task in
the block where we free the `test_root`, rather than up in the
`engine->root` for-loop. Fixed.
2025-04-28 11:45:18 -04:00
Shivam7-1
41aa292e97
Fix stack-buffer-overflow in parse_regex due to missing bounds checks (#1486)
Fixes: https://issues.oss-fuzz.com/issues/388922799
2025-04-24 15:33:26 -04:00
Val S.
00886ee90d
Merge pull request #1478 from val-ms/codesign-fixes-sys_rs
Fix several codesign feature bugs
2025-03-31 10:51:00 -04:00
Val Snyder
6490dde572
Update Rust dependencies in Cargo.lock file to latest versions 2025-03-29 21:05:38 -04:00
Val Snyder
200fe46b27
Update generated Rust sys.rs interface 2025-03-29 21:00:15 -04:00
Val Snyder
afb3d490e1
Fix several codesign bugs
We were signing with the signing key + signing cert and verifying
with the intermediate cert + root cert. However, we should have been
signing with the signing key + signing cert + intermediate cert, and
verifying with just the root cert.
To fix this, I...
1. Provided new certs and test file .sign files to use the correct
   signing method.
2. Restructured the `unit_tests/input/signing` directory to highlight
   which files are for signing and which are for verification.

There is a multi-arch build issue because I previously used i8 to
represent a C character. I switched it to c_char, which should fix the
clamav-debian multi-arch Docker image build.

It turns out we weren't failing out when signing if one of the provided
intermediate certificate paths is incorrect. Instead of using
`filter_map()`, I switched to just iterate the list to populate the
vector of intermediate certs.
2025-03-29 20:38:08 -04:00
Val S.
8ef70a4e6c
Merge pull request #1475 from val-ms/CLAM-2726-1.5-beta-prep
Clam 2726 1.5 beta prep
2025-03-28 14:33:40 -04:00
Val S.
a80db1b8e8
Merge pull request #1476 from val-ms/CLAM-2741-ai-model-file-type-detection
Add CL_TYPE_AI_MODEL and associated file type magic signatures
2025-03-28 14:32:27 -04:00
Val S.
1b32e8da44
Merge pull request #1417 from val-ms/CLAM-2677-2678-codesigning
Clam 2677 2678 FIPS compliant CVD codesigning
2025-03-28 13:50:52 -04:00
Val S.
1638ce2569
Merge pull request #1460 from frsell1/update_zip_parser
Extend zip parser to be less reliant on the central directory
2025-03-28 12:05:23 -04:00
frsell
1199c89c1d
Zip: Fix additional bugs found in PR review
Fix bug in end_offset calculation when searching for additional
file entries.

Fix size of memset after realloc.
2025-03-28 09:42:12 -04:00
Val Snyder
98011c1343
Release notes for 1.5.0-beta 2025-03-27 14:47:14 -04:00
Val Snyder
8a77214c82
Add CL_TYPE_AI_MODEL and associated file type magic signatures
This is just preliminary support for identifying an assortment of
different AI model files.

So far, this detects the following types:
- GGML GGUF (.gguf)
- ONNX AI (.onnx)
- TensorFlow Lite (.tflite)

Additional types to consider:
- SafeTensors (.safetensors)
- TensorFlow (.pb, .ckpt, .tfrecords)
- Keras (.keras)
- pickle (.pkl)
- numpy (.npy, .npz)
- coreml (.coreml)
- PyTorch (.pt, .pth, .bin, .mar, .pte, .pt2, .ptl)

Outside of being able to differentiate by file type, the scanner
will treat CL_TYPE_AI_MODEL the same as CL_TYPE_BINARY_DATA.
We're not adding parsers to further process these files, for now.
2025-03-27 14:30:40 -04:00
Val Snyder
272e84eaa8
Auto-format with clang-format 2025-03-26 20:00:14 -04:00
Val Snyder
8d485b9bfd
FIPS-compliant CVD signing and verification
Add X509 certificate chain based signing with PKCS7-PEM external
signatures distributed alongside CVD's in a custom .cvd.sign format.
This new signing and verification mechanism is primarily in support
of FIPS compliance.

Fixes: https://github.com/Cisco-Talos/clamav/issues/564

Add a Rust implementation for parsing, verifying, and unpacking CVD
files.

Now installs a 'certs' directory in the app config directory
(e.g. <prefix>/etc/certs). The install location is configurable.
The CMake option to configure the CVD certs directory is:
  `-D CVD_CERTS_DIRECTORY=PATH`

New options to set an alternative CVD certs directory:
- Commandline for freshclam, clamd, clamscan, and sigtool is:
  `--cvdcertsdir PATH`
- Env variable for freshclam, clamd, clamscan, and sigtool is:
  `CVD_CERTS_DIR`
- Config option for freshclam and clamd is:
  `CVDCertsDirectory PATH`

Sigtool:
- Add sign/verify commands.
- Also verify CDIFF external digital signatures when applying CDIFFs.
- Place commonly used commands at the top of --help string.
- Fix up manpage.

Freshclam:
- Will try to download .sign files to verify CVDs and CDIFFs.
- Fix an issue where making a CLD would only include the CFG file for
daily and not if patching any other database.

libclamav.so:
- Bump version to 13:0:1 (aka 12.1.0).
- Also remove libclamav.map versioning.
  Resolves: https://github.com/Cisco-Talos/clamav/issues/1304
- Add two new API's to the public clamav.h header:
  ```c
  extern cl_error_t cl_cvdverify_ex(const char *file,
                                    const char *certs_directory);

  extern cl_error_t cl_cvdunpack_ex(const char *file,
                                    const char *dir,
                                    bool dont_verify,
                                    const char *certs_directory);
  ```
  The original `cl_cvdverify` and `cl_cvdunpack` are deprecated.
- Add `cl_engine_field` enum option `CL_ENGINE_CVDCERTSDIR`.
  You may set this option with `cl_engine_set_str` and get it
  with `cl_engine_get_str`, to override the compiled in default
  CVD certs directory.

libfreshclam.so: Bump version to 4:0:0 (aka 4.0.0).

Add sigtool sign/verify tests and test certs.

Make it so downloadFile doesn't throw a warning if the server
doesn't have the .sign file.

Replace use of md5-based FP signatures in the unit tests with
sha256-based FP signatures because the md5 implementation used
by Python may be disabled in FIPS mode.
Fixes: https://github.com/Cisco-Talos/clamav/issues/1411

CMake: Add logic to enable the Rust openssl-sys / openssl-rs crates
to build against the same OpenSSL library as is used for the C build.
The Rust unit test application must also link directly with libcrypto
and libssl.

Fix some log messages with missing new lines.

Fix missing environment variable notes in --help messages and manpages.

Deconflict CONFDIR/DATADIR/CERTSDIR variable names that are defined in
clamav-config.h.in for libclamav from variable that had the same name
for use in clamav applications that use the optparser.

The 'clamav-test' certs for the unit tests will live for 10 years.
The 'clamav-beta.crt' public cert will only live for 120 days and will
be replaced before the stable release with a production 'clamav.crt'.
2025-03-26 19:33:25 -04:00
Val Snyder
96c00b6d80
Zip: Minor fixes, code cleanup
Fixes:

- We need to look at the local headers if no central directory headers are
  found. Restructured the main `cli_unzip()` function to allocate an empty
  zip catalogue when we can't use a central directory at all.

- In `index_local_file_headers_within_bounds()`, we must decrement the
  `coff` variable after adding the size of a file entry using
  `parse_local_file_header()`, to account for the increment when it loops
  around. If we don't, the next entry won't be at 'PK\x03\x04', it will be
  at 'K\0x03\x04'.

- Attempt to unzip when encrypted if we don't have a valid password.
  This may enable extraction for files where a header lies about encryption.

- The `fmap_need_off()` call to get the `compressed_data` pointer used the
  wrong size, checking if there was enough data for a header instead of
  for the compressed data that follows the header. I stumbled across this
  older bug when testing extraction of a zip where the file entries are
  tiny and I'd stripped off the central directory. As a result, there
  wasn't enough data for a whole file header and my test failed.

Cleanup:

- Initialize status variables as CL_ERROR and only assign to CL_SUCCESS if
  successful. This is to protect against future changes in case someone
  accidentally goes-to-done without setting the status.

- Remove legacy use of CL_CLEAN. Not a functional change.
  This mostly a stylistic preference.

- Use calloc instead of malloc + memset in a couple places.
  Make use of the new allocation macros with goto-done error handling.

- Some opinionated format changes such as shifting some longer function
  arguments all to a new line so they're no so far to the right.

- Auto-format with clang-format.
2025-03-25 12:48:52 -04:00
Val Snyder
9e96b63ef8
Tests: add tests for malformed and concatenated zips 2025-03-25 12:17:37 -04:00
frsell
8d8433b5ef
Zip: Extend parsing to rely less on central directory
Add logic to search for additional file entries between those that have
been found using the central directory.
2025-03-25 12:15:37 -04:00
Val Snyder
4a7ac7cc69
Version string to 1.5.0-beta; Bump flevel up to 230
1.4.0 elevated to LTS, so we reserve flevels 210-229.
2025-03-25 10:29:01 -04:00
Val S.
640413d9c5
Merge pull request #1470 from val-ms/CLAM-2736-windows-traverse-reparse-point
Windows: code quality improvement for --move and --remove options
2025-03-22 15:28:30 -04:00
Val S.
1e879873cc
Merge pull request #1469 from val-ms/CLAM-2745-zlib-zip64-undefined-behavior
Fix possible undefined behavior in inflate64 module
2025-03-19 18:02:33 -04:00
Micah Snyder
34bb516748
Windows: code quality improvement for --move and --remove options
When the --move or --remove options are used, ClamAV carefully traverses
the file path one layer at a time so as to avoid following a directory
that is a symlink or reparse point.
We do this for directories, but could also do it for files.
Only an admin should be able to create a reparse point for a file,
but it is better to be consistent.

Thank you to Maxim Suhanov for reporting this issue.
2025-03-19 17:36:05 -04:00
Val Snyder
3862134081
Fix possible undefined behavior in inflate64 module
The ClamAV inflate64 module is based on zlib 1.2.3 source code with
significant changes to support extracting zip64 and some addressing
code quality issues.

This commit adds a zlib v1.2.9 fix for possible undefined behavior:
6a043145ca

Thank you to TITAN Team for reporting this issue.
2025-03-19 09:46:19 -04:00
Val S.
4dab823609
Merge pull request #1465 from Cisco-Talos/CLAM-2742-memstats
clamd: Fix bug reporting memory stats, used by clamdtop
2025-03-13 14:35:20 -04:00
John Humlick
18120a0ef0
clamd: Fix bug reporting memory stats, used by clamdtop
ClamD's STATS API reports process memory stats on systems that
provide the `mallinfo()` system call.
This feature is used by ClamDTOP to show process memory usage.
When we switched to the CMake build system, we neglected to add the
check for the `mallinfo()` system call and so broke ClamD memory
usage reporting.

This commit adds the CMake check for `mallinfo()` and sets
HAVE_MALLINFO, if found.

Fixes: https://github.com/Cisco-Talos/clamav/issues/706

Jira: CLAM-2742
2025-03-13 10:38:49 -07:00
Val S.
492e505070
Merge pull request #1458 from val-ms/CLAM-2696-ole2-decrypt-overread
Fix bounds check in OLE2 decryption
2025-02-24 13:22:43 -05:00
Micah Snyder
e62b5e8d69
Fix bounds check in OLE2 decryption
The bounds check for the loop iterating an OLE2 block during decryption
may have an integer unerflow if the `leftover + bytesToWrite` is less
than 16. That results in a significant buffer over read and a segfault.

The fix is simply to do addition on the left side of the check instead
of subtraction on the right.

Fixes https://issues.oss-fuzz.com/issues/372544101
2025-02-24 11:59:06 -05:00
Val S.
1f214b268c
Merge pull request #1450 from val-ms/issue-1447-dead-code
Tests: remove dead code
2025-02-21 16:30:29 -05:00
Val S.
88e546be78
Merge pull request #1457 from val-ms/kamathmain
Add AIX variables for the load module function to work in AIX.
2025-02-21 13:46:01 -05:00
Micah Snyder
4b5130d50a
Tests: remove dead code
Remove check for 'srcdir' and 'unrar_disabled' variables.
These were only used by legacy Automake tooling.

Resolves: https://github.com/Cisco-Talos/clamav/issues/1447
2025-02-20 10:42:16 -05:00
Aditya Vidyadhar Kamath
ea5d30a216
Add AIX variables for the load module function to work in AIX.
Closes #1435.
2025-02-20 10:35:24 -05:00
Val S.
72805c52a4
Merge pull request #1453 from val-ms/windows-install-openssl-conflict
CMake: Fix Windows build issue w/ conflicting libraries
2025-02-14 12:07:44 -05:00
Val S.
63c87063af
Merge pull request #1454 from val-ms/bump-copyright-2025
Bump copyright dates for 2025
2025-02-14 12:03:02 -05:00
Val Snyder
7ff29b8c37
Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
Micah Snyder
1b504ef30d
CMake: Fix Windows build issue w/ conflicting libraries
At install, the CMake build may fail if it detects the same library
dependency in two locations. This happened for us with the following
error:

  CMake Error at libfreshclam/cmake_install.cmake:157 (file):
    file Multiple conflicting paths found for libcrypto-3-x64.dll:

      C:/Users/clamav_jenkins_svc.TALOS/clam_dependencies/x64/lib/libcrypto-3-x64.dll
      C:/WINDOWS/system32/libcrypto-3-x64.dll
      C:\WINDOWS\system32/libcrypto-3-x64.dll
  Call Stack (most recent call first):
    cmake_install.cmake:96 (include)

This happens when system provided DLL names match exactly with the ones
we provide. ClamAV woudld't prefer that DLL at load time, because it
looks in the EXE directory first. But it does confuse the `file()`
command used to locate build dependencies.

The fix in this commit uses a regex to exclude all libraries found under
C:\Windows
2025-02-13 20:07:46 -05:00
Val S.
f60e2db3ec
Merge pull request #1445 from ylecuyer/patch-1
Fix: TNEF dump hanging
2025-02-03 13:52:37 -05:00
Yoann Lecuyer
0b2ea8439d
Fix: TNEF dump hanging 2025-02-03 10:44:13 +01:00
Micah Snyder
86a3835218
Merge pull request #1398 from micahsnyder/CLAM-2712-freshclam-databasecustomurl-prune-bug
Freshclam: fix crash when using DatabaseCustomURL for CVD and other files
2025-01-12 17:08:09 -05:00
Micah Snyder
8a48e9e72b
Merge pull request #1366 from musicinmybrain/image-0.25
Update the image crate dependency to 0.25, the current release
2025-01-12 16:47:46 -05:00