[SCM] Samba Shared Repository - branch master updated

Karolin Seeger kseeger at samba.org
Wed Sep 20 15:07:02 UTC 2017


The branch, master has been updated
       via  b092ed3 CVE-2017-12163: s3:smbd: Prevent client short SMB1 write from writing server memory to file.
       via  35051a8 CVE-2017-12150: s3:libsmb: only fallback to anonymous if authentication was not requested
       via  22e22d8 CVE-2017-12150: libcli/smb: add smbXcli_conn_signing_mandatory()
       via  7074a1b CVE-2017-12150: auth/credentials: cli_credentials_authentication_requested() should check for NTLM_CCACHE/SIGN/SEAL
       via  6ca2cfa CVE-2017-12150: libgpo: make use of SMB_SIGNING_REQUIRED in gpo_connect_server()
       via  9c1ead5 CVE-2017-12150: s3:pylibsmb: make use of SMB_SIGNING_DEFAULT for 'samba.samba3.libsmb_samba_internal'
       via  52d967e CVE-2017-12150: s3:lib: get_cmdline_auth_info_signing_state smb_encrypt SMB_SIGNING_REQUIRED
       via  44b47f2 CVE-2017-12150: s3:popt_common: don't turn a guessed username into a specified one
       via  3d1c488 CVE-2017-12151: s3:libsmb: make use of cli_state_is_encryption_on()
       via  ace7274 CVE-2017-12151: s3:libsmb: add cli_state_is_encryption_on() helper function
      from  ee4418e dsdb: Only trigger a re-index once per @INDEXLIST modification

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


- Log -----------------------------------------------------------------
commit b092ed38423e23268c389aae4b6ed46682683c12
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Sep 8 10:13:14 2017 -0700

    CVE-2017-12163: s3:smbd: Prevent client short SMB1 write from writing server memory to file.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13020
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(master): Wed Sep 20 17:06:23 CEST 2017 on sn-devel-144

commit 35051a860c75bc119e0ac7755bd69a9ea06695a1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Dec 12 06:07:56 2016 +0100

    CVE-2017-12150: s3:libsmb: only fallback to anonymous if authentication was not requested
    
    With forced encryption or required signing we should also don't fallback.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 22e22d8f49626109dbdbca84a85c5148c23b8a2a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 29 15:35:49 2017 +0200

    CVE-2017-12150: libcli/smb: add smbXcli_conn_signing_mandatory()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 7074a1b7e0ddafa8f09a285cd9f3ae1f26d1709e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 29 15:24:14 2017 +0200

    CVE-2017-12150: auth/credentials: cli_credentials_authentication_requested() should check for NTLM_CCACHE/SIGN/SEAL
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 6ca2cfaff9d0b4203f6964d39a0930938a099e03
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Dec 12 05:49:46 2016 +0100

    CVE-2017-12150: libgpo: make use of SMB_SIGNING_REQUIRED in gpo_connect_server()
    
    It's important that we use a signed connection to get the GPOs!
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 9c1ead502bc3258d444ea0cd5f3148653419d298
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 9 09:26:32 2016 +0100

    CVE-2017-12150: s3:pylibsmb: make use of SMB_SIGNING_DEFAULT for 'samba.samba3.libsmb_samba_internal'
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 52d967e161420b5bc8b49d3597b4d34bfb5b13ac
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Nov 3 17:16:43 2016 +0100

    CVE-2017-12150: s3:lib: get_cmdline_auth_info_signing_state smb_encrypt SMB_SIGNING_REQUIRED
    
    This is an addition to the fixes for CVE-2015-5296.
    
    It applies to smb2mount -e, smbcacls -e and smbcquotas -e.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 44b47f2baec5336e94522938a93cb6b2a8898113
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 29 17:06:21 2017 +0200

    CVE-2017-12150: s3:popt_common: don't turn a guessed username into a specified one
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12997
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 3d1c488c8155f12488116d58c7794555d0dff49f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Dec 17 10:36:49 2016 +0100

    CVE-2017-12151: s3:libsmb: make use of cli_state_is_encryption_on()
    
    This will keep enforced encryption across dfs referrals.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12996
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit ace72741ada1497cf1dc76c9e0bae0a6cd15dd5e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 14 12:13:18 2017 +0200

    CVE-2017-12151: s3:libsmb: add cli_state_is_encryption_on() helper function
    
    This allows to check if the current cli_state uses encryption
    (either via unix extentions or via SMB3).
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12996
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 auth/credentials/credentials.c  | 16 +++++++++++++
 libcli/smb/smbXcli_base.c       |  5 +++++
 libcli/smb/smbXcli_base.h       |  1 +
 libgpo/gpo_fetch.c              |  2 +-
 source3/include/auth_info.h     |  1 +
 source3/lib/popt_common.c       |  7 +-----
 source3/lib/util_cmdline.c      | 32 ++++++++++++++++++++++++++
 source3/libsmb/clidfs.c         | 20 +++++------------
 source3/libsmb/clientgen.c      | 13 +++++++++++
 source3/libsmb/libsmb_context.c |  2 +-
 source3/libsmb/proto.h          |  1 +
 source3/libsmb/pylibsmb.c       |  2 +-
 source3/smbd/reply.c            | 50 +++++++++++++++++++++++++++++++++++++++++
 13 files changed, 129 insertions(+), 23 deletions(-)


