Bug 15282 - smbstatus leaking files in msg.sock and msg.lock
Summary: smbstatus leaking files in msg.sock and msg.lock
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.15.13
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jule Anger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-11 08:53 UTC by Jones Syue
Modified: 2023-01-26 17:52 UTC (History)
3 users (show)

See Also:


Attachments
git-am fix for 4.17.next (1.79 KB, patch)
2023-01-11 22:31 UTC, Jeremy Allison
jra: review? (slow)
vl: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jones Syue 2023-01-11 08:53:26 UTC
If the locking.tdb is not found,
(for example, fresh new installed samba server is not running yet)
smbstatus utility would exit earlier,
and lock files are left behind in the directory 'msg.sock' and 'msg.lock'.
Consider that a script to run smbstatus utility in a loop,
this might result in used space slowly growing-up on the underlying filesystem.
Since the samba server is not running yet,
there is no cleanupd daemon could delete these files to reclaim space.

Supposed to use 'ret = 0; goto done;' instead of exit(0),
this would go through the cmdline_messaging_context_free() which deletes 
the lock files in the directory msg.sock and msg.lock before smbstatus 
utility is exiting.

patch will follow.
Comment 1 Jones Syue 2023-01-11 13:06:08 UTC
1) Before patch:
smbstatus utility would exit earlier if locking.tbd is not found,
the lock entries '16059' are left behind in the 'msg.sock' and 'msg.lock'.

# smbstatus -L
/var/lock/.samba/lock/locking.tdb not initialised
This is normal if an SMB client has never connected to your server.
# ls -l /var/lock/.samba/lock/msg.lock/ /usr/local/samba/private/msg.sock/
/usr/local/samba/private/msg.sock/:
total 0
srwxr-xr-x 1 admin administrators 0 Jan 11 20:45 16059=

/var/lock/.samba/lock/msg.lock/:
total 4
-rw-r--r-- 1 admin administrators 20 Jan 11 20:45 16059
#

strace shows that the lock entries are created and left behind, not deleted.

# strace smbstatus -L 2>&1 | grep "msg..ock/"
open("/var/lock/.samba/lock/msg.lock/21922", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 4
unlink("/usr/local/samba/private/msg.sock/21922") = -1 ENOENT (No such file or directory)
bind(5, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/21922"}, 110) = 0
# 

2) After patch:
strace show that the lock entries are created and then deleted before 
smbstatus is exiting.

# strace smbstatus -L 2>&1 | grep "msg..ock/"
open("/var/lock/.samba/lock/msg.lock/23482", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 4
unlink("/usr/local/samba/private/msg.sock/23482") = -1 ENOENT (No such file or directory)
bind(5, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/23482"}, 110) = 0
unlink("/usr/local/samba/private/msg.sock/23482") = 0
unlink("/var/lock/.samba/lock/msg.lock/23482") = 0
# 

strace with '-k' shows that the destructor is triggered.

# strace -k smbstatus -L
... ...
unlink("/usr/local/samba/private/msg.sock/25539") = 0
 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x12a) [0x370a]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40]
 > /share/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x540bc]
 > /share/samba/bin/smbstatus(main+0x4d3) [0x3a73]
 > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810]
 > /share/samba/bin/smbstatus(_start+0x29) [0x4059]
unlink("/var/lock/.samba/lock/msg.lock/25539") = 0
 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x155) [0x3735]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40]
 > /share/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x540bc]
 > /share/samba/bin/smbstatus(main+0x4d3) [0x3a73]
 > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810]
 > /share/samba/bin/smbstatus(_start+0x29) [0x4059]
Comment 3 Samba QA Contact 2023-01-11 17:09:11 UTC
This bug was referenced in samba master:

de5d31f452b2445bd92b1746efb05aa096716af8
Comment 4 Jeremy Allison 2023-01-11 22:31:12 UTC
Created attachment 17724 [details]
git-am fix for 4.17.next

Cherry-picked from master.
Comment 5 Samba QA Contact 2023-01-13 11:57:27 UTC
This bug was referenced in samba v4-17-test:

0bc115f75704c9dbad86117fd40b023920f31986
Comment 6 Jule Anger 2023-01-13 12:15:22 UTC
Closing out bug report.

Thanks!
Comment 7 Jones Syue 2023-01-16 09:23:25 UTC
Thank you for kindly review! Just for reference:
my test version is 4.15.13, so 4.16 & 4.17 might have this issue too.
Comment 8 Samba QA Contact 2023-01-26 17:52:47 UTC
This bug was referenced in samba v4-17-stable (Release samba-4.17.5):

0bc115f75704c9dbad86117fd40b023920f31986