public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Chen Gang <gang.chen@asianux.com>,
	Jeff Layton <jlayton@redhat.com>,
	Shirish Pargaonkar <shirishpargaonkar@gmail.com>,
	Scott Lovenberg <scott.lovenberg@gmail.com>,
	Steve French <smfrench@gmail.com>
Subject: [ 11/17] cifs: extend the buffer length enought for sprintf() using
Date: Mon, 12 Aug 2013 23:35:57 -0700	[thread overview]
Message-ID: <20130813063502.630391496@linuxfoundation.org> (raw)
In-Reply-To: <20130813063501.728847844@linuxfoundation.org>

3.4-stable review patch.  If anyone has any objections, please let me know.

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

From: Chen Gang <gang.chen@asianux.com>

commit 057d6332b24a4497c55a761c83c823eed9e3f23b upstream.

For cifs_set_cifscreds() in "fs/cifs/connect.c", 'desc' buffer length
is 'CIFSCREDS_DESC_SIZE' (56 is less than 256), and 'ses->domainName'
length may be "255 + '\0'".

The related sprintf() may cause memory overflow, so need extend related
buffer enough to hold all things.

It is also necessary to be sure of 'ses->domainName' must be less than
256, and define the related macro instead of hard code number '256'.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Reviewed-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
Reviewed-by: Scott Lovenberg <scott.lovenberg@gmail.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/cifs/cifsencrypt.c |    2 +-
 fs/cifs/cifsglob.h    |    1 +
 fs/cifs/connect.c     |    7 ++++---
 fs/cifs/sess.c        |    6 +++---
 4 files changed, 9 insertions(+), 7 deletions(-)

