staging: lustre: ldlm: fix a use after free in ldlm_resource_get()
authorJohn L. Hammond <john.hammond@intel.com>
Sun, 18 Sep 2016 20:37:02 +0000 (16:37 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Sep 2016 07:24:10 +0000 (09:24 +0200)
If lvbo initialization has failed then save the return status (from
lr_lvb_len) before putting the resource.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5305
Reviewed-on: http://review.whamcloud.com/11017
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Emoly Liu <emoly.liu@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c

index 62d9f6f0edabe983affe3dd189f7bc4c09827ae0..912cd680d0f1755511e95682c0742719843f6e56 100644 (file)
@@ -1091,6 +1091,7 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
        struct cfs_hash_bd       bd;
        __u64            version;
        int                   ns_refcount = 0;
+       int rc;
 
        LASSERT(!parent);
        LASSERT(ns->ns_rs_hash);
@@ -1140,8 +1141,9 @@ lvbo_init:
                }
 
                if (unlikely(res->lr_lvb_len < 0)) {
+                       rc = res->lr_lvb_len;
                        ldlm_resource_putref(res);
-                       res = ERR_PTR(res->lr_lvb_len);
+                       res = ERR_PTR(rc);
                }
                return res;
        }
@@ -1152,8 +1154,6 @@ lvbo_init:
 
        cfs_hash_bd_unlock(ns->ns_rs_hash, &bd, 1);
        if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
-               int rc;
-
                OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
                rc = ns->ns_lvbo->lvbo_init(res);
                if (rc < 0) {