From 136c177e3d9d5fe01b74c07b71ce3040eebaa277 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 (cherry picked from commit fbb8bbe1243eb2a0351dc2422929278f85a99e26) --- source3/locking/locking.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 1220cb3a2be..2d9569809e4 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -728,8 +728,13 @@ NTSTATUS remove_lease_if_stale(struct share_mode_lock *lck, status = leases_db_del(client_guid, lease_key, &d->id); if (!NT_STATUS_IS_OK(status)) { - DBG_DEBUG("leases_db_del failed: %s\n", - nt_errstr(status)); + int level = DBGLVL_DEBUG; + + if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { + level = DBGLVL_ERR; + } + DBG_PREFIX(level, ("leases_db_del failed: %s\n", + nt_errstr(status))); } return status; } -- 2.26.2 From 337fb9e6506f94e3051e9131019de633ceb3ce2c 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 a12b421d260..2e2ccb150ac 100644 --- a/source3/locking/leases_db.c +++ b/source3/locking/leases_db.c @@ -549,8 +549,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 7b265888ae9282b5da25582bb66bc3c3ea188a66 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 (cherry picked from commit e4328db1c94837a8ea5652971cea20055d3d24ff) --- 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 2c4449b10b2..c63f97aac0a 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -171,24 +171,24 @@ static void downgrade_file_oplock(files_struct *fsp) uint32_t get_lease_type(const struct share_mode_entry *e, struct file_id id) { - 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, - &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, + &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 2c2848a62a51f46a4586ada9e84bfbe7d52229a5 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 (cherry picked from commit 3f4a865821da27efbed4f7c38ad3efbcaae77a02) --- 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 c63f97aac0a..97ab05b2ba6 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -169,7 +169,7 @@ static void downgrade_file_oplock(files_struct *fsp) TALLOC_FREE(fsp->oplock_timeout); } -uint32_t get_lease_type(const struct share_mode_entry *e, struct file_id id) +uint32_t get_lease_type(struct share_mode_entry *e, struct file_id id) { NTSTATUS status; uint32_t current_state; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 60941ce6c1b..ac021ad93fe 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -736,7 +736,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_entry *e, struct file_id id); +uint32_t get_lease_type(struct share_mode_entry *e, struct file_id id); void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp); NTSTATUS set_file_oplock(files_struct *fsp); -- 2.26.2 From 831f816922a3ab4505f577fec6c2efbbc6bb7c94 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 (cherry picked from commit 05d4466a6d1ad048fa86aea09ec0a56a7b961369) --- source3/smbd/oplock.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index 97ab05b2ba6..1c1510f3aab 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -171,6 +171,8 @@ static void downgrade_file_oplock(files_struct *fsp) uint32_t get_lease_type(struct share_mode_entry *e, struct file_id id) { + struct GUID_txt_buf guid_strbuf; + struct file_id_buf file_id_strbuf; NTSTATUS status; uint32_t current_state; @@ -187,8 +189,22 @@ uint32_t get_lease_type(struct share_mode_entry *e, struct file_id id) 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; + } + + if (share_entry_stale_pid(e)) { + 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