diff mbox

cifs: Handle big endianness in NTLM (ntlmv2) authentication

Message ID 1372175077-12846-1-git-send-email-shirishpargaonkar@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shirish Pargaonkar June 25, 2013, 3:44 p.m. UTC
From: Shirish Pargaonkar <shirishpargaonkar@gmail.com>


This is RH bug 970891
Uppercasing of username during calculation of ntlmv2 hash fails
because UniStrupr function does not handle big endian wchars.

Also fix a comment in the same code to reflect its correct usage.


Reported-by: steve <sanpatr1@in.ibm.com>
Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
Cc: <stable@kernel.org>
---
 fs/cifs/cifs_unicode.h |    2 +-
 fs/cifs/cifsencrypt.c  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Jeff Layton June 25, 2013, 5:49 p.m. UTC | #1
On Tue, 25 Jun 2013 10:44:37 -0500
shirishpargaonkar@gmail.com wrote:

> From: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
> 
> 
> This is RH bug 970891
> Uppercasing of username during calculation of ntlmv2 hash fails
> because UniStrupr function does not handle big endian wchars.
> 
> Also fix a comment in the same code to reflect its correct usage.
> 
> 
> Reported-by: steve <sanpatr1@in.ibm.com>
> Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
> Cc: <stable@kernel.org>
> ---
>  fs/cifs/cifs_unicode.h |    2 +-
>  fs/cifs/cifsencrypt.c  |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
> index 4fb0974..bec1137 100644
> --- a/fs/cifs/cifs_unicode.h
> +++ b/fs/cifs/cifs_unicode.h
> @@ -334,7 +334,7 @@ UniStrupr(register wchar_t *upin)
>  
>  	up = upin;
>  	while (*up) {		/* For all characters */
> -		*up = UniToupper(*up);
> +		*up = cpu_to_le16(UniToupper(le16_to_cpu(*up)));
>  		up++;
>  	}
>  	return upin;		/* Return input pointer */
> diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
> index 71436d1..8b34a73 100644
> --- a/fs/cifs/cifsencrypt.c
> +++ b/fs/cifs/cifsencrypt.c
> @@ -439,7 +439,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
>  		return rc;
>  	}
>  
> -	/* convert ses->user_name to unicode and uppercase */
> +	/* convert ses->user_name to unicode */
>  	len = ses->user_name ? strlen(ses->user_name) : 0;
>  	user = kmalloc(2 + (len * 2), GFP_KERNEL);
>  	if (user == NULL) {

Looks correct. Nice work tracking that down!

Reviewed-by: Jeff Layton <jlayton@redhat.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jeff Layton June 25, 2013, 5:54 p.m. UTC | #2
On Tue, 25 Jun 2013 13:49:29 -0400
Jeff Layton <jlayton@redhat.com> wrote:

> On Tue, 25 Jun 2013 10:44:37 -0500
> shirishpargaonkar@gmail.com wrote:
> 
> > From: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
> > 
> > 
> > This is RH bug 970891
> > Uppercasing of username during calculation of ntlmv2 hash fails
> > because UniStrupr function does not handle big endian wchars.
> > 
> > Also fix a comment in the same code to reflect its correct usage.
> > 
> > 
> > Reported-by: steve <sanpatr1@in.ibm.com>
> > Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
> > Cc: <stable@kernel.org>
> > ---
> >  fs/cifs/cifs_unicode.h |    2 +-
> >  fs/cifs/cifsencrypt.c  |    2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
> > index 4fb0974..bec1137 100644
> > --- a/fs/cifs/cifs_unicode.h
> > +++ b/fs/cifs/cifs_unicode.h
> > @@ -334,7 +334,7 @@ UniStrupr(register wchar_t *upin)
> >  
> >  	up = upin;
> >  	while (*up) {		/* For all characters */
> > -		*up = UniToupper(*up);
> > +		*up = cpu_to_le16(UniToupper(le16_to_cpu(*up)));
> >  		up++;
> >  	}
> >  	return upin;		/* Return input pointer */

Actually...there is one more change I'd suggest. With this, we now
expect an array of le16 values, and not an array of wchar_t's. The
arguments to this function and the "up" variable should probably be
changed accordingly.

Some comments clarifying that (maybe even a kerneldoc header?) might be
good too.

> > diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
> > index 71436d1..8b34a73 100644
> > --- a/fs/cifs/cifsencrypt.c
> > +++ b/fs/cifs/cifsencrypt.c
> > @@ -439,7 +439,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
> >  		return rc;
> >  	}
> >  
> > -	/* convert ses->user_name to unicode and uppercase */
> > +	/* convert ses->user_name to unicode */
> >  	len = ses->user_name ? strlen(ses->user_name) : 0;
> >  	user = kmalloc(2 + (len * 2), GFP_KERNEL);
> >  	if (user == NULL) {
> 
> Looks correct. Nice work tracking that down!
>
Steve French June 25, 2013, 6:08 p.m. UTC | #3
Good idea - but we need to fix the endian warning that you introduce
fixing the endian problem

  CHECK   /home/smfrench/cifs-2.6/fs/cifs/cifsencrypt.c
/home/smfrench/cifs-2.6/fs/cifs/cifs_unicode.h:337:23: warning: cast
to restricted __le16
/home/smfrench/cifs-2.6/fs/cifs/cifs_unicode.h:337:21: warning:
incorrect type in assignment (different base types)
/home/smfrench/cifs-2.6/fs/cifs/cifs_unicode.h:337:21:    expected
unsigned short [unsigned] [short] [usertype] <noident>
/home/smfrench/cifs-2.6/fs/cifs/cifs_unicode.h:337:21:    got
restricted __le16 [usertype] <noident>


On Tue, Jun 25, 2013 at 10:44 AM,  <shirishpargaonkar@gmail.com> wrote:
> From: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
>
>
> This is RH bug 970891
> Uppercasing of username during calculation of ntlmv2 hash fails
> because UniStrupr function does not handle big endian wchars.
>
> Also fix a comment in the same code to reflect its correct usage.
>
>
> Reported-by: steve <sanpatr1@in.ibm.com>
> Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
> Cc: <stable@kernel.org>
> ---
>  fs/cifs/cifs_unicode.h |    2 +-
>  fs/cifs/cifsencrypt.c  |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
> index 4fb0974..bec1137 100644
> --- a/fs/cifs/cifs_unicode.h
> +++ b/fs/cifs/cifs_unicode.h
> @@ -334,7 +334,7 @@ UniStrupr(register wchar_t *upin)
>
>         up = upin;
>         while (*up) {           /* For all characters */
> -               *up = UniToupper(*up);
> +               *up = cpu_to_le16(UniToupper(le16_to_cpu(*up)));
>                 up++;
>         }
>         return upin;            /* Return input pointer */
> diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
> index 71436d1..8b34a73 100644
> --- a/fs/cifs/cifsencrypt.c
> +++ b/fs/cifs/cifsencrypt.c
> @@ -439,7 +439,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
>                 return rc;
>         }
>
> -       /* convert ses->user_name to unicode and uppercase */
> +       /* convert ses->user_name to unicode */
>         len = ses->user_name ? strlen(ses->user_name) : 0;
>         user = kmalloc(2 + (len * 2), GFP_KERNEL);
>         if (user == NULL) {
> --
> 1.6.0.2
>
diff mbox

Patch

diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
index 4fb0974..bec1137 100644
--- a/fs/cifs/cifs_unicode.h
+++ b/fs/cifs/cifs_unicode.h
@@ -334,7 +334,7 @@  UniStrupr(register wchar_t *upin)
 
 	up = upin;
 	while (*up) {		/* For all characters */
-		*up = UniToupper(*up);
+		*up = cpu_to_le16(UniToupper(le16_to_cpu(*up)));
 		up++;
 	}
 	return upin;		/* Return input pointer */
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 71436d1..8b34a73 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -439,7 +439,7 @@  static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
 		return rc;
 	}
 
-	/* convert ses->user_name to unicode and uppercase */
+	/* convert ses->user_name to unicode */
 	len = ses->user_name ? strlen(ses->user_name) : 0;
 	user = kmalloc(2 + (len * 2), GFP_KERNEL);
 	if (user == NULL) {