Changeset truncated at 500 lines:

diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
index 105c73c..4f3042e 100644
--- a/auth/credentials/credentials.c
+++ b/auth/credentials/credentials.c
@@ -25,6 +25,7 @@
 #include "librpc/gen_ndr/samr.h" /* for struct samrPassword */
 #include "auth/credentials/credentials.h"
 #include "auth/credentials/credentials_internal.h"
+#include "auth/gensec/gensec.h"
 #include "libcli/auth/libcli_auth.h"
 #include "tevent.h"
 #include "param/param.h"
@@ -300,6 +301,8 @@ _PUBLIC_ bool cli_credentials_set_principal_callback(struct cli_credentials *cre
 
 _PUBLIC_ bool cli_credentials_authentication_requested(struct cli_credentials *cred) 
 {
+	uint32_t gensec_features = 0;
+
 	if (cred->bind_dn) {
 		return true;
 	}
@@ -327,6 +330,19 @@ _PUBLIC_ bool cli_credentials_authentication_requested(struct cli_credentials *c
 		return true;
 	}
 
+	gensec_features = cli_credentials_get_gensec_features(cred);
+	if (gensec_features & GENSEC_FEATURE_NTLM_CCACHE) {
+		return true;
+	}
+
+	if (gensec_features & GENSEC_FEATURE_SIGN) {
+		return true;
+	}
+
+	if (gensec_features & GENSEC_FEATURE_SEAL) {
+		return true;
+	}
+
 	return false;
 }
 
diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c
index 5493954..7322380 100644
--- a/libcli/smb/smbXcli_base.c
+++ b/libcli/smb/smbXcli_base.c
@@ -468,6 +468,11 @@ bool smbXcli_conn_use_unicode(struct smbXcli_conn *conn)
 	return false;
 }
 
+bool smbXcli_conn_signing_mandatory(struct smbXcli_conn *conn)
+{
+	return conn->mandatory_signing;
+}
+
 /*
  * [MS-SMB] 2.2.2.3.5 - SMB1 support for passing through
  * query/set commands to the file system
diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h
index 338f0a4..d0ee04f 100644
--- a/libcli/smb/smbXcli_base.h
+++ b/libcli/smb/smbXcli_base.h
@@ -47,6 +47,7 @@ bool smbXcli_conn_dfs_supported(struct smbXcli_conn *conn);
 
 enum protocol_types smbXcli_conn_protocol(struct smbXcli_conn *conn);
 bool smbXcli_conn_use_unicode(struct smbXcli_conn *conn);
+bool smbXcli_conn_signing_mandatory(struct smbXcli_conn *conn);
 bool smbXcli_conn_support_passthrough(struct smbXcli_conn *conn);
 
 void smbXcli_conn_set_sockopt(struct smbXcli_conn *conn, const char *options);
diff --git a/libgpo/gpo_fetch.c b/libgpo/gpo_fetch.c
index 836bc23..3740d4e 100644
--- a/libgpo/gpo_fetch.c
+++ b/libgpo/gpo_fetch.c
@@ -133,7 +133,7 @@ static NTSTATUS gpo_connect_server(ADS_STRUCT *ads,
 			ads->auth.password,
 			CLI_FULL_CONNECTION_USE_KERBEROS |
 			CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
-			Undefined);
+			SMB_SIGNING_REQUIRED);
 	if (!NT_STATUS_IS_OK(result)) {
 		DEBUG(10,("check_refresh_gpo: "
 				"failed to connect: %s\n",
diff --git a/source3/include/auth_info.h b/source3/include/auth_info.h
index c6f71ad..8212c27 100644
--- a/source3/include/auth_info.h
+++ b/source3/include/auth_info.h
@@ -29,6 +29,7 @@ void set_cmdline_auth_info_from_file(struct user_auth_info *auth_info,
 const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info);
 void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
 				    const char *username);
+void reset_cmdline_auth_info_username(struct user_auth_info *auth_info);
 const char *get_cmdline_auth_info_domain(const struct user_auth_info *auth_info);
 void set_cmdline_auth_info_domain(struct user_auth_info *auth_info,
 				  const char *domain);
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 65b6efe..cc93a75 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -247,8 +247,6 @@ void popt_common_credentials_set_delay_post(void)
 
 void popt_common_credentials_post(void)
 {
-	const char *username = NULL;
-
 	if (get_cmdline_auth_info_use_machine_account(cmdline_auth_info) &&
 	    !set_cmdline_auth_info_machine_account_creds(cmdline_auth_info))
 	{
@@ -268,10 +266,7 @@ void popt_common_credentials_post(void)
 	 * correctly parsed yet. If we have a username we need to set it again
 	 * to run the string parser for the username correctly.
 	 */