--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -369,7 +369,7 @@ find_domain_name(struct cifs_ses *ses, c
 		if (blobptr + attrsize > blobend)
 			break;
 		if (type == NTLMSSP_AV_NB_DOMAIN_NAME) {
-			if (!attrsize)
+			if (!attrsize || attrsize >= CIFS_MAX_DOMAINNAME_LEN)
 				break;
 			if (!ses->domainName) {
 				ses->domainName =
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -38,6 +38,7 @@
 #define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1)
 #define MAX_SERVER_SIZE 15
 #define MAX_SHARE_SIZE 80
+#define CIFS_MAX_DOMAINNAME_LEN 256 /* max domain name length */
 #define MAX_USERNAME_SIZE 256	/* reasonable maximum for current servers */
 #define MAX_PASSWORD_SIZE 512	/* max for windows seems to be 256 wide chars */
 
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1698,7 +1698,8 @@ cifs_parse_mount_options(const char *mou
 			if (string == NULL)
 				goto out_nomem;
 
-			if (strnlen(string, 256) == 256) {
+			if (strnlen(string, CIFS_MAX_DOMAINNAME_LEN)
+					== CIFS_MAX_DOMAINNAME_LEN) {
 				printk(KERN_WARNING "CIFS: domain name too"
 						    " long\n");
 				goto cifs_parse_mount_err;
@@ -2356,8 +2357,8 @@ cifs_put_smb_ses(struct cifs_ses *ses)
 
 #ifdef CONFIG_KEYS
 
-/* strlen("cifs:a:") + INET6_ADDRSTRLEN + 1 */
-#define CIFSCREDS_DESC_SIZE (7 + INET6_ADDRSTRLEN + 1)
+/* strlen("cifs:a:") + CIFS_MAX_DOMAINNAME_LEN + 1 */
+#define CIFSCREDS_DESC_SIZE (7 + CIFS_MAX_DOMAINNAME_LEN + 1)
 
 /* Populate username and pw fields from keyring if possible */
 static int
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -198,7 +198,7 @@ static void unicode_domain_string(char *
 		bytes_ret = 0;
 	} else
 		bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->domainName,
-					    256, nls_cp);
+					    CIFS_MAX_DOMAINNAME_LEN, nls_cp);
 	bcc_ptr += 2 * bytes_ret;
 	bcc_ptr += 2;  /* account for null terminator */
 
@@ -256,8 +256,8 @@ static void ascii_ssetup_strings(char **
 
 	/* copy domain */
 	if (ses->domainName != NULL) {
-		strncpy(bcc_ptr, ses->domainName, 256);
-		bcc_ptr += strnlen(ses->domainName, 256);
+		strncpy(bcc_ptr, ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
+		bcc_ptr += strnlen(ses->domainName, CIFS_MAX_DOMAINNAME_LEN);
 	} /* else we will send a null domain name
 	     so the server will default to its own domain */
 	*bcc_ptr = 0;



  parent reply	other threads:[~2013-08-13  6:34 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-13  6:35 [ 00/17] 3.4.58-stable review Greg Kroah-Hartman
2013-08-13  6:35 ` [ 01/17] SCSI: Dont attempt to send extended INQUIRY command if skip_vpd_pages is set Greg Kroah-Hartman
2013-08-13  6:35 ` [ 02/17] SCSI: megaraid_sas: megaraid_sas driver init fails in kdump kernel Greg Kroah-Hartman
2013-08-13  6:35 ` [ 03/17] ext4: make sure group number is bumped after a inode allocation race Greg Kroah-Hartman
2013-08-13  6:35 ` [ 04/17] hwmon: (adt7470) Fix incorrect return code check Greg Kroah-Hartman
2013-08-13  6:35 ` [ 05/17] virtio: console: fix race with port unplug and open/close Greg Kroah-Hartman
2013-08-13  6:35 ` [ 06/17] virtio: console: fix race in port_fops_open() and port unplug Greg Kroah-Hartman
2013-08-13  6:35 ` [ 07/17] virtio: console: clean up port data immediately at time of unplug Greg Kroah-Hartman
2013-08-13  6:35 ` [ 08/17] virtio: console: fix raising SIGIO after port unplug Greg Kroah-Hartman
2013-08-13  6:35 ` [ 09/17] virtio: console: return -ENODEV on all read operations after unplug Greg Kroah-Hartman
2013-08-13  6:35 ` [ 10/17] ext4: fix mount/remount error messages for incompatible mount options Greg Kroah-Hartman
2013-08-13  6:35 ` Greg Kroah-Hartman [this message]
2013-08-13  6:35 ` [ 12/17] usb: core: dont try to reset_device() a port that got just disconnected Greg Kroah-Hartman
2013-08-13  6:35 ` [ 13/17] debugfs: debugfs_remove_recursive() must not rely on list_empty(d_subdirs) Greg Kroah-Hartman
2013-08-13  6:36 ` [ 14/17] tracing: Fix fields of struct trace_iterator that are zeroed by mistake Greg Kroah-Hartman
2013-08-13  6:36 ` [ 15/17] SCSI: nsp32: use mdelay instead of large udelay constants Greg Kroah-Hartman
2013-08-13  6:36 ` [ 16/17] vfs: d_obtain_alias() needs to use "/" as default name Greg Kroah-Hartman
2013-08-13  6:36 ` [ 17/17] perf tools: Add anonymous huge page recognition Greg Kroah-Hartman
2013-08-13 11:49 ` [ 00/17] 3.4.58-stable review Guenter Roeck
2013-08-13 17:58   ` Greg Kroah-Hartman
2013-08-13 20:19     ` Guenter Roeck
2013-08-13 20:49       ` Geert Uytterhoeven
2013-08-13 22:36         ` Guenter Roeck
2013-08-14  8:26           ` Geert Uytterhoeven
2013-08-14 10:14             ` Guenter Roeck
2013-08-15  6:36               ` Greg Kroah-Hartman
2013-08-15  7:08                 ` Guenter Roeck
2013-08-15  8:40                 ` Guenter Roeck
2013-08-16  0:54                   ` Greg Kroah-Hartman
2013-08-15  9:07                 ` Guenter Roeck
2013-08-16  0:58                   ` Greg Kroah-Hartman
2013-08-16  1:07                     ` Guenter Roeck
2013-08-15 14:45                 ` Guenter Roeck
2013-08-16  1:22                   ` Greg Kroah-Hartman
2013-08-16  1:28                     ` Guenter Roeck
2013-08-16  1:38                       ` Greg Kroah-Hartman
2013-08-15 15:12                 ` Guenter Roeck
2013-08-16  1:18                   ` Greg Kroah-Hartman
2013-08-15  6:35             ` Greg Kroah-Hartman
2013-08-15 16:54           ` Luis Henriques
2013-08-15  6:34         ` Greg Kroah-Hartman
2013-08-15  6:31       ` Greg Kroah-Hartman
2013-08-15  7:43         ` Guenter Roeck
2013-08-15  7:55           ` Geert Uytterhoeven
2013-08-15  8:05             ` Guenter Roeck
2013-08-16  4:53             ` Guenter Roeck
2013-08-16  5:10               ` Greg Kroah-Hartman
2013-08-16  8:26                 ` Guenter Roeck
2013-08-16 12:41                   ` Greg Kroah-Hartman
2013-08-16 20:27                     ` Guenter Roeck
2013-08-16 21:55                       ` Geert Uytterhoeven
2013-08-16 22:39                         ` Guenter Roeck
2013-08-16 23:08                           ` Greg Kroah-Hartman
2013-08-16  0:53           ` Greg Kroah-Hartman
2013-08-13 20:33     ` Guenter Roeck
2013-08-13 17:19 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130813063502.630391496@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=gang.chen@asianux.com \
    --cc=jlayton@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=scott.lovenberg@gmail.com \
    --cc=shirishpargaonkar@gmail.com \
    --cc=smfrench@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox