lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f93d3ea32ac04a5edd8159abcb0504f71fe7aee4.camel@perches.com>
Date:   Sun, 31 Jul 2022 10:12:56 -0700
From:   Joe Perches <joe@...ches.com>
To:     Phillip Potter <phil@...lpotter.co.uk>,
        Dan Carpenter <dan.carpenter@...cle.com>
Cc:     gregkh@...uxfoundation.org, Larry.Finger@...inger.net,
        paskripkin@...il.com, martin@...ser.cx, straube.linux@...il.com,
        fmdefrancesco@...il.com, abdun.nihaal@...il.com,
        linux-staging@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] staging: r8188eu: convert rtw_set_802_11_add_wep
 error code semantics

On Sat, 2022-07-30 at 19:36 +0100, Phillip Potter wrote:
> On Fri, Jul 29, 2022 at 09:48:03AM +0300, Dan Carpenter wrote:
> > On Fri, Jul 29, 2022 at 12:11:50AM +0100, Phillip Potter wrote:
> > > -u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
> > > +int rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
> > >  {
> > >  	int		keyid, res;
> > >  	struct security_priv *psecuritypriv = &padapter->securitypriv;
> > > -	u8		ret = _SUCCESS;
> > > +	int		ret = 0;
> > >  
> > >  	keyid = wep->KeyIndex & 0x3fffffff;
> > >  
> > >  	if (keyid >= 4) {
> > > -		ret = false;
> > > +		ret = -EOPNOTSUPP;
> > >  		goto exit;
> > >  	}
> > >  
> > > @@ -424,7 +424,7 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
> > >  	res = rtw_set_key(padapter, psecuritypriv, keyid, 1);
> > >  
> > >  	if (res == _FAIL)
> > > -		ret = false;
> > > +		ret = -ENOMEM;
> > >  exit:
> > >  
> > >  	return ret;
> > 
> > No, this isn't right.  This now returns 1 on success and negative
> > error codes on error.
> > 
> > There are a couple anti-patterns here:
> > 
> > 1) Do nothing gotos
> > 2) Mixing error paths and success paths.
> > 
> > If you avoid mixing error paths and success paths then you get a pattern
> > called: "Solid return zero."  This is where the end of the function has
> > a very chunky "return 0;" to mark that it is successful.  You want that.
> > Some people do a "if (ret == 0) return ret;".  Nope.  "return ret;" is
> > not chunky.
> > 
> > regards,
> > dan carpenter
> > 
> 
> Hi Dan,
> 
> Thank you for the review firstly, much appreciated.
> 
> I'm happy of course to rewrite this to address any concerns, but
> I was hoping I could clarify what you've said though? Apologies if I've
> missed it, but how is this function now returning 1 on success? It sets
> ret to 0 (success) at the start and then sets it to one of two negative
> error codes depending on what happens. Am I missing something here?
> (Perfectly possible that I am).
> 
> In terms of do nothing gotos, do you mean gotos that just set an error
> code then jump to the end? If you'd prefer, as the function just returns
> right after the exit label, I can just return the codes directly and have
> a 'return 0;' like you say above?
> 
> Thanks as always for your insight.

Yes, you've got it right.

I think Dan is suggesting something like the below, but
not necessarily in a single patch:
---
 drivers/staging/r8188eu/core/rtw_ioctl_set.c | 38 ++++++++++++----------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_ioctl_set.c b/drivers/staging/r8188eu/core/rtw_ioctl_set.c
index 17f6bcbeebf42..2736bbce83b5b 100644
--- a/drivers/staging/r8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/r8188eu/core/rtw_ioctl_set.c
@@ -390,44 +390,38 @@ u8 rtw_set_802_11_authentication_mode(struct adapter *padapter, enum ndis_802_11
 	return ret;
 }
 
-u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
+int rtw_set_802_11_add_wep(struct adapter *padapter,
+			   struct ndis_802_11_wep *wep)
 {
-	int		keyid, res;
-	struct security_priv *psecuritypriv = &padapter->securitypriv;
-	u8		ret = _SUCCESS;
+	int keyid;
+	struct security_priv *secpriv = &padapter->securitypriv;
 
 	keyid = wep->KeyIndex & 0x3fffffff;
-
-	if (keyid >= 4) {
-		ret = false;
-		goto exit;
-	}
+	if (keyid >= 4)
+		return -EOPNOTSUPP;
 
 	switch (wep->KeyLength) {
 	case 5:
-		psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
+		secpriv->dot11PrivacyAlgrthm = _WEP40_;
 		break;
 	case 13:
-		psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
+		secpriv->dot11PrivacyAlgrthm = _WEP104_;
 		break;
 	default:
-		psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
+		secpriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
 		break;
 	}
 
-	memcpy(&psecuritypriv->dot11DefKey[keyid].skey[0], &wep->KeyMaterial, wep->KeyLength);
+	memcpy(secpriv->dot11DefKey[keyid].skey, &wep->KeyMaterial,
+	       wep->KeyLength);
 
-	psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
+	secpriv->dot11DefKeylen[keyid] = wep->KeyLength;
+	secpriv->dot11PrivacyKeyIndex = keyid;
 
-	psecuritypriv->dot11PrivacyKeyIndex = keyid;
+	if (rtw_set_key(padapter, secpriv, keyid, 1) == _FAIL)
+		return -ENOMEM;
 
-	res = rtw_set_key(padapter, psecuritypriv, keyid, 1);
-
-	if (res == _FAIL)
-		ret = false;
-exit:
-
-	return ret;
+	return 0;
 }
 
 /*

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