Bug 14606 - vfs_virusfilter stops working after some time after startup
Summary: vfs_virusfilter stops working after some time after startup
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: VFS Modules (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: Samba QA Contact
Depends on:
Reported: 2021-01-02 04:54 UTC by Arne Kreddig
Modified: 2021-01-14 08:45 UTC (History)
3 users (show)

See Also:

Samba Log File (1.51 KB, text/plain)
2021-01-02 04:54 UTC, Arne Kreddig
no flags Details
git-am fix for 4.13.next. (5.72 KB, patch)
2021-01-07 23:00 UTC, Jeremy Allison
vl: review+
slow: review+
git-am fix for 4.12.next. (5.70 KB, patch)
2021-01-07 23:00 UTC, Jeremy Allison
vl: review+
slow: review+

Note You need to log in before you can comment on or make changes to this bug.
Description Arne Kreddig 2021-01-02 04:54:11 UTC
Created attachment 16372 [details]
Samba Log File

If samba is up for a while and vfs_virusfilter is used, the virusfilter will stop working after some time.

Steps to Reproduce:
I do not have a definitive 100% working method here. However, on both my productive system (home server) and my laptop, it happened persistently enough to debug a bit into it. Steps that I took:
  1) Start smbd
  2) Open a few Excel files on Windows 10 (on the samba share of course)
  3) Write and close and reopen the Excel-Files in a random fashion
  4) After some minutes (sometimes just seconds) the bug should occur

Actual result:
vfs_virusfilter stops working. According to the log file, it cannot connect to the ClamAV socket anymore. Judging from the log file (see attachment), the memory where the "virusfilter:socket path" configuration is stored gets overwritten by some seemingly random data (yes, I have set it correctly in the configuration file and directly after startup of smbd everything works and smbd communicates properly with the ClamAV socket).

Expected result:
vfs_virusfilter should keep working without overwriting its internal configuration memory.

Version 4.11.6-Ubuntu

Additional Information:
From my first investigation, it seems that the memory which holds the configuration gets freed and thus gets later allocated somewhere else and thus gets overwritten with some seemingly random data. I made a first attempt in fixing the bug here: https://gitlab.com/fr89k/samba/-/commit/6e0b8468195fac8f5791ca9e8eb25af0321b89ae
I think the configuration char pointers should be copied into a newly allocated memory during initialization of vfs_virusfilter. At least this is the way other vfs modules do it, as far as I have seen. However, due to lack of understanding of the samba software architecture, memory ownership, and memory allocation concepts, I am not sure if I identified the root cause correctly and if my fix is actually the correct way to fix the problem (or if I just introduced a new memory leak).
Comment 1 Samba QA Contact 2021-01-07 19:26:03 UTC
This bug was referenced in samba master:

Comment 2 Jeremy Allison 2021-01-07 23:00:14 UTC
Created attachment 16381 [details]
git-am fix for 4.13.next.
Comment 3 Jeremy Allison 2021-01-07 23:00:56 UTC
Created attachment 16382 [details]
git-am fix for 4.12.next.
Comment 4 Karolin Seeger 2021-01-08 07:56:17 UTC
Puhsed to autobuild-v4-{13,12}-test.
Comment 5 Samba QA Contact 2021-01-13 13:45:21 UTC
This bug was referenced in samba v4-12-test:

Comment 6 Samba QA Contact 2021-01-13 14:55:10 UTC
This bug was referenced in samba v4-13-test:

Comment 7 Samba QA Contact 2021-01-14 08:34:59 UTC
This bug was referenced in samba v4-12-stable (Release samba-4.12.11):

Comment 8 Karolin Seeger 2021-01-14 08:45:29 UTC
Closing out bug report.