From ff6e6aa66be358a30c76a93a3c7f3d6b0b558c38 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 2 Jul 2020 14:09:15 +0200 Subject: [PATCH 1/5] smbd: increase loglevel when leases_db_del() with anything then NT_STATUS_NOT_FOUND BUG: https://bugzilla.samba.org/show_bug.cgi?id=14428 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher (backported from commit fbb8bbe1243eb2a0351dc2422929278f85a99e26) [slow@samba.org: remove_lease_if_stale() does not exist in 4.11] --- source3/locking/locking.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 8fa1237d6ad..5272a3dc829 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -704,13 +704,16 @@ static void remove_share_mode_lease(struct share_mode_data *d, } { + int level = DBGLVL_DEBUG; NTSTATUS status; status = leases_db_del(&e->client_guid, &e->lease_key, &d->id); - - DEBUG(10, ("%s: leases_db_del returned %s\n", __func__, + if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { + level = DBGLVL_ERR; + } + DBG_PREFIX(level, ("leases_db_del failed: %s\n", nt_errstr(status))); } } -- 2.26.2 From 466fc30f8c4b834a29504b26d4f647f4ca7c71f5 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 2 Jul 2020 14:10:05 +0200 Subject: [PATCH 2/5] s3/leases: log NDR decoding failure with level 0 in leases_db_get_fn() BUG: https://bugzilla.samba.org/show_bug.cgi?id=14428 Signed-off-by: Ralph Boehme (cherry picked from commit 383a2457bd6cbe0acd571a8d601f8bdc5365f0b4) --- source3/locking/leases_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/locking/leases_db.c b/source3/locking/leases_db.c index 17778050acc..3c074c62751 100644 --- a/source3/locking/leases_db.c +++ b/source3/locking/leases_db.c @@ -544,8 +544,8 @@ static void leases_db_get_fn(TDB_DATA key, TDB_DATA data, void *private_data) &blob, value, value, (ndr_pull_flags_fn_t)ndr_pull_leases_db_value); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { - DBG_DEBUG("ndr_pull_struct_blob_failed: %s\n", - ndr_errstr(ndr_err)); + DBG_ERR("ndr_pull_struct_blob_failed: %s\n", + ndr_errstr(ndr_err)); TALLOC_FREE(value); state->status = ndr_map_error2ntstatus(ndr_err); return; -- 2.26.2 From 208a9bc869835954b6404e53a2a98aad21f357a6 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 2 Jul 2020 14:08:44 +0200 Subject: [PATCH 3/5] smbd: inverse if/else logic in get_lease_type() No change in behaviour. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14428 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher (backported from commit e4328db1c94837a8ea5652971cea20055d3d24ff) [slow@samba.org: take id from d as it's not passed as arg] --- source3/smbd/oplock.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index fe88adc9806..16484bb3d9d 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -175,24 +175,24 @@ static void downgrade_file_oplock(files_struct *fsp) uint32_t get_lease_type(const struct share_mode_data *d, const struct share_mode_entry *e) { - if (e->op_type == LEASE_OPLOCK) { - NTSTATUS status; - uint32_t current_state; + NTSTATUS status; + uint32_t current_state; - status = leases_db_get( - &e->client_guid, - &e->lease_key, - &d->id, - ¤t_state, - NULL, /* breaking */ - NULL, /* breaking_to_requested */ - NULL, /* breaking_to_required */ - NULL, /* lease_version */ - NULL); /* epoch */ - SMB_ASSERT(NT_STATUS_IS_OK(status)); - return current_state; - } - return map_oplock_to_lease_type(e->op_type); + if (e->op_type != LEASE_OPLOCK) { + return map_oplock_to_lease_type(e->op_type); + } + + status = leases_db_get(&e->client_guid, + &e->lease_key, + &d->id, + ¤t_state, + NULL, /* breaking */ + NULL, /* breaking_to_requested */ + NULL, /* breaking_to_required */ + NULL, /* lease_version */ + NULL); /* epoch */ + SMB_ASSERT(NT_STATUS_IS_OK(status)); + return current_state; } /**************************************************************************** -- 2.26.2 From 65c3f9c5f2a67b453341b7ed0059cd171f69eca0 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 2 Jul 2020 14:45:59 +0200 Subject: [PATCH 4/5] smbd: let get_lease_type() take a non-const share_mode_entry We're going to add a call to share_entry_stale_pid(share_mode_entry) which takes a non-const pointer (in order to eventually set e->state = true). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14428 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher (backported from commit 3f4a865821da27efbed4f7c38ad3efbcaae77a02) [slow@samba.org: get_lease_type() takes arg d in 4.11] --- source3/smbd/oplock.c | 2 +- source3/smbd/proto.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index 16484bb3d9d..957955bd635 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -173,7 +173,7 @@ static void downgrade_file_oplock(files_struct *fsp) } uint32_t get_lease_type(const struct share_mode_data *d, - const struct share_mode_entry *e) + struct share_mode_entry *e) { NTSTATUS status; uint32_t current_state; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 6e2509e7c57..825870bff05 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -721,7 +721,7 @@ NTSTATUS create_file_default(connection_struct *conn, /* The following definitions come from smbd/oplock.c */ uint32_t get_lease_type(const struct share_mode_data *d, - const struct share_mode_entry *e); + struct share_mode_entry *e); void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp); NTSTATUS set_file_oplock(files_struct *fsp); -- 2.26.2 From 54b7018d1465f0b5048190330609a110a80f5064 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 2 Jul 2020 14:47:12 +0200 Subject: [PATCH 5/5] smbd: check for stale pid in get_lease_type() 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 a 0 lease state. In any other case, log a debug messages and panic. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14428 Signed-off-by: Ralph Boehme Autobuild-User(master): Stefan Metzmacher Autobuild-Date(master): Thu Jul 2 16:45:42 UTC 2020 on sn-devel-184 (backported from commit 05d4466a6d1ad048fa86aea09ec0a56a7b961369) [slow@samba.org: use share_mode_stale_pid() instead of share_entry_stale_pid()] --- source3/smbd/oplock.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index 957955bd635..e34ef08579c 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -175,8 +175,11 @@ static void downgrade_file_oplock(files_struct *fsp) uint32_t get_lease_type(const struct share_mode_data *d, struct share_mode_entry *e) { + struct GUID_txt_buf guid_strbuf; + struct file_id_buf file_id_strbuf; NTSTATUS status; uint32_t current_state; + int idx; if (e->op_type != LEASE_OPLOCK) { return map_oplock_to_lease_type(e->op_type); @@ -191,8 +194,31 @@ uint32_t get_lease_type(const struct share_mode_data *d, NULL, /* breaking_to_required */ NULL, /* lease_version */ NULL); /* epoch */ - SMB_ASSERT(NT_STATUS_IS_OK(status)); - return current_state; + if (NT_STATUS_IS_OK(status)) { + return current_state; + } + + for (idx = 0; idx < d->num_share_modes; idx++) { + struct share_mode_entry *_e = &d->share_modes[idx]; + + if (_e->share_file_id = e->share_file_id) { + break; + } + } + SMB_ASSERT(idx < d->num_share_modes); + + if (share_mode_stale_pid(d, idx)) { + return 0; + } + 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(id, &file_id_strbuf), + nt_errstr(status)); + smb_panic("leases_db_get() failed"); } /**************************************************************************** -- 2.26.2