s3:smbd: check for stale pid in delay_for_oplock_fn() when leases_db_get() fails master
authorStefan Metzmacher <metze@samba.org>
Mon, 6 Jul 2020 06:58:22 +0000 (08:58 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 7 Jul 2020 02:47:46 +0000 (02:47 +0000)
If leases_db_get() failed the leases_db record might have been cleaned up for
stale processes. Check if the share-mode-entry owner is stale in this case and
return ignore the entry. In any other case, log a debug messages and panic.

Commit 05d4466a6d1ad048fa86aea09ec0a56a7b961369
"smbd: check for stale pid in get_lease_type()" fixed only one half of
this.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Jul  7 02:47:46 UTC 2020 on sn-devel-184

source3/smbd/open.c

index 8f6d293c06fbecbce17dfd25134fea980ebfbb91..fa3d21fe38e805868ad07db9a1096516167e9821 100644 (file)
@@ -2463,7 +2463,42 @@ static bool delay_for_oplock_fn(
                        NULL, /* breaking_to_required */
                        NULL, /* lease_version */
                        NULL); /* epoch */
-               SMB_ASSERT(NT_STATUS_IS_OK(status));
+
+               /*
+                * leases_db_get() can return NT_STATUS_NOT_FOUND
+                * if the share_mode_entry e is stale and the
+                * lease record was already removed. In this case return
+                * false so the traverse continues.
+                */
+
+               if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND) &&
+                   share_entry_stale_pid(e))
+               {
+                       struct GUID_txt_buf guid_strbuf;
+                       struct file_id_buf file_id_strbuf;
+                       DBG_DEBUG("leases_db_get for client_guid [%s] "
+                                 "lease_key [%"PRIu64"/%"PRIu64"] "
+                                 "file_id [%s] failed for stale "
+                                 "share_mode_entry\n",
+                                 GUID_buf_string(&e->client_guid, &guid_strbuf),
+                                 e->lease_key.data[0],
+                                 e->lease_key.data[1],
+                                 file_id_str_buf(fsp->file_id, &file_id_strbuf));
+                       return false;
+               }
+               if (!NT_STATUS_IS_OK(status)) {
+                       struct GUID_txt_buf guid_strbuf;
+                       struct file_id_buf file_id_strbuf;
+                       DBG_ERR("leases_db_get for client_guid [%s] "
+                               "lease_key [%"PRIu64"/%"PRIu64"] "
+                               "file_id [%s] failed: %s\n",
+                               GUID_buf_string(&e->client_guid, &guid_strbuf),
+                               e->lease_key.data[0],
+                               e->lease_key.data[1],
+                               file_id_str_buf(fsp->file_id, &file_id_strbuf),
+                               nt_errstr(status));
+                       smb_panic("leases_db_get() failed");
+               }
        }
 
        if (!state->got_handle_lease &&