Commit graph

12 commits

Author SHA1 Message Date
micasnyd
140c88aa4e Bump copyright for 2022
Includes minor format corrections.
2022-01-09 14:23:25 -07:00
Mickey Sola
d0d0a8307c clamonacc: Fix segfault and socket fd leak
This fixes a fatal issue that would occur when unable to queue events due to
clamonacc improperly using all available fds.

It also fixes the core fd socket leak issue at the heart of the segfault by
properly cleaning up after a failed curl connection.

Lastly, worst case recovery code now allows more time for consumer queue
to catchup. It accomplishes this by increasing wait time and adding
retry logic.

More info: https://github.com/Cisco-Talos/clamav/issues/184
2021-08-05 17:33:21 -07:00
Micah Snyder
c025afd683 Rename "shared" library to "common"
The named "shared" is confusing, especially now that these features are
built as a static library instead of being directly compiled into the
various applications.
2021-04-20 17:31:19 -07:00
Andrew
81367e0829 Fixed several coverity warnings (error handling++)
Coverity warnings:
- 293628 Uninitialized pointer read - In reload_db: Reads
  an uninitialized pointer or its target. A fail case
  could lead to `rldata` being used before initialization

- 293627 Uninitialized pointer read - In reload_th: Reads
  an uninitialized pointer or its target. A fail case could
  lead to `engine` being used before initialization

- 265483 Uninitialized pointer write - In parseEmailFile:
  Write to target of an uninitialized pointer. A fail case
  could lead `ret` to be dereferenced and written to

- 265482 Resource leak - In parseEmailFile: Leak of memory
  or pointers to system resources.  A fail case could lead
  to `head` being leaked

- 225221 Resource leak - In onas_get_opt_list: Leak of memory
  or pointers to system resources. A fail case could lead to
  `opt_list` being leaked

- 225181 Resource leak - In onas_ht_rm_hierarchy: Leak of
  memory or pointers to system resources. A fail case could
  lead to `prntname` being leaked

- 193874 Resource leak - In cli_genfname: Leak of memory
  or pointers to system resources. A fail case could lead
  to `sanitized_prefix` being leaked

- 225196 Resource leak - In onas_fan_eloop: Leak of memory
  or pointers to system resources. A fail cases could lead
  to `event_data` being leaked

Also, I added some unresolved comments regarding clamonacc
functionality, and added a version compatibility check that
is shown in the example code in the `fanotify` man page
2021-04-02 12:58:11 -07:00
Micah Snyder (micasnyd)
b9ca6ea103 Update copyright dates for 2021
Also fixes up clang-format.
2021-03-19 15:12:26 -07:00
Micah Snyder
c522f45267 clamonacc: Reduce warning log verbosity
Users have complained about two specific log events that are extremely
verbose in non-critical error conditions:

- clamonacc reports "ERROR: Can't send to clamd: Bad address"

  This may occur when small files are created/destroyed before they can
  be sent to be scanned. The log message probably should only be
  reported in verbose mode.

- clamonacc reports "ClamMisc: $/proc/XXX vanished before UIDs could be
  excluded; scanning anyway"

  This may occur when a process that accessed a file exits before
  clamonacc find out who accessed the file. This is a fairly frequent
  occurence. It can still be problematic if `clamd` was the process which
  accessed the file (like a clamd temp file if watching /tmp), generally
  it's not an issue and we want to silently scan it anyways.

Also addressed copypaste issue in onas_send_stream() wherein fd is set
to 0 (aka STDIN) if the provided fd == 0 (should've been -1 for invalid
FD) and if filename == NULL. In fact clamonacc never scans STDIN so the
scan should fail if filename == NULL and the provided FD is invalid
(-1).

I also found that "Access denied. ERROR" is easily provoked when using
--fdpass or --stream using this simple script:

  for i in {1..5000}; do echo "blah $i" > tmp-$i && rm tmp-$i; done

Clamdscan does not allow for scans to fail quietly because the file does
not exist, but for clamonacc it's a common thing and we don't want to
output an error. To solve this, I changed it so a return length of -1
will still result in an "internal error" message but return len 0
failures will be silently ignored.

I've added a static variable to onas_client_scan() that keeps state in
case clamd is stopped and started - that way it won't print an error
message for every event when offline. Instead it will log an error for
the first connection failure, and log again when the connection is
re-established for a future scan. Calls to onas_client_scan() are
already wrapped with the onas_scan_lock mutex so the static variable
should be safe.

