public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	Chuck Ebbert <cebbert@redhat.com>,
	Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
	Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
	Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, Jeff Layton <jlayton@redhat.com>,
	Steve French <sfrench@us.ibm.com>
Subject: [patch 07/94] CIFS: make sure that DFS pathnames are properly formed
Date: Thu, 15 Jan 2009 11:57:27 -0800	[thread overview]
Message-ID: <20090115195727.GG14419@kroah.com> (raw)
In-Reply-To: <20090115195520.GA14403@kroah.com>

[-- Attachment #1: cifs-make-sure-that-dfs-pathnames-are-properly-formed.patch --]
[-- Type: text/plain, Size: 4529 bytes --]

2.6.28-stable review patch.  If anyone has any objections, please let us know.

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

From: Steve French <sfrench@us.ibm.com>

commit c6fbba0546d3ead18d4a623e76e28bcbaa66a325 upstream.

The paths in a DFS request are supposed to only have a single preceding
backslash, but we are sending them with a double backslash. This is
exposing a bug in Windows where it also sends a path in the response
that has a double backslash.

The existing code that builds the mount option string however expects a
double backslash prefix in a couple of places when it tries to use the
path returned by build_path_from_dentry. Fix compose_mount_options to
expect properly formed DFS paths (single backslash at front).

Also clean up error handling in that function. There was a possible
NULL pointer dereference and situations where a partially built option
string would be returned.

Tested against Samba 3.0.28-ish server and Samba 3.3 and Win2k8.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/cifs/cifs_dfs_ref.c |   48 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 12 deletions(-)

--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -122,7 +122,7 @@ static char *compose_mount_options(const
 				   char **devname)
 {
 	int rc;
-	char *mountdata;
+	char *mountdata = NULL;
 	int md_len;
 	char *tkn_e;
 	char *srvIP = NULL;
@@ -136,10 +136,9 @@ static char *compose_mount_options(const
 	*devname = cifs_get_share_name(ref->node_name);
 	rc = dns_resolve_server_name_to_ip(*devname, &srvIP);
 	if (rc != 0) {
-		cERROR(1, ("%s: Failed to resolve server part of %s to IP",
-			  __func__, *devname));
-		mountdata = ERR_PTR(rc);
-		goto compose_mount_options_out;
+		cERROR(1, ("%s: Failed to resolve server part of %s to IP: %d",
+			  __func__, *devname, rc));;
+		goto compose_mount_options_err;
 	}
 	/* md_len = strlen(...) + 12 for 'sep+prefixpath='
 	 * assuming that we have 'unc=' and 'ip=' in
@@ -149,8 +148,8 @@ static char *compose_mount_options(const
 		strlen(ref->node_name) + 12;
 	mountdata = kzalloc(md_len+1, GFP_KERNEL);
 	if (mountdata == NULL) {
-		mountdata = ERR_PTR(-ENOMEM);
-		goto compose_mount_options_out;
+		rc = -ENOMEM;
+		goto compose_mount_options_err;
 	}
 
 	/* copy all options except of unc,ip,prefixpath */
@@ -197,18 +196,32 @@ static char *compose_mount_options(const
 
 	/* find & copy prefixpath */
 	tkn_e = strchr(ref->node_name + 2, '\\');
-	if (tkn_e == NULL) /* invalid unc, missing share name*/
-		goto compose_mount_options_out;
+	if (tkn_e == NULL) {
+		/* invalid unc, missing share name*/
+		rc = -EINVAL;
+		goto compose_mount_options_err;
+	}
 
+	/*
+	 * this function gives us a path with a double backslash prefix. We
+	 * require a single backslash for DFS. Temporarily increment fullpath
+	 * to put it in the proper form and decrement before freeing it.
+	 */
 	fullpath = build_path_from_dentry(dentry);
+	if (!fullpath) {
+		rc = -ENOMEM;
+		goto compose_mount_options_err;
+	}
+	++fullpath;
 	tkn_e = strchr(tkn_e + 1, '\\');
-	if (tkn_e || strlen(fullpath) - (ref->path_consumed)) {
+	if (tkn_e || (strlen(fullpath) - ref->path_consumed)) {
 		strncat(mountdata, &sep, 1);
 		strcat(mountdata, "prefixpath=");
 		if (tkn_e)
 			strcat(mountdata, tkn_e + 1);
-		strcat(mountdata, fullpath + (ref->path_consumed));
+		strcat(mountdata, fullpath + ref->path_consumed);
 	}
+	--fullpath;
 	kfree(fullpath);
 
 	/*cFYI(1,("%s: parent mountdata: %s", __func__,sb_mountdata));*/
@@ -217,6 +230,11 @@ static char *compose_mount_options(const
 compose_mount_options_out:
 	kfree(srvIP);
 	return mountdata;
+
+compose_mount_options_err:
+	kfree(mountdata);
+	mountdata = ERR_PTR(rc);
+	goto compose_mount_options_out;
 }
 
 
@@ -309,13 +327,19 @@ cifs_dfs_follow_mountpoint(struct dentry
 		goto out_err;
 	}
 
+	/*
+	 * The MSDFS spec states that paths in DFS referral requests and
+	 * responses must be prefixed by a single '\' character instead of
+	 * the double backslashes usually used in the UNC. This function
+	 * gives us the latter, so we must adjust the result.
+	 */
 	full_path = build_path_from_dentry(dentry);
 	if (full_path == NULL) {
 		rc = -ENOMEM;
 		goto out_err;
 	}
 
-	rc = get_dfs_path(xid, ses , full_path, cifs_sb->local_nls,
+	rc = get_dfs_path(xid, ses , full_path + 1, cifs_sb->local_nls,
 		&num_referrals, &referrals,
 		cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
 


  parent reply	other threads:[~2009-01-15 20:04 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090115194806.804618825@mini.kroah.org>
2009-01-15 19:55 ` [patch 00/94] 2.6.28.1 stable review Greg KH
2009-01-15 19:57   ` [patch 01/94] ALSA: hda - Add quirk for another HP dv7 Greg KH
2009-01-15 19:57   ` [patch 02/94] ALSA: hda - Add quirk for HP6730B laptop Greg KH
2009-01-15 19:57   ` [patch 03/94] ALSA: caiaq - Fix Oops with MIDI Greg KH
2009-01-15 19:57   ` [patch 04/94] ALSA: hda - Fix typos for AD1882 codecs Greg KH
2009-01-15 19:57   ` [patch 05/94] x86: fix intel x86_64 llc_shared_map/cpu_llc_id anomolies Greg KH
2009-01-15 19:57   ` [patch 06/94] x86: default to SWIOTLB=y on x86_64 Greg KH
2009-01-15 19:57   ` Greg KH [this message]
2009-01-15 19:57   ` [patch 08/94] ring-buffer: prevent false positive warning Greg KH
2009-01-15 19:57   ` [patch 09/94] ring-buffer: fix dangling commit race Greg KH
2009-01-15 19:57   ` [patch 10/94] iwlwifi: use GFP_KERNEL to allocate Rx SKB memory Greg KH
2009-01-15 19:57   ` [patch 11/94] tx493[89]ide: Fix length for __ide_flush_dcache_range Greg KH
2009-01-15 19:57   ` [patch 12/94] tx4939ide: Do not use zero count PRD entry Greg KH
2009-01-15 19:57   ` [patch 13/94] SCSI: eata: fix the data buffer accessors conversion regression Greg KH
2009-01-15 19:57   ` [patch 14/94] USB: emi26: fix oops on load Greg KH
2009-01-15 19:57   ` [patch 15/94] x86, UV: remove erroneous BAU initialization Greg KH
2009-01-15 19:57   ` [patch 16/94] x86: fix incorrect __read_mostly on _boot_cpu_pda Greg KH
2009-01-15 19:57   ` [patch 17/94] vmalloc.c: fix flushing in vmap_page_range() Greg KH
2009-01-15 19:57   ` [patch 18/94] fs: symlink write_begin allocation context fix Greg KH
2009-01-15 19:57   ` [patch 19/94] cgroups: fix a race between cgroup_clone and umount Greg KH
2009-01-15 19:57   ` [patch 20/94] dm raid1: fix error count Greg KH
2009-01-15 19:58   ` [patch 21/94] dm log: fix dm_io_client leak on error paths Greg KH
2009-01-15 19:58   ` [patch 22/94] minix: fix add links wrong position calculation Greg KH
2009-01-15 19:58   ` [patch 23/94] md: fix bitmap-on-external-file bug Greg KH
2009-01-15 19:58   ` [patch 24/94] sched_clock: prevent scd->clock from moving backwards, take #2 Greg KH
2009-01-15 19:58   ` [patch 25/94] devices cgroup: allow mkfifo Greg KH
2009-01-15 19:58   ` [patch 26/94] SCSI: aha152x_cs: Fix regression that keeps driver from using shared interrupts Greg KH
2009-01-15 19:58   ` [patch 27/94] ioat: fix self test for multi-channel case Greg KH
2009-01-15 19:58   ` [patch 28/94] USB: isp1760: use a specific PLX bridge instead of any bdridge Greg KH
2009-01-15 19:58   ` [patch 29/94] USB: isp1760: Fix probe in PCI glue code Greg KH
2009-01-15 19:58   ` [patch 30/94] USB: unusual_devs.h additions for Pentax K10D Greg KH
2009-01-15 19:58   ` [patch 31/94] inotify: fix type errors in interfaces Greg KH
2009-01-15 19:58   ` [patch 32/94] [PATCH 01/44] [CVE-2009-0029] Move compat system call declarations to compat header file Greg KH
2009-01-15 19:58   ` [patch 33/94] [PATCH 02/44] [CVE-2009-0029] Convert all system calls to return a long Greg KH
2009-01-15 19:58   ` [patch 34/94] [PATCH 03/44] [CVE-2009-0029] Rename old_readdir to sys_old_readdir Greg KH
2009-01-15 19:58   ` [patch 35/94] [PATCH 04/44] [CVE-2009-0029] Remove __attribute__((weak)) from sys_pipe/sys_pipe2 Greg KH
2009-01-15 19:58   ` [patch 36/94] [PATCH 05/44] [CVE-2009-0029] Make sys_pselect7 static Greg KH
2009-01-15 19:58   ` [patch 37/94] [PATCH 06/44] [CVE-2009-0029] Make sys_syslog a conditional system call Greg KH
2009-01-15 19:58   ` [patch 38/94] [PATCH 07/44] [CVE-2009-0029] System call wrapper infrastructure Greg KH
2009-01-15 19:58   ` [patch 39/94] [PATCH 08/44] [CVE-2009-0029] powerpc: Enable syscall wrappers for 64-bit Greg KH
2009-01-15 19:58   ` [patch 40/94] [PATCH 09/44] [CVE-2009-0029] s390: enable system call wrappers Greg KH
2009-01-15 19:58   ` [patch 41/94] [PATCH 10/44] [CVE-2009-0029] System call wrapper special cases Greg KH
2009-01-15 19:58   ` [patch 42/94] [PATCH 11/44] [CVE-2009-0029] System call wrappers part 01 Greg KH
2009-01-16 11:00     ` Pavel Machek
2009-01-16 11:24       ` Heiko Carstens
2009-01-16 14:43         ` Pavel Machek
2009-01-16 15:00           ` [stable] " Greg KH
2009-01-15 19:58   ` [patch 43/94] [PATCH 12/44] [CVE-2009-0029] System call wrappers part 02 Greg KH
2009-01-15 19:58   ` [patch 44/94] [PATCH 13/44] [CVE-2009-0029] System call wrappers part 03 Greg KH
2009-01-15 19:58   ` [patch 45/94] [PATCH 14/44] [CVE-2009-0029] System call wrappers part 04 Greg KH
2009-01-15 19:58   ` [patch 46/94] [PATCH 15/44] [CVE-2009-0029] System call wrappers part 05 Greg KH
2009-01-15 19:58   ` [patch 47/94] [PATCH 16/44] [CVE-2009-0029] System call wrappers part 06 Greg KH
2009-01-15 19:59   ` [patch 48/94] [PATCH 17/44] [CVE-2009-0029] System call wrappers part 07 Greg KH
2009-01-15 19:59   ` [patch 49/94] [PATCH 18/44] [CVE-2009-0029] System call wrappers part 08 Greg KH
2009-01-15 19:59   ` [patch 50/94] [PATCH 19/44] [CVE-2009-0029] System call wrappers part 09 Greg KH
2009-01-15 19:59   ` [patch 51/94] [PATCH 20/44] [CVE-2009-0029] System call wrappers part 10 Greg KH
2009-01-15 19:59   ` [patch 52/94] [PATCH 21/44] [CVE-2009-0029] System call wrappers part 11 Greg KH
2009-01-15 19:59   ` [patch 53/94] [PATCH 22/44] [CVE-2009-0029] System call wrappers part 12 Greg KH
2009-01-15 19:59   ` [patch 54/94] [PATCH 23/44] [CVE-2009-0029] System call wrappers part 13 Greg KH
2009-01-15 19:59   ` [patch 55/94] [PATCH 24/44] [CVE-2009-0029] System call wrappers part 14 Greg KH
2009-01-15 19:59   ` [patch 56/94] [PATCH 25/44] [CVE-2009-0029] System call wrappers part 15 Greg KH
2009-01-15 19:59   ` [patch 57/94] [PATCH 26/44] [CVE-2009-0029] System call wrappers part 16 Greg KH
2009-01-15 19:59   ` [patch 58/94] [PATCH 27/44] [CVE-2009-0029] System call wrappers part 17 Greg KH
2009-01-15 19:59   ` [patch 59/94] [PATCH 28/44] [CVE-2009-0029] System call wrappers part 18 Greg KH
2009-01-15 19:59   ` [patch 60/94] [PATCH 29/44] [CVE-2009-0029] System call wrappers part 19 Greg KH
2009-01-15 19:59   ` [patch 61/94] [PATCH 30/44] [CVE-2009-0029] System call wrappers part 20 Greg KH
2009-01-15 19:59   ` [patch 62/94] [PATCH 31/44] [CVE-2009-0029] System call wrappers part 21 Greg KH
2009-01-15 19:59   ` [patch 63/94] [PATCH 32/44] [CVE-2009-0029] System call wrappers part 22 Greg KH
2009-01-15 19:59   ` [patch 64/94] [PATCH 33/44] [CVE-2009-0029] System call wrappers part 23 Greg KH
2009-01-15 19:59   ` [patch 65/94] [PATCH 34/44] [CVE-2009-0029] System call wrappers part 24 Greg KH
2009-01-15 19:59   ` [patch 66/94] [PATCH 35/44] [CVE-2009-0029] System call wrappers part 25 Greg KH
2009-01-15 19:59   ` [patch 67/94] [PATCH 36/44] [CVE-2009-0029] System call wrappers part 26 Greg KH
2009-01-15 19:59   ` [patch 68/94] [PATCH 37/44] [CVE-2009-0029] System call wrappers part 27 Greg KH
2009-01-15 19:59   ` [patch 69/94] [PATCH 38/44] [CVE-2009-0029] System call wrappers part 28 Greg KH
2009-01-15 19:59   ` [patch 70/94] [PATCH 39/44] [CVE-2009-0029] System call wrappers part 29 Greg KH
2009-01-15 20:00   ` [patch 71/94] [PATCH 40/44] [CVE-2009-0029] System call wrappers part 30 Greg KH
2009-01-15 20:00   ` [patch 72/94] [PATCH 41/44] [CVE-2009-0029] System call wrappers part 31 Greg KH
2009-01-15 20:00   ` [patch 73/94] [PATCH 42/44] [CVE-2009-0029] System call wrappers part 32 Greg KH
2009-01-15 20:00   ` [patch 74/94] [PATCH 43/44] [CVE-2009-0029] System call wrappers part 33 Greg KH
2009-01-15 20:00   ` [patch 75/94] [PATCH 44/44] [CVE-2009-0029] s390 specific system call wrappers Greg KH
2009-01-15 20:00   ` [patch 76/94] x86: fix RIP printout in early_idt_handler Greg KH
2009-01-15 20:00   ` [patch 77/94] Fix timeouts in sys_pselect7 Greg KH
2009-01-15 20:00   ` [patch 78/94] USB: another unusual_devs entry for another bad Argosy storage device Greg KH
2009-01-15 20:00   ` [patch 79/94] USB: storage: extend unusual range for 067b:3507 Greg KH
2009-01-15 20:00   ` [patch 80/94] USB: storage: recognizing and enabling Nokia 5200 cell phoes Greg KH
2009-01-15 20:00   ` [patch 81/94] HID: fix error condition propagation in hid-sony driver Greg KH
2009-01-15 20:00   ` [patch 82/94] fix switch_names() breakage in short-to-short case Greg KH
2009-01-15 20:00   ` [patch 83/94] nfs: remove redundant tests on reading new pages Greg KH
2009-01-15 20:00   ` [patch 84/94] eCryptfs: check readlink result was not an error before using it Greg KH
2009-01-15 20:00   ` [patch 85/94] [SCSI] mvsas: increase port type detection delay to suit Seagates 10k6 drive ST3450856SS 0003 Greg KH
2009-01-15 20:00   ` [patch 86/94] x86: avoid theoretical vmalloc fault loop Greg KH
2009-01-15 20:00   ` [patch 87/94] ath9k: enable RXing of beacons on STA/IBSS Greg KH
2009-01-15 20:00   ` [patch 88/94] mm lockless pagecache barrier fix Greg KH
2009-01-15 20:00   ` [patch 89/94] powerpc: Disable Collaborative Memory Manager for kdump Greg KH
2009-01-15 20:00   ` [patch 90/94] [SCSI] ibmvfc: Delay NPIV login retry and add retries Greg KH
2009-01-15 20:00   ` [patch 91/94] [SCSI] ibmvfc: Improve async event handling Greg KH
2009-01-15 20:00   ` [patch 92/94] getrusage: RUSAGE_THREAD should return ru_utime and ru_stime Greg KH
2009-01-15 20:00   ` [patch 93/94] ath5k: ignore the return value of ath5k_hw_noise_floor_calibration Greg KH
2009-01-15 20:00   ` [patch 94/94] mm: fix assertion Greg KH
2009-01-15 21:08   ` [patch 95/94] XFS: truncate readdir offsets to signed 32 bit values Greg KH
2009-01-15 21:10   ` [patch 00/94] 2.6.28.1 stable review Greg KH
     [not found]   ` <200901152200.04272.s.L-H@gmx.de>
2009-01-15 21:12     ` Greg KH
2009-01-15 21:26       ` Alan Stern
2009-01-15 21:19     ` Alan Stern
2009-01-15 21:27       ` Greg KH

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=20090115195727.GG14419@kroah.com \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=cavokz@gmail.com \
    --cc=cebbert@redhat.com \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=eteo@redhat.com \
    --cc=jake@lwn.net \
    --cc=jlayton@redhat.com \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkrufky@linuxtv.org \
    --cc=rbranco@la.checkpoint.com \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=sfrench@us.ibm.com \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=w@1wt.eu \
    --cc=zwane@arm.linux.org.uk \
    /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