Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2689479imm; Sun, 3 Jun 2018 09:16:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKc8bWQiZpBw0EPCx0X6XN553IK8iWqU3fmE7wnkrVEXEvljW3a1LDwpvb2rOdDW43FNy9I X-Received: by 2002:a17:902:b189:: with SMTP id s9-v6mr18722608plr.352.1528042565909; Sun, 03 Jun 2018 09:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528042565; cv=none; d=google.com; s=arc-20160816; b=CvnDlZGlzhdi6pbJK2N1TEm5ipfdvQv5SyFyqsj5QnVDbmsweRs9Yt/ja5Knz/ndMh tI5unXgU583IJFvbKXdaJhcNn1GQ00vZcNeLYkgAceULpn+HpJ9jZQzB54VbeJMfD2Qa kxleSYYpJhH8rFdVEG/HhVdIWstE3GKxDbsgp1JxGQRCg0bdyy2XTstoQKHCn9MaFMQp 3ZDQXsooj8EjL0aYzt1esuMPQv0I33Em/OV/Eyk396jOII+SN+rldl8f7HMFPk7Q72Le 9o3qv+x/ljxe2nPF27yYC6s56ZBfNT+3I64xsc2BiMX/06Zrim+N7++aDVirbsN/2K+g Vkfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=bnRsUy5oXSqNlsXd9tMyuaEPmUp6QCsOL7n0tb48k0I=; b=qY1Yb549Haqk9gytZGh5z7+iTpk/6rXKtohumbBY+WphB4PKUvHTHgnVRT/vQ21Wgw dsVGhAGzLKhjBiXDPbmaBUKdjcPZYKxgvfVER6yh5QWmEE2L9hJk9+Zcp0JQXvqYJcBc 1KuWdmdqp2gdmQzMzTNVJJdxINubByyW+KVZZyA6WO+Z+uiOrg7ExiqyOgPc4XtkUyqR wILtdHAJTkd8RcZhIJzBav3PH3y43ftvWL7GzihBpJ0SmjJu1/BvRVKlAXyxAMJ0hrPl WZQrLgE7vqwR+nqLIEFLaVCVrOpfo6Ib7Bkp7p3IWVZT7qCWMebwtFHy6Ne+FCi5sKtY ukAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hSC/BoAG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5-v6si45007134plo.166.2018.06.03.09.15.49; Sun, 03 Jun 2018 09:16:05 -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=@gmail.com header.s=20161025 header.b=hSC/BoAG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751210AbeFCQPX (ORCPT + 99 others); Sun, 3 Jun 2018 12:15:23 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:40146 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789AbeFCQPW (ORCPT ); Sun, 3 Jun 2018 12:15:22 -0400 Received: by mail-lf0-f68.google.com with SMTP id q11-v6so21533123lfc.7 for ; Sun, 03 Jun 2018 09:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=bnRsUy5oXSqNlsXd9tMyuaEPmUp6QCsOL7n0tb48k0I=; b=hSC/BoAGWmLMws1o1jEtWiVqaQPUgIbUvTGco0WJYDY3fXiTieHoqiTeQhElrEcUDn lP9aAQW3vK7x7fF1LRl/seMDlQqpsRFWTEbf6/qwY/ksP9IWfFHJlgrRA2+anyTKuPaO 8CX2b3RL3aq0gGCQyZ+zZqviCTUdufzW4g5McSb3/uOr4Uzowg5QZnuc7xZ/iZV6ZfTY 9LNy2ezrcB45xgw2FQun5wBe/rrOTmMyOAXW9BVRJW7Ri1u7+trIdS1kGlFDnRpE/OAx zHQDwiqARgtk//SgywnfnGsWfgGfjk1DnwS/t3UxDvtJUjEy2KASc/3m5kPtKRKWyJY0 iLZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bnRsUy5oXSqNlsXd9tMyuaEPmUp6QCsOL7n0tb48k0I=; b=RVca0iL4hEdAcDelFr5Rsf/JweVyMG8hHurglYVrrHn6oCR4Uwbs4dsqFLL63tJepI vqWKzK3nwXGHRMq9Gv/qxExzAJrQNpsrYIEQp9TTbe2YSiUi/tS1xEhbZ9AkKRO5UcfL QzzlS7yw2dmB2yuyvzVMSpFI+2DvPj2WHYM0PVEvFdlLdFyCgfRk9yTk48pQsqSIjL5t ysjj0r8u2c9bHCqsG/dVIEaMzkPiMMcdmsFHQgmZ+xwc2ELO0aaiehvV1sc1myz2pqCn adL5+ZntIY81NNt48u5R32eELAmxXVhtf3O9VY8l1Si9A8sUNKtn7HlnhBynCT7Ecaml AU8Q== X-Gm-Message-State: APt69E2EaYrC6VnYLKI2b9MlJeXe5yL58zsLSfEVgNoMkbLbejGKxIYP SMq1abHhWYECY9XYyrPzDOo/+xNi X-Received: by 2002:a19:e619:: with SMTP id d25-v6mr3327722lfh.68.1528042520417; Sun, 03 Jun 2018 09:15:20 -0700 (PDT) Received: from [192.168.0.160] (ppp89-110-17-188.pppoe.avangarddsl.ru. [89.110.17.188]) by smtp.gmail.com with ESMTPSA id h2-v6sm9359789ljk.60.2018.06.03.09.15.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jun 2018 09:15:19 -0700 (PDT) Subject: Re: [PATCH] staging:r8188eu: Use lib80211 to encrypt (WEP) tx frames To: Dan Carpenter Cc: Greg Kroah-Hartman , devel@driverdev.osuosl.org, Santha Meena Ramamoorthy , Janani Sankara Babu , linux-kernel@vger.kernel.org References: <20180528061821.26948-1-insafonov@gmail.com> <20180528135351.5y66u4puldawfic5@mwanda> From: Ivan Safonov Message-ID: <3e3851f2-7b51-3ab3-5663-ce7147ef8114@gmail.com> Date: Sun, 3 Jun 2018 19:16:19 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180528135351.5y66u4puldawfic5@mwanda> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) { ... } } > > Flip the if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) { > tests so it's: > > if (pattrib->encrypt != _WEP40_ && pattrib->encrypt != _WEP104_) > return; The check is superfluous inside this function, it should be (somewhen) around rtw_wep_encrypt(). > > The use normal error handling style: > > kfree_skb(skb); > return; > > err_free_skb: > kfree_skb(skb); > err_deinit: > crypto_ops->deinit(crypto_private); > } > 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. > regards, > dan carpenter > Ivan Safonov.