From patchwork Wed Feb 16 15:50:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 567681 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1GFmRBF028087 for ; Wed, 16 Feb 2011 15:49:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751208Ab1BPPtm (ORCPT ); Wed, 16 Feb 2011 10:49:42 -0500 Received: from mail-qw0-f46.google.com ([209.85.216.46]:62256 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095Ab1BPPtl (ORCPT ); Wed, 16 Feb 2011 10:49:41 -0500 Received: by qwa26 with SMTP id 26so1424138qwa.19 for ; Wed, 16 Feb 2011 07:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=suv8DrWqhn1LCiHZ7wMrPHdKpwdDX1VYsK09EJLaz2c=; b=iXRLsIPYvMOvLscfDBBu0J27mcK4DmMGxRFMrRhHvqytJwaTe/mIuFnM4rtrhrPTRs 36e1wzxOeQ/BlQTAgMZJw9nGwtwrntM5JvyNexaSXX4l38Ung+DJOtKnmFK3pdzZoZzD aPd+9TlLu9NxSZtvvAekAVae6WQeCGaYXsOgA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=OUpsg3QcFKGnMKCz94E6TGNyYrDOQZyrp1PEA4i5cXdQMTE3wFCzVCKYMpNEyOfetj uHPFpELHIm2C1LdCuG7AOrum5tm7y9BSo5INMDfRLrW3KvjxXFApAtVtskvsfzyLoBvu 9MZbqZtWXcrJNPcp/MrwzOHTnDO91eDRc63Yo= Received: by 10.229.222.194 with SMTP id ih2mr851805qcb.197.1297871380135; Wed, 16 Feb 2011 07:49:40 -0800 (PST) Received: from localhost ([32.97.110.58]) by mx.google.com with ESMTPS id nb15sm197005qcb.38.2011.02.16.07.49.39 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 16 Feb 2011 07:49:39 -0800 (PST) From: shirishpargaonkar@gmail.com To: smfrench@gmail.com Cc: linux-cifs@vger.kernel.org, Shirish Pargaonkar Subject: [PATCH] cifs: fix broken lanman (lm) auth code (try #2) Date: Wed, 16 Feb 2011 09:50:14 -0600 Message-Id: <1297871414-11560-1-git-send-email-shirishpargaonkar@gmail.com> X-Mailer: git-send-email 1.6.0.2 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 16 Feb 2011 15:49:42 +0000 (UTC) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 8d6c17a..e3494df 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1014,6 +1014,9 @@ cifs_parse_mount_options(char *options, const char *devname, /* BB is there a better way to do this? */ vol->secFlg |= CIFSSEC_MAY_NTLMV2; #ifdef CONFIG_CIFS_WEAK_PW_HASH + } else if (strnicmp(value, "lanmani", 7) == 0) { + vol->secFlg |= CIFSSEC_MAY_LANMAN | + CIFSSEC_MUST_SIGN; } else if (strnicmp(value, "lanman", 6) == 0) { vol->secFlg |= CIFSSEC_MAY_LANMAN; #endif 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..7bdf42c 100644 --- a/fs/cifs/smbdes.c +++ b/fs/cifs/smbdes.c @@ -299,6 +299,20 @@ dohash(char *out, char *in, char *key, int forw) kfree(ki); } +static int +odd_parity(unsigned char c) +{ + int i; + int val = 0x80; + int count = 0; + + for (i = 0; i < 7; ++i) + if (c & (val >> i)) + ++count; + + return count % 2; +} + static void str_to_key(unsigned char *str, unsigned char *key) { @@ -312,8 +326,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 (!odd_parity(key[i])) + key[i] |= 0x1; /* add odd parity bit */ + } } static void