Finally, there were a couple of error responses from clamd that can
occur if the file isn't found which we want to silently ignore, so I've
tweaked the code which checks for specific error messages to account for
these.
2021-01-22 12:53:19 -08:00
Micah Snyder (micasnyd)
9e20cdf6ea Add CMake build tooling
This patch adds experimental-quality CMake build tooling.

The libmspack build required a modification to use "" instead of <> for
header #includes. This will hopefully be included in the libmspack
upstream project when adding CMake build tooling to libmspack.

Removed use of libltdl when using CMake.

Flex & Bison are now required to build.

If -DMAINTAINER_MODE, then GPERF is also required, though it currently
doesn't actually do anything.  TODO!

I found that the autotools build system was generating the lexer output
but not actually compiling it, instead using previously generated (and
manually renamed) lexer c source. As a consequence, changes to the .l
and .y files weren't making it into the build. To resolve this, I
removed generated flex/bison files and fixed the tooling to use the
freshly generated files. Flex and bison are now required build tools.
On Windows, this adds a dependency on the winflexbison package,
which can be obtained using Chocolatey or may be manually installed.

CMake tooling only has partial support for building with external LLVM
library, and no support for the internal LLVM (to be removed in the
future). I.e. The CMake build currently only supports the bytecode
interpreter.

Many files used include paths relative to the top source directory or
relative to the current project, rather than relative to each build
target. Modern CMake support requires including internal dependency
headers the same way you would external dependency headers (albeit
with "" instead of <>). This meant correcting all header includes to
be relative to the build targets and not relative to the workspace.

For example, ...

```c
include "../libclamav/clamav.h"
include "clamd/clamd_others.h"
```

... becomes:

```c
// libclamav
include "clamav.h"

// clamd
include "clamd_others.h"
```

Fixes header name conflicts by renaming a few of the files.

Converted the "shared" code into a static library, which depends on
libclamav. The ironically named "shared" static library provides
features common to the ClamAV apps which are not required in
libclamav itself and are not intended for use by downstream projects.
This change was required for correct modern CMake practices but was
also required to use the automake "subdir-objects" option.
This eliminates warnings when running autoreconf which, in the next
version of autoconf & automake are likely to break the build.

libclamav used to build in multiple stages where an earlier stage is
a static library containing utils required by the "shared" code.
Linking clamdscan and clamdtop with this libclamav utils static lib
allowed these two apps to function without libclamav. While this is
nice in theory, the practical gains are minimal and it complicates
the build system. As such, the autotools and CMake tooling was
simplified for improved maintainability and this feature was thrown
out. clamdtop and clamdscan now require libclamav to function.

Removed the nopthreads version of the autotools
libclamav_internal_utils static library and added pthread linking to
a couple apps that may have issues building on some platforms without
it, with the intention of removing needless complexity from the
source. Kept the regular version of libclamav_internal_utils.la
though it is no longer used anywhere but in libclamav.

Added an experimental doxygen build option which attempts to build
clamav.h and libfreshclam doxygen html docs.

The CMake build tooling also may build the example program(s), which
isn't a feature in the Autotools build system.

Changed C standard to C90+ due to inline linking issues with socket.h
when linking libfreshclam.so on Linux.

Generate common.rc for win32.

Fix tabs/spaces in shared Makefile.am, and remove vestigial ifndef
from misc.c.

Add CMake files to the automake dist, so users can try the new
CMake tooling w/out having to build from a git clone.

clamonacc changes:
- Renamed FANOTIFY macro to HAVE_SYS_FANOTIFY_H to better match other
  similar macros.
- Added a new clamav-clamonacc.service systemd unit file, based on
  the work of ChadDevOps & Aaron Brighton.
- Added missing clamonacc man page.

Updates to clamdscan man page, add missing options.

Remove vestigial CL_NOLIBCLAMAV definitions (all apps now use
libclamav).

Rename Windows mspack.dll to libmspack.dll so all ClamAV-built
libraries have the lib-prefix with Visual Studio as with CMake.
2020-08-13 00:25:34 -07:00
Mickey Sola
88ede3063f onas - fix warnings and remove unused variable 2020-02-03 09:08:00 -08:00
Micah Snyder
206dbaefe8 Update copyright dates for 2020 2020-01-03 15:44:07 -05:00
Mickey Sola
4fee702fc3 clamonacc - conform to clang-format 2019-10-02 16:08:29 -04:00
Mickey Sola
72c10bd1a5 clamonacc - fix distcheck, patch by Micah 2019-10-02 16:08:29 -04:00
Mickey Sola
78b1b1b4c6 clamonacc - rename/cleanup filenames, variables, and some logging to be more unified and explicit 2019-10-02 16:08:28 -04:00
Renamed from clamonacc/misc/onaccess_others.c (Browse further)