-	username = get_cmdline_auth_info_username(cmdline_auth_info);
-	if (username != NULL && username[0] != '\0') {
-		set_cmdline_auth_info_username(cmdline_auth_info, username);
-	}
+	reset_cmdline_auth_info_username(cmdline_auth_info);
 }
 
 static void popt_common_credentials_callback(poptContext con,
diff --git a/source3/lib/util_cmdline.c b/source3/lib/util_cmdline.c
index ad51a4f..90ee67c 100644
--- a/source3/lib/util_cmdline.c
+++ b/source3/lib/util_cmdline.c
@@ -37,6 +37,7 @@
 struct user_auth_info {
 	struct cli_credentials *creds;
 	struct loadparm_context *lp_ctx;
+	bool got_username;
 	bool got_pass;
 	int signing_state;
 	bool smb_encrypt;
@@ -93,6 +94,7 @@ void set_cmdline_auth_info_from_file(struct user_auth_info *auth_info,
 	if (!ok) {
 		exit(EIO);
 	}
+	auth_info->got_username = true;
 }
 
 const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info)
@@ -123,11 +125,38 @@ void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
 		exit(ENOMEM);
 	}
 
+	auth_info->got_username = true;
 	if (strchr_m(username, '%') != NULL) {
 		auth_info->got_pass = true;
 	}
 }
 
