Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2371677imm; Mon, 28 May 2018 06:56:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoTP9fA04XXgTEpdLvG63HT6hPalbP0A01QxQUsZ7499CzhYI/eVBHcXzxe+T2WyHDa+7ae X-Received: by 2002:a65:4549:: with SMTP id x9-v6mr10783804pgr.158.1527515783890; Mon, 28 May 2018 06:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527515783; cv=none; d=google.com; s=arc-20160816; b=NzMNbJbN1w4NQ+VtD9Us+A1PDuwV2xkC3kign6JEPt0dwnej1wc0wCJUmJ4vMnuRla b+dOWdR6TwFJzvZN4d/2I8rNQkN36ATofS1X8jx9uQrIPJz/KXrOkMKL4mJHu19+u+CN UtQjbCGfagh7Us3axewzaCFXTKy+JUDccHW+w3w6ebyl4FwRAScxwaJDzkubWdy+yUna AoKy9Uhc/bOQz93uxoASGEIfNGRglVcChvaD/DzhEHBnEWvv1Igg7hklPiBtn03Lsc4a hK8mQVe/efbUXFUD8ujGKtdkV7ebp3Mn7PVixqaIU7FtK1df9gmVUd2KN0srPiEAoIRF bR3A== 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=FNjmqS7dugFj13NLH/sF/Ds3zmQT3xlBdaLiD+CRZNs=; b=vnqLTtyfGIeAbEOF0RFeq6egRyfpaBLzmGmyLUsVVD9O9buMK7nAEtU8zPqLoNm8mU tnb6aERKW5nXBbZWBNNzz2nxYjICshHvpG00SFD/Q7LD+7VvPSuwpqI4pGTuWtBtzoX2 MRHYGID4vcjvU/D7hrbx9CWKCeywGg3oZSE0G6DkoXknaWKPxR5kGWi7GVqJhc0c7s2g eR5d1wOv8yI0gFfADifLCLVqR3qjPvvvxSj3EsWomvGLrP2fcaFZNRz/4s6hS93tb377 sMqKbf3OC8u9kzijTRfSTuWRMNsbOEbT+Jd68cUcImQyDaJKyOo8j3Lpf4lvCk75rOkY +eDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=P6FVVk77; 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 v5-v6si6596518pgq.32.2018.05.28.06.56.08; Mon, 28 May 2018 06:56:23 -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=P6FVVk77; 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 S1754639AbeE1Nyb (ORCPT + 99 others); Mon, 28 May 2018 09:54:31 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:51822 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939261AbeE1NyK (ORCPT ); Mon, 28 May 2018 09:54:10 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4SDonvN023166; Mon, 28 May 2018 13:54:06 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=FNjmqS7dugFj13NLH/sF/Ds3zmQT3xlBdaLiD+CRZNs=; b=P6FVVk77fTZkxEiNmnFKAYOXxhmL/FajhnZm8dIqDyMA9CVuc0R2xzqPzYUifDGMP99t fsG0zNHoDGv9A7oO5x6PDicJD3f12kugbBAG9Wgow18cQs3fRHyv3ld4RRSqE9fyXtdy G/BOUZkyk52/iTFcRXrps7eSqzANlldTCwxR+jlA4lfSBAuSLKrgZnZiy7itiuOH5VYw hNMIKrCWms7ZrwfM/c9xzLtcfZln50td9l6IrsEjE9ejfVudcsJRPle/+1dWcHH+aXuR VIU6Kr+GyrX6BnrjZmgp0PzV7V0hGSvGHixzED2uCjRNWIJuDXkn+b1EB34yeOzrzOUv gA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2j6yjbderg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 May 2018 13:54:06 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4SDs5VO024008 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 May 2018 13:54:05 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4SDs4HN023265; Mon, 28 May 2018 13:54:04 GMT Received: from mwanda (/41.202.241.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 May 2018 06:54:04 -0700 Date: Mon, 28 May 2018 16:53:51 +0300 From: Dan Carpenter To: Ivan Safonov Cc: Greg Kroah-Hartman , devel@driverdev.osuosl.org, Santha Meena Ramamoorthy , Janani Sankara Babu , linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging:r8188eu: Use lib80211 to encrypt (WEP) tx frames Message-ID: <20180528135351.5y66u4puldawfic5@mwanda> References: <20180528061821.26948-1-insafonov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180528061821.26948-1-insafonov@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8906 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 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-1711220000 definitions=main-1805280168 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... Flip the if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { tests so it's: if (pattrib->encrypt != _WEP40_ && pattrib->encrypt != _WEP104_) return; The use normal error handling style: kfree_skb(skb); return; err_free_skb: kfree_skb(skb); err_deinit: crypto_ops->deinit(crypto_private); } regards, dan carpenter