Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp749949ybp; Wed, 9 Oct 2019 03:44:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJZJ51vZH+YeExHCHWqSrNajWw8Xi2aWRXkfPriFJh/9HtSBb0mpV1kt4K1Bku7wfLwWnn X-Received: by 2002:a17:906:55d1:: with SMTP id z17mr2114917ejp.300.1570617853137; Wed, 09 Oct 2019 03:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570617853; cv=none; d=google.com; s=arc-20160816; b=ZXDWZ6+i4NuqrYAbktWQs9QIF9fHUKBt3GqGGjStIbIUZZQxmPG/V+1ehgDKPR2Sfy IA/iI8z+c9cVOb/8uyu8VwIy8asLRKNllv2oXGj9rDFBkzoJVOxWg/xf/8/UHuYiQBTm BT8eQXQmnHLf1DwdTTDyqw6XkSaWVJp877a9LTcY5oc9SV6m4/Zdpp1jaqPmtkkS/Ts8 NMwmupgZ5XVxZQoX9m1tKW3vQpAp6UkfGXTwO6V/cEvxnHp5QWlOx2c3jWk0xAPOvSCn OnxakJihMqwaqA6TCxHo1R3EldwZRKGob6QpfBugmwNLck2HVzdOK7weq3bpLm9UXKlc FcLQ== 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:subject:autocrypt:from:references:cc:to; bh=ZH/t6Z5SKm0O+GF3c+jnCpiA2fHZKai+CXFJKmI0anE=; b=maZ61k6t3SSGW0BwNrm/b+ldSYgun0vXXYWeeED1FkUXt4H9rFqpPl+DtL/fTdTD+o GLnATafvVwFjH5yWBsftd5HBjEEKVXZYOeNA23DTjhtnj/HKKsvOpFFWAc9Jh2JOqqe2 /gdGV9db8DPTFpwKUaBQEKkMGLwVzWaM8jpcy3jA3PyHkPF0ExZAZVvxYoRHOenzz9f9 5ZoHv8Pp+SL1ttIQBNL6qlA5fVRABzSHJMXotf3OLeV1KlWvTdfIJkd5bYFOeaQAkEH+ 2I43fZj+GcQvjiCG1aJyL/V0037mbPTeq0BL9ZAUX6/jH77QGEDIzoG8Uh1L8wSKaTFp rIMw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g20si1246428edb.149.2019.10.09.03.43.49; Wed, 09 Oct 2019 03:44:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730835AbfJIKnP (ORCPT + 99 others); Wed, 9 Oct 2019 06:43:15 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:41163 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727035AbfJIKnP (ORCPT ); Wed, 9 Oct 2019 06:43:15 -0400 Received: by mail-ed1-f66.google.com with SMTP id f20so1555295edv.8; Wed, 09 Oct 2019 03:43:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=ZH/t6Z5SKm0O+GF3c+jnCpiA2fHZKai+CXFJKmI0anE=; b=foNGsBUMMxcNRAm4b8gjo6ARjAE3C0mTF2iEdJzjkqR4UW0tgVi6q8qf/gcmA0pDOn FMIY52VVAYRu7/DGTAfcWsMWfpUuJZd+H7bwNqpyQ/CeywlWBSLr6t7tZNMLFXgG/yDH 3WvNtKKn4Q/Iu95GBClEeYzQn6CFzIqKj9THxTy6wh44cwvvaUIWfvIZFQfSDfc7UPo8 DH/aAJLTkMszWDrOevk9XZ/gN7GrBZu2/LxdINyTFw1AUBvCN0rajzx5M50z2p+2sfNp F+A7piHckxLqpa4ejujZ6Yw4+MVAeUjnkKJkDvV3jh6NRaztAwkixlU19DiPnWA2xVWd KE1A== X-Gm-Message-State: APjAAAXMJkuybu6APl8L1x/rA4xc+1g4XydsN+W2iaDTWsWKqEmVtGvo Knj1bIxWvQSOjuUbb5WU6spuhTtZEwc= X-Received: by 2002:a17:906:4748:: with SMTP id j8mr2143495ejs.210.1570617792769; Wed, 09 Oct 2019 03:43:12 -0700 (PDT) Received: from [172.16.14.133] ([62.28.178.14]) by smtp.gmail.com with ESMTPSA id t9sm202921eji.26.2019.10.09.03.43.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Oct 2019 03:43:11 -0700 (PDT) To: Hans de Goede , devel@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Bastien Nocera , Larry Finger , Jes Sorensen , stable@vger.kernel.org References: <20190930110141.29271-1-efremov@linux.com> <94af475e-dd7a-6066-146a-30a9915cd325@redhat.com> From: Denis Efremov Autocrypt: addr=efremov@linux.com; keydata= mQINBFsJUXwBEADDnzbOGE/X5ZdHqpK/kNmR7AY39b/rR+2Wm/VbQHV+jpGk8ZL07iOWnVe1 ZInSp3Ze+scB4ZK+y48z0YDvKUU3L85Nb31UASB2bgWIV+8tmW4kV8a2PosqIc4wp4/Qa2A/ Ip6q+bWurxOOjyJkfzt51p6Th4FTUsuoxINKRMjHrs/0y5oEc7Wt/1qk2ljmnSocg3fMxo8+ y6IxmXt5tYvt+FfBqx/1XwXuOSd0WOku+/jscYmBPwyrLdk/pMSnnld6a2Fp1zxWIKz+4VJm QEIlCTe5SO3h5sozpXeWS916VwwCuf8o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otgLV95yL0dPyZxvOPPnbjF0cCtHfdKhXIt7Syzjb M8k2fmSF0FM+89/hP11aRrs6+qMHSd/s3N3j0hR2Uxsski8q6x+LxU1aHS0FFkSl0m8SiazA Gd1zy4pXC2HhCHstF24Nu5iVLPRwlxFS/+o3nB1ZWTwu8I6s2ZF5TAgBfEONV5MIYH3fOb5+ r/HYPye7puSmQ2LCXy7X5IIsnAoxSrcFYq9nGfHNcXhm5x6WjYC0Kz8l4lfwWo8PIpZ8x57v gTH1PI5R4WdRQijLxLCW/AaiuoEYuOLAoW481XtZb0GRRe+Tm9z/fCbkEveyPiDK7oZahBM7 QdWEEV8mqJoOZ3xxqMlJrxKM9SDF+auB4zWGz5jGzCDAx/0qMUrVn2+v8i4oEKW6IUdV7axW Nk9a+EF5JSTbfv0JBYeSHK3WRklSYLdsMRhaCKhSbwo8Xgn/m6a92fKd3NnObvRe76iIEMSw 60iagNE6AFFzuF/GvoIHb2oDUIX4z+/D0TBWH9ADNptmuE+LZnlPUAAEzRgUFtlN5LtJP8ph Subject: Re: [PATCH] staging: rtl8723bs: hal: Fix memcpy calls Message-ID: <996e0e51-019a-5d65-026a-9599f9228299@linux.com> Date: Wed, 9 Oct 2019 13:43:09 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <94af475e-dd7a-6066-146a-30a9915cd325@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 09.10.2019 12:35, Hans de Goede wrote: > Hi Denis, > > On 30-09-2019 13:01, Denis Efremov wrote: >> memcpy() in phy_ConfigBBWithParaFile() and PHY_ConfigRFWithParaFile() is >> called with "src == NULL && len == 0". This is an undefined behavior. >> Moreover this if pre-condition "pBufLen && (*pBufLen == 0) && !pBuf" >> is constantly false because it is a nested if in the else brach, i.e., >> "if (cond) { ... } else { if (cond) {...} }". This patch alters the >> if condition to check "pBufLen && pBuf" pointers are not NULL. >> >> Cc: Greg Kroah-Hartman >> Cc: Hans de Goede >> Cc: Bastien Nocera >> Cc: Larry Finger >> Cc: Jes Sorensen >> Cc: stable@vger.kernel.org >> Signed-off-by: Denis Efremov >> --- >> Not tested. I don't have the hardware. The fix is based on my guess. > > Thsnk you for your patch. > > So I've been doing some digging and this code normally never executes. > > For this to execute the user would need to change the rtw_load_phy_file module > param from its default of 0x44 (LOAD_BB_PG_PARA_FILE | LOAD_RF_TXPWR_LMT_PARA_FILE) > to something which includes 0x02 (LOAD_BB_PARA_FILE) as mask. > > And even with that param set for this code to actually do something / > for pBuf to ever not be NULL the following conditions would have to > be true: > > 1) Set the rtw_load_phy_file module param from its default of >    0x44 (LOAD_BB_PG_PARA_FILE | LOAD_RF_TXPWR_LMT_PARA_FILE) to something >    which includes 0x02 as mask; and > 2) Set rtw_phy_file_path module parameter to say "/lib/firmware/"; and > 3) Store a /lib/firmware/rtl8723b/PHY_REG.txt file in the expected format. > > So I've come to the conclusion that all the phy_Config*WithParaFile functions > (and a bunch of stuff they use) can be removed. > > I will prepare and submit a patch for this. > Thank you for perfect investigation! I can only agree with you, because this code is buggy. It looks like no one faced this bug previously and the code can be safely removed. Best Regards, Denis > >> >>   drivers/staging/rtl8723bs/hal/hal_com_phycfg.c | 4 ++-- >>   1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c >> index 6539bee9b5ba..0902dc3c1825 100644 >> --- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c >> +++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c >> @@ -2320,7 +2320,7 @@ int phy_ConfigBBWithParaFile( >>               } >>           } >>       } else { >> -        if (pBufLen && (*pBufLen == 0) && !pBuf) { >> +        if (pBufLen && pBuf) { >>               memcpy(pHalData->para_file_buf, pBuf, *pBufLen); >>               rtStatus = _SUCCESS; >>           } else >> @@ -2752,7 +2752,7 @@ int PHY_ConfigRFWithParaFile( >>               } >>           } >>       } else { >> -        if (pBufLen && (*pBufLen == 0) && !pBuf) { >> +        if (pBufLen && pBuf) { >>               memcpy(pHalData->para_file_buf, pBuf, *pBufLen); >>               rtStatus = _SUCCESS; >>           } else >> >