Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3363084imm; Mon, 4 Jun 2018 02:13:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLs3z1tBDM5yMBo9xvPoeFpO2v90mD7Bt2K7MCFuJlKPZSRakpgi37bjycWd0NT/SRu2b4n X-Received: by 2002:a17:902:7484:: with SMTP id h4-v6mr20541049pll.154.1528103611624; Mon, 04 Jun 2018 02:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528103611; cv=none; d=google.com; s=arc-20160816; b=jfhj2TV8ebktevOaxKWD8I5NIxGTzlIENs6y+jOhDDK9xnuy+v6jp4Ni9sUkRqbIrL Sob3/eotC9XKYMGqWgbnM8aqgrekKCWl4uJJEFVZdR1b/iJ2DSx5Gz8NBbX7E3iJdkev uaz6+pwGHHYq73uRjfSgTOyCBa5c8jLJGseX9WL8WmOjrUfHMa5HYA9ftpI9OQAXgzXW LCKieTW92EQZIJdj4b1t4wtx/Y1xpBt+JV6aC+SwEhTzFUjH6PorelIXGnehzXwgw8qB kx2p16Du1rLjsXxAD9upWEBF0e+wbh6Fusx9wwgS+FSoctilkyXGTpU7rnoL4oCLW3qW VPcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=izcSm/Ri2lI3iUzlFVaqgmN+QQM7+HCWB3MXSpXZR2I=; b=hHgJpHknO9E68kn5b21gIGZzJmls4D29GvqrWkIeh8OdpeSPxTpLAtixuAoqjBIueo azpTORfFsU87/o+wbW8WYSBBvD45OKrsHmGbFBnonVtkWtPE92GzqhHKB8VAto0PSc2D UFPYQDJ1ud5mYjYQgp8DzwdkD6eMhI5S8LGMISJPB95zl3pvPm9XJTJ9+xmRmuyBPkPY pVLAubWnjnYkva+biy2qhyckEr8L1eZsceumynIlfEd/h+qHYlS2CPaIvpGkMoxnxUWO KCZjZFSkZArKtUzk5+VieYwYmFSTbGj14TQ5Q/e8l86L6+BSS43GseHSJ3EUEjnu5wg7 NQWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=bqnuXwjx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1-v6si45700703plk.257.2018.06.04.02.13.16; Mon, 04 Jun 2018 02:13:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=bqnuXwjx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752310AbeFDJL5 (ORCPT + 99 others); Mon, 4 Jun 2018 05:11:57 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:57194 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752093AbeFDJLz (ORCPT ); Mon, 4 Jun 2018 05:11:55 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w549BRuB013025; Mon, 4 Jun 2018 09:11:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=izcSm/Ri2lI3iUzlFVaqgmN+QQM7+HCWB3MXSpXZR2I=; b=bqnuXwjx3g1VktNjgkzIh9rDe/zBGBp9led5HPZy2tAJcxGmT19nMQ0V211xehw2Xnpv U7jLsN79w3VRg3QcwCThj1MPAkX/nOlkEpD+J5iMtEt55xoviyTC0imYQOFug9Pm2Umw EnatGLjglltvNjrQGR+Bct6YrBL9RNV1PTwZpfddayy1Mx/GeXE3VJZpPINSgMM6VPbM LTnVcMqMsHJOmHGmvbIf71Ik0ZpS7ElbRYmmXdxRZGKL+LVb+HgPC4KQSI3vPrriHMwH DrynD1aV/UqEcRtvtj98/K0P9XU/FHtiHczb8/KO1kyfpkL6hkckMAaVWFmHe/tI+cgj Ew== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2jbvyntn1t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 04 Jun 2018 09:11:52 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w549BoiB001967 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 Jun 2018 09:11:51 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w549BoY2024953; Mon, 4 Jun 2018 09:11:50 GMT Received: from mwanda (/41.202.241.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 04 Jun 2018 02:11:49 -0700 Date: Mon, 4 Jun 2018 12:11:39 +0300 From: Dan Carpenter To: Ivan Safonov Cc: devel@driverdev.osuosl.org, Greg Kroah-Hartman , Janani Sankara Babu , linux-kernel@vger.kernel.org, Santha Meena Ramamoorthy Subject: Re: [PATCH] staging:r8188eu: Use lib80211 to encrypt (WEP) tx frames Message-ID: <20180604091139.zbe2kkoe3uaktanu@mwanda> References: <20180528061821.26948-1-insafonov@gmail.com> <20180528135351.5y66u4puldawfic5@mwanda> <3e3851f2-7b51-3ab3-5663-ce7147ef8114@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3e3851f2-7b51-3ab3-5663-ce7147ef8114@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8913 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806040114 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 03, 2018 at 07:16:19PM +0300, Ivan Safonov wrote: > On 05/28/2018 04:53 PM, Dan Carpenter wrote: > > On Mon, May 28, 2018 at 09:18:21AM +0300, Ivan Safonov wrote: > > > Put data to skb, decrypt with lib80211_crypt_wep, and place back to tx buffer. > > > > > > Signed-off-by: Ivan Safonov > > > --- > > > drivers/staging/rtl8188eu/core/rtw_security.c | 72 ++++++++++++++++----------- > > > 1 file changed, 43 insertions(+), 29 deletions(-) > > > > > > diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c > > > index bfe0b217e679..80d7569a3108 100644 > > > --- a/drivers/staging/rtl8188eu/core/rtw_security.c > > > +++ b/drivers/staging/rtl8188eu/core/rtw_security.c > > > @@ -139,17 +139,11 @@ static __le32 getcrc32(u8 *buf, int len) > > > Need to consider the fragment situation > > > */ > > > void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) > > > -{ /* exclude ICV */ > > > - > > > - unsigned char crc[4]; > > > - struct arc4context mycontext; > > > - > > > +{ > > > int curfragnum, length; > > > - u32 keylength; > > > - u8 *pframe, *payload, *iv; /* wepkey */ > > > - u8 wepkey[16]; > > > - u8 hw_hdr_offset = 0; > > > + u8 *pframe; > > > + u8 hw_hdr_offset = 0; > > > struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; > > > struct security_priv *psecuritypriv = &padapter->securitypriv; > > > struct xmit_priv *pxmitpriv = &padapter->xmitpriv; > > > @@ -165,33 +159,53 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) > > > /* start to encrypt each fragment */ > > > if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { > > > - keylength = psecuritypriv->dot11DefKeylen[psecuritypriv->dot11PrivacyKeyIndex]; > > > + const int keyindex = psecuritypriv->dot11PrivacyKeyIndex; > > > + void *crypto_private; > > > + struct sk_buff *skb; > > > + struct lib80211_crypto_ops *crypto_ops = try_then_request_module(lib80211_get_crypto_ops("WEP"), "lib80211_crypt_wep"); > > > + > > > + if (!crypto_ops) > > > + goto exit; > > > + > > > + crypto_private = crypto_ops->init(keyindex); > > > + if (!crypto_private) > > > + goto exit; > > > + > > > + if (crypto_ops->set_key(psecuritypriv->dot11DefKey[keyindex].skey, > > > + psecuritypriv->dot11DefKeylen[keyindex], NULL, crypto_private) < 0) > > > + goto exit; > > > for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { > > > - iv = pframe+pattrib->hdrlen; > > > - memcpy(&wepkey[0], iv, 3); > > > - memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[psecuritypriv->dot11PrivacyKeyIndex].skey[0], keylength); > > > - payload = pframe+pattrib->iv_len+pattrib->hdrlen; > > > + if (curfragnum + 1 == pattrib->nr_frags) > > > + length = pattrib->last_txcmdsz; > > > + else > > > + length = pxmitpriv->frag_len; > > > + skb = dev_alloc_skb(length); > > > + if (!skb) > > > + goto exit; > > > - if ((curfragnum+1) == pattrib->nr_frags) { /* the last fragment */ > > > - length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; > > > + skb_put_data(skb, pframe, length); > > > - *((__le32 *)crc) = getcrc32(payload, length); > > > + memmove(skb->data + 4, skb->data, pattrib->hdrlen); > > > + skb_pull(skb, 4); > > > + skb_trim(skb, skb->len - 4); > > > - arcfour_init(&mycontext, wepkey, 3+keylength); > > > - arcfour_encrypt(&mycontext, payload, payload, length); > > > - arcfour_encrypt(&mycontext, payload+length, crc, 4); > > > - } else { > > > - length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len; > > > - *((__le32 *)crc) = getcrc32(payload, length); > > > - arcfour_init(&mycontext, wepkey, 3+keylength); > > > - arcfour_encrypt(&mycontext, payload, payload, length); > > > - arcfour_encrypt(&mycontext, payload+length, crc, 4); > > > - > > > - pframe += pxmitpriv->frag_len; > > > - pframe = (u8 *)round_up((size_t)(pframe), 4); > > > + if (crypto_ops->encrypt_mpdu(skb, pattrib->hdrlen, crypto_private)) { > > > + kfree_skb(skb); > > > + goto exit; > > > } > > > + > > > + memcpy(pframe, skb->data, skb->len); > > > + > > > + pframe += skb->len; > > > + pframe = (u8 *)round_up((size_t)(pframe), 4); > > > + > > > + kfree_skb(skb); > > > } > > > + > > > +exit: > > > + if (crypto_ops && crypto_private) > > > + crypto_ops->deinit(crypto_private); > > > > One label style error handling is always bugggy. I'm surprised GCC > > doesn't catch that crypto_private can be uninitialized... > > This is not a compiler defect. The code > > if (a && b) { > ... > } > > is equal to > > if (a) { > if (b) { > ... > } > } Heh... Oops. Sorry, I misread the code. That's embarrassing. > rtw_(wep|aes|tkip)_(en|de)crypt still need to be rewritten, so I'll leave > this patch as is. In the following patches I'll take your comments into > account, they really simplify reading the code. > Sounds good. regards, dan carpenter