[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Mon May 1 12:40:02 UTC 2017


The branch, master has been updated
       via  2951c59 torture3: Make sure dbwrap_parse_record returns NOT_FOUND for invalid watchers data
       via  6f81f07 dbwrap_watch: Protect against corrupt records
       via  5e00fdd selftest: Make sure that LOCAL-DBWRAP-WATCH1 is run in make test
       via  63bb574 torture3: In LOCAL-DBWRAP-WATCH1, open tdb with CLEAR_IF_FIRST
      from  37ef287 Revert "lib/util: make use of tfork in samba_runcmd_send()"

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 2951c592f72b3c2f3e9318730063771846d7aa82
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 28 13:58:48 2017 +0200

    torture3: Make sure dbwrap_parse_record returns NOT_FOUND for invalid watchers data
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Mon May  1 14:39:41 CEST 2017 on sn-devel-144

commit 6f81f07303773d15ce16629c6759540b1d9adab7
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Mar 15 16:54:34 2017 +0100

    dbwrap_watch: Protect against corrupt records
    
    If locking.tdb contains invalid records, "get_file_infos" called from directory
    enumeration crashes in Samba 4.4. The reason is that if "dbwrap_watched_parse"
    returns -1 due to record corruption, dbwrap_watched_parse_record returns
    NT_STATUS_OK without having called the parse function. Before 66cba9939b76f
    this led to "lck->data" to be uninitialized data, so smbd 4.4 would crash in
    this case.  After 66cba9939b76f we implicitly initialize "state.lck" to NULL,
    so we don't have this particular problem anymore
    
    Apply the fix in master too, returning NT_STATUS_OK from parse_record without
    having called the parser could lead to bugs in other cases too.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5e00fdd4dd7a4ca67538527182ee0fd91c90df58
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 28 13:41:30 2017 +0200

    selftest: Make sure that LOCAL-DBWRAP-WATCH1 is run in make test
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 63bb5745f428ede34c533f9d965f9c042d529fe5
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 28 13:45:47 2017 +0200

    torture3: In LOCAL-DBWRAP-WATCH1, open tdb with CLEAR_IF_FIRST
    
    Also ensure we delete the temp tdb file on success.
    
    Just make sure we start with fresh data
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Signed-off-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/lib/dbwrap/dbwrap_watch.c   |  5 ++-
 source3/selftest/tests.py           |  2 ++
 source3/torture/proto.h             |  1 +
 source3/torture/test_dbwrap_watch.c | 71 ++++++++++++++++++++++++++++++++++++-
 source3/torture/torture.c           |  1 +
 5 files changed, 78 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index 6057bf4..585010f 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -521,7 +521,10 @@ static void dbwrap_watched_parse_record_parser(TDB_DATA key, TDB_DATA data,
 
 	num_watchers = dbwrap_watched_parse(data, NULL, 0, &state->deleted,
 					    &userdata);
-	if ((num_watchers == -1) || state->deleted) {
+	if (num_watchers == -1) {
+		state->deleted = true;
+	}
+	if (state->deleted) {
 		return;
 	}
 	state->parser(key, userdata, state->private_data);
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 9bb7903..1d02bd2 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -146,6 +146,8 @@ local_tests = [
     "LOCAL-MESSAGING-FDPASS2b",
     "LOCAL-PTHREADPOOL-TEVENT",
     "LOCAL-CANONICALIZE-PATH",
+    "LOCAL-DBWRAP-WATCH1",
+    "LOCAL-DBWRAP-WATCH2",
     "LOCAL-hex_encode_buf",
     "LOCAL-remove_duplicate_addrs2"]
 
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index da0c69f..129c05d 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -109,6 +109,7 @@ bool run_cleanup4(int dummy);
 bool run_notify_bench2(int dummy);
 bool run_notify_bench3(int dummy);
 bool run_dbwrap_watch1(int dummy);
+bool run_dbwrap_watch2(int dummy);
 bool run_idmap_tdb_common_test(int dummy);
 bool run_local_dbwrap_ctdb(int dummy);
 bool run_qpathinfo_bufsize(int dummy);
diff --git a/source3/torture/test_dbwrap_watch.c b/source3/torture/test_dbwrap_watch.c
index d3eac6f..5aa0430 100644
--- a/source3/torture/test_dbwrap_watch.c
+++ b/source3/torture/test_dbwrap_watch.c
@@ -48,7 +48,7 @@ bool run_dbwrap_watch1(int dummy)
 		fprintf(stderr, "messaging_init failed\n");
 		goto fail;
 	}
-	backend = db_open(msg, "test_watch.tdb", 0, TDB_DEFAULT,
+	backend = db_open(msg, "test_watch.tdb", 0, TDB_CLEAR_IF_FIRST,
 			  O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1,
 			  DBWRAP_FLAG_NONE);
 	if (backend == NULL) {
@@ -98,6 +98,7 @@ bool run_dbwrap_watch1(int dummy)
 		goto fail;
 	}
 
+	(void)unlink("test_watch.tdb");
 	ret = true;
 fail:
 	TALLOC_FREE(req);
@@ -107,3 +108,71 @@ fail:
 	TALLOC_FREE(ev);
 	return ret;
 }
+
+/*
+ * Make sure dbwrap_parse_record does not return NT_STATUS_OK on
+ * invalid data
+ */
+
+bool run_dbwrap_watch2(int dummy)
+{
+	struct tevent_context *ev = NULL;
+	struct messaging_context *msg = NULL;
+	struct db_context *backend = NULL;
+	struct db_context *db = NULL;
+	const char *keystr = "key";
+	TDB_DATA key = string_term_tdb_data(keystr);
+	NTSTATUS status;
+	bool ret = false;
+
+	ev = samba_tevent_context_init(talloc_tos());
+	if (ev == NULL) {
+		fprintf(stderr, "tevent_context_init failed\n");
+		goto fail;
+	}
+	msg = messaging_init(ev, ev);
+	if (msg == NULL) {
+		fprintf(stderr, "messaging_init failed\n");
+		goto fail;
+	}
+	backend = db_open(msg, "test_watch.tdb", 0, TDB_CLEAR_IF_FIRST,
+			  O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1,
+			  DBWRAP_FLAG_NONE);
+	if (backend == NULL) {
+		fprintf(stderr, "db_open failed: %s\n", strerror(errno));
+		goto fail;
+	}
+
+	/*
+	 * Store invalid data (from the dbwrap_watch point of view)
+	 * directly into the backend database
+	 */
+	status = dbwrap_store_uint32_bystring(backend, keystr, UINT32_MAX);
+	if (!NT_STATUS_IS_OK(status)) {
+		fprintf(stderr, "dbwrap_store_uint32_bystring failed: %s\n",
+			nt_errstr(status));
+		goto fail;
+	}
+
+	db = db_open_watched(ev, backend, msg);
+	if (db == NULL) {
+		fprintf(stderr, "db_open_watched failed\n");
+		goto fail;
+	}
+	backend = NULL;		/* open_watch talloc_moves backend */
+
+	status = dbwrap_parse_record(db, key, NULL, NULL);
+	if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+		fprintf(stderr, "dbwrap_parse_record returned %s, expected "
+			"NT_STATUS_NOT_FOUND\n", nt_errstr(status));
+		goto fail;
+	}
+
+	(void)unlink("test_watch.tdb");
+	ret = true;
+fail:
+	TALLOC_FREE(db);
+	TALLOC_FREE(msg);
+	TALLOC_FREE(ev);
+	return ret;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 0d9a653..bdcf1e1 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -11448,6 +11448,7 @@ static struct {
 	{ "LOCAL-GENCACHE", run_local_gencache, 0},
 	{ "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
 	{ "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
+	{ "LOCAL-DBWRAP-WATCH2", run_dbwrap_watch2, 0 },
 	{ "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
 	{ "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
 	{ "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },


-- 
Samba Shared Repository



More information about the samba-cvs mailing list