1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00
samba-mirror/source3
Stefan Metzmacher f348b84fbc s3:smbd: fix multichannel connection passing race
If a client opens multiple connection with the same
client guid in parallel, our connection passing is likely
to hit a race.

Assume we have 3 processes:

smbdA: This process already handles all connections for
       a given client guid
smbdB: This just received a new connection with an
       SMB2 neprot for the same client guid
smbdC: This also received a new connection with an
       SMB2 neprot for the same client guid

Now both smbdB and smbdC send a MSG_SMBXSRV_CONNECTION_PASS
message to smbdA. These messages contain the socket fd
for each connection.

While waiting for a MSG_SMBXSRV_CONNECTION_PASSED message
from smbdA, both smbdB and smbdC watch the smbXcli_client.tdb
record for changes (that also verifies smbdA stays alive).

Once one of them say smbdB received the MSG_SMBXSRV_CONNECTION_PASSED
message, the dbwrap_watch logic will wakeup smbdC in order to
let it recheck the smbXcli_client.tdb record in order to
handle the case where smbdA died or deleted its record.

Now smbdC rechecks the smbXcli_client.tdb record, but it
was not woken because of a problem with smbdA. It meant
that smbdC sends a MSG_SMBXSRV_CONNECTION_PASS message
including the socket fd again.

As a result smbdA got the socket fd from smbdC twice (or even more),
and creates two (or more) smbXsrv_connection structures for the
same low level tcp connection. And it also sends more than one
SMB2 negprot response. Depending on the tevent logic, it will
use different smbXsrv_connection structures to process incoming
requests. And this will almost immediately result in errors.

The typicall error is:
 smb2_validate_sequence_number: smb2_validate_sequence_number: bad message_id 2 (sequence id 2) (granted = 1, low = 1, range = 1)

But other errors would also be possible.

The detail that leads to the long delays on the client side is
that our smbd_server_connection_terminate_ex() code will close
only the fd of a single smbXsrv_connection, but the refcount
on the socket fd in the kernel is still not 0, so the tcp
connection is still alive...

Now we remember the server_id of the process that we send
the MSG_SMBXSRV_CONNECTION_PASS message to. And just keep
watching the smbXcli_client.tdb record if the server_id
don't change. As we just need more patience to wait for
the MSG_SMBXSRV_CONNECTION_PASSED message.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15346

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>

Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Tue Aug  8 13:59:58 UTC 2023 on atb-devel-224
2023-08-08 13:59:58 +00:00
..
auth s3:auth: Add missing newlines to logging messages 2023-08-08 04:39:37 +00:00
build
client s3:client: Remove unnecessary newline from logging message 2023-08-08 04:39:37 +00:00
exports
groupdb s3:groupdb: Add missing newline to logging message 2023-08-08 04:39:38 +00:00
include s3:include: Fix code spelling 2023-07-13 05:41:36 +00:00
intl
lib tldap: avoid infinite loop when filter contains "\)" 2023-08-08 04:39:39 +00:00
libads s3:libads: Add missing newlines to logging messages 2023-08-08 04:39:38 +00:00
libgpo/gpext
libnet s3:libnet: Add missing newline to logging message 2023-08-08 04:39:38 +00:00
librpc s3:librpc: Add missing newline to logging message 2023-08-08 04:39:38 +00:00
libsmb s3:libsmb: Add missing parenthesis to logging message 2023-08-08 04:39:38 +00:00
locale s3:utils: Fix code spelling 2023-08-08 04:39:38 +00:00
locking s3:locking: Fix code spelling 2023-07-17 11:46:29 +00:00
modules s3:vfs: Add missing space in debug message 2023-08-08 04:39:38 +00:00
nmbd s3:nmbd: Add missing newlines to logging messages 2023-08-08 04:39:38 +00:00
param s3:param: Fix code spelling 2023-07-19 09:58:37 +00:00
passdb s3:passdb: Fix typo 2023-08-08 04:39:38 +00:00
printing s3:printing: Fix code spelling 2023-08-08 04:39:38 +00:00
profile profiling: Factor out functions to read smbprofile.tdb 2023-06-16 16:14:30 +00:00
registry s3:registry: Add missing newlines to logging messages 2023-08-08 04:39:38 +00:00
rpc_client s3:rpc_client: Add missing newlines to logging messages 2023-08-08 04:39:38 +00:00
rpc_server s3:rpc_server: Fix typo 2023-08-08 04:39:38 +00:00
rpcclient CVE-2023-34968: mdssvc: introduce an allocating wrapper to sl_pack() 2023-07-21 12:05:35 +00:00
script sefltest: Add new regression test dfs with widelinks = yes 2023-07-28 23:50:32 +00:00
selftest sefltest: Add new regression test dfs with widelinks = yes 2023-07-28 23:50:32 +00:00
services s3:services: Disable rcinit-based service control code 2021-12-10 14:02:30 +00:00
smbd s3:smbd: fix multichannel connection passing race 2023-08-08 13:59:58 +00:00
torture s3: torture: Add test to show an SMB1 DFS path of "\\x//\\/" crashes smbd. 2023-07-27 09:59:29 +00:00
utils s3:utils: Fix code spelling 2023-08-08 04:39:38 +00:00
web
winbindd s3:winbindd: Fix debug messages 2023-08-08 04:39:38 +00:00
.clang_complete
.dmallocrc
.indent.pro
Doxyfile
mainpage.dox
smbadduser.in
wscript s3:waf: Fix code spelling 2023-07-19 09:58:37 +00:00
wscript_build profiling: Factor out functions to read smbprofile.tdb 2023-06-16 16:14:30 +00:00
wscript_configure_system_ncurses