Bug 13218 - SMB2 keepalive/echo terminates connection
Summary: SMB2 keepalive/echo terminates connection
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: libsmbclient (show other bugs)
Version: 4.7.0
Hardware: All Linux
: P5 normal (vote)
Target Milestone: ---
Assignee: Björn Jacke
QA Contact: Samba QA Contact
Depends on:
Reported: 2018-01-13 15:51 UTC by Jan (dead mail address)
Modified: 2022-08-29 09:05 UTC (History)
3 users (show)

See Also:

git-am fix for master. (1.94 KB, patch)
2019-12-11 23:17 UTC, Jeremy Allison
no flags Details
Corrected version that doesn't change the error return from 1 -> -1. (1.89 KB, patch)
2019-12-11 23:19 UTC, Jeremy Allison
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan (dead mail address) 2018-01-13 15:51:43 UTC
I think I am experiencing a bug in the implementation of SMB2 keepalives. As 
libsmbclient does not set the session for the echo request, the server used in 
my environment responds with STATUS_USER_SESSION_DELETED, which is the 
expected behavior (see [1,2]). As the server response indicates an 
error, the client disconnects. Ultimately, this leads to a new 
connection for every operation, which introduces painful delays.

I first experienced this behavior using libsmbclient 4.7.0 on a Fedora Linux 27. It looks like older versions would behave the same, but 4.7 was the first using SMB2 in my setup.

Unfortunately, I am not able to share PCAPs publicly.

Best regards,

[1] https://msdn.microsoft.com/en-us/library/cc246324.aspx
[2] https://msdn.microsoft.com/en-us/library/cc246482.aspx
Comment 1 Björn Jacke 2019-12-11 11:36:19 UTC
SMB2 does not have keep avlives at all. We still have a very old but I think that we send SMBv1 keep alives on port 445, where keep alive pacakges from smbd to a windows client lead to connection terminations. We should probably fix that one also one day.

You could send a pcap from a test system, won't you? Without a pcap we can only make guesses what kind of issue you actually see in your case.
Comment 2 Björn Jacke 2019-12-11 12:37:15 UTC
the SMBv1 keepalive bug is https://bugzilla.samba.org/show_bug.cgi?id=6558
Comment 3 Jeremy Allison 2019-12-11 21:22:58 UTC
OK, I've followed up on this. smbd as a server doesn't require a valid sessionid to process an incoming keepalive packet, which is why the libsmbclient code doesn't bother to send one.

What server are you talking to ?
Comment 4 Jeremy Allison 2019-12-11 21:30:32 UTC
Samba torture test source4/torture/smb2/session.c:test_session_expire2i()

shows that a sessionid is not required to process an SMB2_ECHO (called SMB2_OP_KEEPALIVE in the samba code).

There's a simple fix for this I can add to libsmbclient, but I think your server shouldn't be returning STATUS_USER_SESSION_DELETED for an SMB2 echo request.

Can you run all the Samba smb2.session.expire tests against your server ?
Comment 5 Jeremy Allison 2019-12-11 21:34:20 UTC
Remember these tests (smb2.session.expire) pass against Windows, which show that SMB2_ECHO requests don't require a valid sessionid, unless the transport is encrypted I think.
Comment 6 Jeremy Allison 2019-12-11 23:17:18 UTC
Created attachment 15676 [details]
git-am fix for master.

Can you test this fix against your server and let me know if it fixes the problem ?
Comment 7 Jeremy Allison 2019-12-11 23:19:08 UTC
Created attachment 15677 [details]
Corrected version that doesn't change the error return from 1 -> -1.
Comment 8 Jan (dead mail address) 2019-12-12 09:53:05 UTC
(In reply to Jeremy Allison from comment #7)
It will take me some time to do the testing. Thanks a lot for having a look!
Comment 9 Björn Jacke 2020-05-20 21:44:16 UTC
Jan: what were the results of your tests with the patch ?
Comment 10 Jan (dead mail address) 2020-05-22 10:48:59 UTC
I am very sorry but I haven't found the time to test the patch in the environment in which I could verify it works as intended.
Comment 11 Jeremy Allison 2022-02-15 19:02:32 UTC
Björn, do you think we should just push and then close this ? It seems harmless for Windows and Samba servers.
Comment 12 Björn Jacke 2022-02-16 00:23:25 UTC
I tend to agree, yes.

Jan: if you can't confirm that the patch works, can you at least say which SMB server implementation was used there?
Comment 13 Jeremy Allison 2022-04-05 19:57:06 UTC
Bjorn. Submitter seems to have lost interest. Let's just push.
Comment 14 Jeremy Allison 2022-05-11 16:25:58 UTC
Re-assigning to Bjorn so he will make a decision on this :-).
Comment 15 Samba QA Contact 2022-05-11 18:07:12 UTC
This bug was referenced in samba master:

Comment 16 Björn Jacke 2022-05-11 18:15:55 UTC
closing finally, will be in 4.17. If someone sees an urgent need for a fix in 4.16 or 4.15, feel free to reopen and request a backport.