Skip to contentSkip to conversation

NFS thinko

PATCH Dave Jones 3 participants 3 messages Apr 16, 2004

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

Dereferencing 'exp' before the check for NULL.

Dave

include/linux/nfsd/export.h renamed from include/linux/nfsd/export.h~ +4 -2
@@ -118,13 +118,15 @@
 	if (ek && !IS_ERR(ek)) {
 		struct svc_export *exp = ek->ek_export;
 		int err;
+		if (!exp)
+			goto out;
 		cache_get(&exp->h);
 		expkey_put(&ek->h, &svc_expkey_cache);
-		if (exp &&
-		    (err = cache_check(&svc_export_cache, &exp->h, reqp)))
+		if (err = cache_check(&svc_export_cache, &exp->h, reqp))
 			exp = ERR_PTR(err);
 		return exp;
 	} else
+out:
 		return ERR_PTR(PTR_ERR(ek));
 }
 
#1 lore raw
Quoted 1 line · Dave Jones

Dereferencing 'exp' before the check for NULL.

Hmm. If we're referencing 'ek' to get at exp, 'ek' isn't an error, so it shouldn't be passed into PTR_ERR().

Quoted 19 lines
include/linux/nfsd/export.h renamed from include/linux/nfsd/export.h~ +4 -2
@@ -118,13 +118,15 @@
 	if (ek && !IS_ERR(ek)) {
 		struct svc_export *exp = ek->ek_export;
 		int err;
+		if (!exp)
+			goto out;
 		cache_get(&exp->h);
 		expkey_put(&ek->h, &svc_expkey_cache);
-		if (exp &&
-		    (err = cache_check(&svc_export_cache, &exp->h, reqp)))
+		if (err = cache_check(&svc_export_cache, &exp->h, reqp))
 			exp = ERR_PTR(err);
 		return exp;
 	} else
+out:
 		return ERR_PTR(PTR_ERR(ek));
 }
Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#2 lore raw
In reply to Dave Jones
Quoted 1 line · Dave Jones

Dereferencing 'exp' before the check for NULL.

It would be a bug if exp were ever NULL there. Better just to delete that check entirely.

--Bruce Fields

If ek = exp_find_key() is not an error, then ek->ek_export should be set; no point in checking if it's NULL.

 include/linux/nfsd/export.h |    3 +--
 1 files changed, 1 insertion(+), 2 deletions(-)
include/linux/nfsd/export.h renamed from include/linux/nfsd/export.h~export_exp_deref_fix +1 -2
diff -puN include/linux/nfsd/export.h~export_exp_deref_fix include/linux/nfsd/export.h
@@ -120,8 +120,7 @@ exp_find(struct auth_domain *clp, int fs
 		int err;
 		cache_get(&exp->h);
 		expkey_put(&ek->h, &svc_expkey_cache);
-		if (exp &&
-		    (err = cache_check(&svc_export_cache, &exp->h, reqp)))
+		if ((err = cache_check(&svc_export_cache, &exp->h, reqp)))
 			exp = ERR_PTR(err);
 		return exp;
 	} else

_