Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clamav freshclam fails when /var/log/clamav/freshclam.log does not exist #1155

Open
Atrate opened this issue Jan 25, 2024 · 5 comments · May be fixed by #1322
Open

Clamav freshclam fails when /var/log/clamav/freshclam.log does not exist #1155

Atrate opened this issue Jan 25, 2024 · 5 comments · May be fixed by #1322

Comments

@Atrate
Copy link

Atrate commented Jan 25, 2024

Describe the bug

When /var/log/clamav/freshclam.log does not exist (such as when /var/log is mounted as tmpfs to extend SSD (or SD card on rpis) longevity), freshclam does not create the log file and simply crashes (the systemd freshclam service).

How to reproduce the problem

  1. Mount /var/log/ as tmpfs.
  2. Reboot
  3. Start clamav-freshclam.service

Clamconf:

Checking configuration files in /etc/clamav

Config file: clamd.conf
-----------------------
LogFile = "/var/log/clamav/clamd.log"
LogTime = "yes"
PidFile = "/run/clamav/clamd.pid"
TemporaryDirectory = "/tmp"
LocalSocket = "/run/clamav/clamd.ctl"
User = "clamav"

Config file: freshclam.conf
---------------------------
PidFile = "/run/clamav/freshclam.pid"
UpdateLogFile = "/var/log/clamav/freshclam.log"
DatabaseMirror = "database.clamav.net"

Config file: clamav-milter.conf
-------------------------------
LogFile = "/var/log/clamav/clamav-milter.log"
LogTime = "yes"
PidFile = "/run/clamav/clamav-milter.pid"
TemporaryDirectory = "/tmp"
User = "clamav"

Software settings
-----------------
Version: 1.2.1
Optional features supported: MEMPOOL AUTOIT_EA06 BZIP2 LIBXML2 PCRE2 ICONV JSON RAR

Database information
--------------------
Database directory: /var/lib/clamav
bytecode.cvd: version 334, sigs: 91, built on Wed Feb 22 22:33:21 2023
main.cvd: version 62, sigs: 6647427, built on Thu Sep 16 14:32:42 2021
daily.cvd: version 27164, sigs: 2051511, built on Wed Jan 24 10:45:32 2024
Total number of signatures: 8699029

Platform information
--------------------
uname: Linux 6.6.13-hardened1-1-hardened #1 SMP PREEMPT_DYNAMIC Sun, 21 Jan 2024 00:24:54 +0000 x86_64
OS: Linux, ARCH: x86_64, CPU: x86_64
Full OS version: "Arch Linux"
zlib version: 1.3 (1.3), compile flags: a9
platform id: 0x0a21bfbf08000000000d0201

Build information
-----------------
GNU C: 13.2.1 20230801 (13.2.1)
sizeof(void*) = 8
Engine flevel: 191, dconf: 191

Attachments

Logs:

Jan 21 22:27:11 hostname systemd[1]: Started ClamAV virus database updater.
Jan 21 22:27:11 hostname freshclam[1322]: ERROR: lchown to user 'clamav' failed on
Jan 21 22:27:11 hostname freshclam[1322]: log file '/var/log/clamav/freshclam.log'.
Jan 21 22:27:11 hostname freshclam[1322]: Error was 'No such file or directory'
Jan 21 22:27:11 hostname freshclam[1322]: WARNING: lchown to user 'clamav' failed on log file '/var/log/clamav/freshclam.log'.  Error was 'No such file or directory'
Jan 21 22:27:11 hostname freshclam[1322]: ERROR: Failed to switch to clamav user.
Jan 21 22:27:11 hostname systemd[1]: clamav-freshclam.service: Main process exited, code=exited, status=9/n/a
Jan 21 22:27:11 hostname systemd[1]: clamav-freshclam.service: Failed with result 'exit-code'.
@Kiggins26
Copy link
Contributor

I can look into this and put a fix in for it

@micahsnyder
Copy link
Contributor

@Kiggins26 thanks I look forward to what you find.

I imagine the issue is that freshclam does not try to create the "clamav" subdirectory. It expects to be able to create "freshclam.log" directly and fails when the directory does not exist. I don't really

Something to consider if you try to change it so freshclam does try to create the missing subdirectories... If freshclam is run as root, then I think freshclam should chown that lowest subdirectory to be owned by the DatabaseOwner (most likely the "clamav" user) before creating the "freshclam.log" file.

@Kiggins26
Copy link
Contributor

Haven't gotten a lot of time to look at it. Have a potential fix, but have not recreated the issue. Someone can take it on if they would like, if not I will take a look at it in the following week

@DonKatsu
Copy link

I recently switched from Fedora to CachyOS (arch based). Installed clamav and enabled clamav-freshclam.service.
While going through my journal, I saw this error. Found this issue, throwing in my two cents.
On my system, /var is not mounted as a tmpfs. /var//log/clamav exists, but no freshclam.log is made. Checking the clamav-freshclam.service also showed the log failure, with the service not running.
I did touch /var/log/clamav/freshclam.log and rebooted. Now that error doesn't happen and the service runs successfully. The log is still empty at the moment.

On another machine still running Fedora 39, their clamav-freshclam doesn't seem to use a log? /var/log/clamav does not exist, yet the service runs with no error. Besides Fedora packaging freshclam separately, I don't know what else they do to it.

@userwiths
Copy link
Contributor

I think the PR above should suffice for a fix. I've put it in draft because I did not have enough time to test it to my liking, which I plan to do in the following days/week and move it for review when I think its solid enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants