Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 921617 - app-antivirus/clamav create socket directory /run/clamav/ with wrong permission 0710 instead of 0755
Summary: app-antivirus/clamav create socket directory /run/clamav/ with wrong permissi...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Antivirus Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-08 20:21 UTC by Matthias Nagel
Modified: 2024-01-16 01:45 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Nagel 2024-01-08 20:21:21 UTC
After installation or upgrade the socket directory /run/clamav has the permissions 0711 instead of 0755. This makes it impossible for any other program (e.g. Rspamd) to connect to the socket /run/clamav/clamd.ctl inside that directory, although the the client is a member of the clamav group as the group has no permission to read the directory. The correct permission should be 0755.

Note, the permissions on the socket file itself are fine and are set by the clamd daemon itself when the daemon starts according to the daemon's configuration file.

Reproducible: Always

Steps to Reproduce:
1. (Re-)Emerge app-antivirus/clamav
2. /run/clamav has permissions 0711
Actual Results:  
/run/clamav has permissions 0711

Expected Results:  
/run/clamav should have permissions 0777
Comment 1 Mike Gilbert gentoo-dev 2024-01-09 04:42:01 UTC
The execute bit on a directory allows files within the directory to be accessed.

The read bit on a directory allows files within the directory to be listed.

I don't see any obvious reason random programs would need to list the contents of /run/clamav. Mode 0711 should suffice.
Comment 2 Matthias Nagel 2024-01-09 07:26:18 UTC
I haven't looked into the implementation of rspamd, but fact is that rspamd cannot connect to clamav, if the directory permissions are 0711. The issue vanishes, if the permissions are set to 0755 manually. Currently, I fix this issue by remembering to change the permissions after an (re-)emerge of clamav. Maybe, rspamd first tries to open the directory for reading, I don't know. You could call this a bug on rspamd side, but this would have to fixed upstream by rspamd while the directory permissions are something which Gentoo can fix itself.

Also, there is nothing inside the directory which isn't public information. Hence, 0755 should be fine, too. Moreover, 0755 would be more consistent with all the other directories below /run/ which store daemon sockets. Currently,.clamav is the only package (at least the only package I have installed) which uses an overly restricted 0711 for its directory. All other services which create directories with sockets (PHP FPM, rspamd, PostgeSQL, Postfix, Dovecot, ...) also use 0755 for their directory.

I guess 0755 is so usual that this is the only case which gets enough upstream attention and becomes tested. 0711 is causing problems and probably will continue to cause problems, if it isn't used widespread.
Comment 3 Michael Orlitzky gentoo-dev 2024-01-09 14:04:11 UTC
No objection from me, the OpenRC service scripts are using 755.
Comment 4 Mike Gilbert gentoo-dev 2024-01-09 16:25:09 UTC
After installing app-antivirus/clamav-1.2.1, /run/clamav looks like this:

drwx--x--- 2 clamav clamav 40 Jan  9 11:21 /run/clamav

That is mode 0710, not 0711. That's a big difference, and it would explain why rspamd is unable to access the socket.

That mode appears to come from the tmpfiles.d entry:

% cat /usr/lib/tmpfiles.d/clamav.conf
d /run/clamav 0710 clamav clamav

This tmpfiles entry should probably be updated with a more permissive mode.
Comment 5 Michael Orlitzky gentoo-dev 2024-01-09 16:46:43 UTC
The 710 was probably reasonable at the time. The "standard" advice from random how-to pages on the internet was to add your mail filter to the clamav group or vice-versa to ensure that e.g. clamd (running as clamav) could access the files that the mail filter (running as e.g. amavis) is trying to scan. If you do that, then mode 0710 will suffice.

But, a better approach (especially when it comes to distro packaging) is to run "clamd --fdpass" from the mail filter. That uses a standard UNIX trick that allows clamd to read the mail filter's files via their descriptors. With that, anyone can scan any file that he can read, and there's no need to mess with the users and groups on your system. You do however need to be able to traverse /run/clamav as an unprivileged user to write to the socket.

Regardless of what rspamd is doing, the default in amavisd is now to use --fdpass, and the wiki says not to mess with the users/groups. For that to work on systemd, /run/clamav should be world-traversable.
Comment 6 Larry the Git Cow gentoo-dev 2024-01-16 01:45:57 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=873ea574ea7e050bd7f1a7d4297528d3b2e5592e

commit 873ea574ea7e050bd7f1a7d4297528d3b2e5592e
Author:     Michael Orlitzky <mjo@gentoo.org>
AuthorDate: 2024-01-16 01:14:32 +0000
Commit:     Michael Orlitzky <mjo@gentoo.org>
CommitDate: 2024-01-16 01:35:10 +0000

    app-antivirus/clamav: fix LTS socket permissions under systemd
    
    Bug: https://bugs.gentoo.org/921617
    Signed-off-by: Michael Orlitzky <mjo@gentoo.org>

 .../{clamav-0.103.11.ebuild => clamav-0.103.11-r1.ebuild}     | 11 ++++-------
 app-antivirus/clamav/files/tmpfiles.d/clamav-r1.conf          |  1 +
 2 files changed, 5 insertions(+), 7 deletions(-)