+void reset_cmdline_auth_info_username(struct user_auth_info *auth_info)
+{
+	const char *username = NULL;
+	const char *new_val = NULL;
+
+	if (!auth_info->got_username) {
+		return;
+	}
+
+	username = cli_credentials_get_username(auth_info->creds);
+	if (username == NULL) {
+		return;
+	}
+	if (username[0] == '\0') {
+		return;
+	}
+
+	cli_credentials_parse_string(auth_info->creds,
+				     username,
+				     CRED_SPECIFIED);
+	new_val = cli_credentials_get_username(auth_info->creds);
+	if (new_val == NULL) {
+		exit(ENOMEM);
+	}
+}
+
 const char *get_cmdline_auth_info_domain(const struct user_auth_info *auth_info)
 {
 	const char *domain = NULL;
@@ -236,6 +265,9 @@ void set_cmdline_auth_info_signing_state_raw(struct user_auth_info *auth_info,
 
 int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
 {
+	if (auth_info->smb_encrypt) {
+		return SMB_SIGNING_REQUIRED;
+	}
 	return auth_info->signing_state;
 }
 
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index 5cc220a..0dfb8b3 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -26,6 +26,7 @@
 #include "trans2.h"
 #include "libsmb/nmblib.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "auth/credentials/credentials.h"
 
 /********************************************************************
  Important point.
@@ -144,9 +145,6 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
 	char *servicename;
 	char *sharename;
 	char *newserver, *newshare;
-	const char *username;
-	const char *password;
-	const char *domain;
 	NTSTATUS status;
 	int flags = 0;
 	enum protocol_types protocol = PROTOCOL_NONE;
@@ -229,21 +227,15 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
 		smb2cli_conn_set_max_credits(c->conn, DEFAULT_SMB2_MAX_CREDITS);
 	}
 
-	username = get_cmdline_auth_info_username(auth_info);
-	password = get_cmdline_auth_info_password(auth_info);
-	domain = get_cmdline_auth_info_domain(auth_info);
-	if ((domain == NULL) || (domain[0] == '\0')) {
-		domain = lp_workgroup();
-	}
-
 	creds = get_cmdline_auth_info_creds(auth_info);
 
 	status = cli_session_setup_creds(c, creds);
 	if (!NT_STATUS_IS_OK(status)) {
 		/* If a password was not supplied then
 		 * try again with a null username. */
-		if (password[0] || !username[0] ||
-			get_cmdline_auth_info_use_kerberos(auth_info) ||
+		if (force_encrypt || smbXcli_conn_signing_mandatory(c->conn) ||
+			cli_credentials_authentication_requested(creds) ||
+			cli_credentials_is_anonymous(creds) ||
 			!NT_STATUS_IS_OK(status = cli_session_setup_anon(c)))
 		{
 			d_printf("session setup failed: %s\n",
@@ -995,7 +987,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
 			     smbXcli_conn_remote_name(rootcli->conn),
 			     "IPC$",
 			     dfs_auth_info,
-			     smb1cli_conn_encryption_on(rootcli->conn),
+			     cli_state_is_encryption_on(rootcli),
 			     smbXcli_conn_protocol(rootcli->conn),
 			     0,
 			     0x20,
@@ -1052,7 +1044,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
 				dfs_refs[count].server,
 				dfs_refs[count].share,
 				dfs_auth_info,
-				smb1cli_conn_encryption_on(rootcli->conn),
+				cli_state_is_encryption_on(rootcli),
 				smbXcli_conn_protocol(rootcli->conn),
 				0,
 				0x20,
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 039176e..44afee1 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -321,6 +321,19 @@ uint32_t cli_getpid(struct cli_state *cli)
 	return cli->smb1.pid;
 }
 
+bool cli_state_is_encryption_on(struct cli_state *cli)
+{
+	if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
+		return smb1cli_conn_encryption_on(cli->conn);
+	}
+
+	if (cli->smb2.tcon == NULL) {
+		return false;
+	}
+
+	return smb2cli_tcon_is_encryption_on(cli->smb2.tcon);
+}
+
 bool cli_state_has_tcon(struct cli_state *cli)
 {
 	uint32_t tid;
diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c
index ed6ca2b..b55cf1e 100644
--- a/source3/libsmb/libsmb_context.c
+++ b/source3/libsmb/libsmb_context.c
@@ -486,7 +486,7 @@ smbc_option_get(SMBCCTX *context,
 
                 for (s = context->internal->servers; s; s = s->next) {
                         num_servers++;
-                        if (!smb1cli_conn_encryption_on(s->cli->conn)) {
+                        if (!cli_state_is_encryption_on(s->cli)) {
                                 return (void *)false;
                         }
                 }
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index a74433f..4ae566c 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -200,6 +200,7 @@ void cli_shutdown(struct cli_state *cli);
 uint16_t cli_state_get_vc_num(struct cli_state *cli);
 uint32_t cli_setpid(struct cli_state *cli, uint32_t pid);
 uint32_t cli_getpid(struct cli_state *cli);
+bool cli_state_is_encryption_on(struct cli_state *cli);
 bool cli_state_has_tcon(struct cli_state *cli);
 uint32_t cli_state_get_tid(struct cli_state *cli);
 uint32_t cli_state_set_tid(struct cli_state *cli, uint32_t tid);
diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
index 39afdc8..d2167e9 100644
--- a/source3/libsmb/pylibsmb.c
+++ b/source3/libsmb/pylibsmb.c
@@ -451,7 +451,7 @@ static int py_cli_state_init(struct py_cli_state *self, PyObject *args,
 
 	req = cli_full_connection_creds_send(
 		NULL, self->ev, "myname", host, NULL, 0, share, "?????",
-		cli_creds, flags, 0);
+		cli_creds, flags, SMB_SIGNING_DEFAULT);
 	if (!py_tevent_req_wait_exc(self->ev, req)) {
 		return -1;
 	}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 317143f..7b07078 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -4474,6 +4474,9 @@ void reply_writebraw(struct smb_request *req)
 	}
 
 	/* Ensure we don't write bytes past the end of this packet. */
+	/*
+	 * This already protects us against CVE-2017-12163.
+	 */
 	if (data + numtowrite > smb_base(req->inbuf) + smb_len(req->inbuf)) {
 		reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
 		error_to_writebrawerr(req);
@@ -4574,6 +4577,11 @@ void reply_writebraw(struct smb_request *req)
 			exit_server_cleanly("secondary writebraw failed");
 		}
 
+		/*
+		 * We are not vulnerable to CVE-2017-12163
+		 * here as we are guarenteed to have numtowrite
+		 * bytes available - we just read from the client.
+		 */
 		nwritten = write_file(req,fsp,buf+4,startpos+nwritten,numtowrite);
 		if (nwritten == -1) {
 			TALLOC_FREE(buf);
@@ -4647,6 +4655,7 @@ void reply_writeunlock(struct smb_request *req)
 	connection_struct *conn = req->conn;
 	ssize_t nwritten = -1;
 	size_t numtowrite;
+	size_t remaining;
 	off_t startpos;
 	const char *data;
 	NTSTATUS status = NT_STATUS_OK;
@@ -4679,6 +4688,17 @@ void reply_writeunlock(struct smb_request *req)
 	startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
 	data = (const char *)req->buf + 3;
 
+	/*
+	 * Ensure client isn't asking us to write more than
+	 * they sent. CVE-2017-12163.
+	 */
+	remaining = smbreq_bufrem(req, data);
+	if (numtowrite > remaining) {
+		reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+		END_PROFILE(SMBwriteunlock);
+		return;
+	}
+
 	if (!fsp->print_file && numtowrite > 0) {
 		init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
 		    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
@@ -4756,6 +4776,7 @@ void reply_write(struct smb_request *req)
 {
 	connection_struct *conn = req->conn;
 	size_t numtowrite;
+	size_t remaining;
 	ssize_t nwritten = -1;
 	off_t startpos;
 	const char *data;
@@ -4796,6 +4817,17 @@ void reply_write(struct smb_request *req)
 	startpos = IVAL_TO_SMB_OFF_T(req->vwv+2, 0);
 	data = (const char *)req->buf + 3;
 
+	/*
+	 * Ensure client isn't asking us to write more than
+	 * they sent. CVE-2017-12163.
+	 */
+	remaining = smbreq_bufrem(req, data);
+	if (numtowrite > remaining) {
+		reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+		END_PROFILE(SMBwrite);
+		return;
+	}
+
 	if (!fsp->print_file) {
 		init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
 			(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
@@ -5018,6 +5050,9 @@ void reply_write_and_X(struct smb_request *req)
 			goto out;
 		}
 	} else {
+		/*
+		 * This already protects us against CVE-2017-12163.
+		 */
 		if (smb_doff > smblen || smb_doff + numtowrite < numtowrite ||
 				smb_doff + numtowrite > smblen) {
 			reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
@@ -5444,6 +5479,7 @@ void reply_writeclose(struct smb_request *req)
 {
 	connection_struct *conn = req->conn;
 	size_t numtowrite;
+	size_t remaining;
 	ssize_t nwritten = -1;
 	NTSTATUS close_status = NT_STATUS_OK;
 	off_t startpos;
@@ -5477,6 +5513,17 @@ void reply_writeclose(struct smb_request *req)
 	mtime = convert_time_t_to_timespec(srv_make_unix_date3(req->vwv+4));
 	data = (const char *)req->buf + 1;
 
+	/*
+	 * Ensure client isn't asking us to write more than
+	 * they sent. CVE-2017-12163.
+	 */
+	remaining = smbreq_bufrem(req, data);
+	if (numtowrite > remaining) {
+		reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+		END_PROFILE(SMBwriteclose);
+		return;
+	}
+
 	if (fsp->print_file == NULL) {
 		init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
 		    (uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
@@ -6069,6 +6116,9 @@ void reply_printwrite(struct smb_request *req)
 
 	numtowrite = SVAL(req->buf, 1);
 
+	/*
+	 * This already protects us against CVE-2017-12163.
+	 */
 	if (req->buflen < numtowrite + 3) {
 		reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
 		END_PROFILE(SMBsplwr);


-- 
Samba Shared Repository



More information about the samba-cvs mailing list