Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Shirish Pargaonkar
	<shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] cifs: Fix broken lanman (lm) auth code (try #4)
Date: Thu, 17 Feb 2011 07:59:22 -0500	[thread overview]
Message-ID: <20110217075922.75bbd03b@barsoom.rdu.redhat.com> (raw)
In-Reply-To: <AANLkTi=a8Wb6jwvJExFmMn3ADeXPq2J9AAJYBfuQ=hhZ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Thu, 17 Feb 2011 00:59:44 -0600
Shirish Pargaonkar <shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> On Wed, Feb 16, 2011 at 7:52 PM, Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
> > On Wed, 16 Feb 2011 18:05:28 -0600
> > shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
> >
> >> From: Shirish Pargaonkar <shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >>
> >>
> >> Fix lanman (lm) authentication code.
> >>
> >> Change lm response length back to 24 from 16.
> >> Add code to add odd parity bit to each of the eight bytes of a DES key.
> >>
> >>
> >> Signed-off-by: Shirish Pargaonkar <shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >> ---
> >>  fs/cifs/sess.c   |    8 ++++----
> >>  fs/cifs/smbdes.c |    5 ++++-
> >>  2 files changed, 8 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
> >> index 1adc962..1676570 100644
> >> --- a/fs/cifs/sess.c
> >> +++ b/fs/cifs/sess.c
> >> @@ -656,13 +656,13 @@ ssetup_ntlmssp_authenticate:
> >>
> >>       if (type == LANMAN) {
> >>  #ifdef CONFIG_CIFS_WEAK_PW_HASH
> >> -             char lnm_session_key[CIFS_SESS_KEY_SIZE];
> >> +             char lnm_session_key[CIFS_AUTH_RESP_SIZE];
> >>
> >>               pSMB->req.hdr.Flags2 &= ~SMBFLG2_UNICODE;
> >>
> >>               /* no capabilities flags in old lanman negotiation */
> >>
> >> -             pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_SESS_KEY_SIZE);
> >> +             pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_AUTH_RESP_SIZE);
> >>
> >>               /* Calculate hash with password and copy into bcc_ptr.
> >>                * Encryption Key (stored as in cryptkey) gets used if the
> >> @@ -675,8 +675,8 @@ ssetup_ntlmssp_authenticate:
> >>                                       true : false, lnm_session_key);
> >>
> >>               ses->flags |= CIFS_SES_LANMAN;
> >> -             memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_SESS_KEY_SIZE);
> >> -             bcc_ptr += CIFS_SESS_KEY_SIZE;
> >> +             memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_AUTH_RESP_SIZE);
> >> +             bcc_ptr += CIFS_AUTH_RESP_SIZE;
> >>
> >>               /* can not sign if LANMAN negotiated so no need
> >>               to calculate signing key? but what if server
> >> diff --git a/fs/cifs/smbdes.c b/fs/cifs/smbdes.c
> >> index 0472148..0ab5def 100644
> >> --- a/fs/cifs/smbdes.c
> >> +++ b/fs/cifs/smbdes.c
> >> @@ -312,8 +312,11 @@ str_to_key(unsigned char *str, unsigned char *key)
> >>       key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
> >>       key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
> >>       key[7] = str[6] & 0x7F;
> >> -     for (i = 0; i < 8; i++)
> >> +     for (i = 0; i < 8; i++) {
> >>               key[i] = (key[i] << 1);
> >> +             if (~(hweight8(key[i]) & 1))
> >> +                     key[i] |= 0x1; /* add odd parity bit */
> >> +     }
> >
> > This doesn't look right:
> >
> > hweight8 will return an unsigned int. You & that with 1, so you'll
> > either get 0x1 (for odd number of bits) or 0x0 (for even). Then take
> > the one's compliment of that and you'll either have 0xfffffffe (odd) or
> > 0xffffffff (even), both of which will return true.
> >
> > I think you'll need to do this differently -- perhaps something like
> > this which also has the advantage of avoiding the if statement:
> >
> >        /* set the odd parity bit */
> >        key[i] |= (~(hweight8(key[i]) & 1)) & 1;
> 
> This should work
>           key[i] |= !(hweight8(key[i]) % 2);

That should work if the ! always turns 0x0 into 0x1. How certain of that
are you?

-- 
Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

  parent reply	other threads:[~2011-02-17 12:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-17  0:05 [PATCH] cifs: Fix broken lanman (lm) auth code (try #4) shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w
     [not found] ` <1297901128-23418-1-git-send-email-shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-02-17  1:52   ` Jeff Layton
     [not found]     ` <20110216205215.40c6b7c3-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2011-02-17  2:41       ` Shirish Pargaonkar
2011-02-17  5:23       ` Shirish Pargaonkar
2011-02-17  6:59       ` Shirish Pargaonkar
     [not found]         ` <AANLkTi=a8Wb6jwvJExFmMn3ADeXPq2J9AAJYBfuQ=hhZ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-17 12:59           ` Jeff Layton [this message]
     [not found]             ` <20110217075922.75bbd03b-xSBYVWDuneFaJnirhKH9O4GKTjYczspe@public.gmane.org>
2011-02-17 13:54               ` Shirish Pargaonkar
     [not found]                 ` <AANLkTik_qVr07D5jQP-7a5Q=-d8rZ1c5he4ZY5-C69PB-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-17 14:43                   ` Jeff Layton
     [not found]                     ` <20110217094314.6dd1cb7a-xSBYVWDuneFaJnirhKH9O4GKTjYczspe@public.gmane.org>
2011-02-17 17:07                       ` Shirish Pargaonkar

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=20110217075922.75bbd03b@barsoom.rdu.redhat.com \
    --to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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