diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2015-04-21 09:46:28 -0400 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2015-05-05 11:20:13 -0400 |
commit | d67e199611b986b345ea3087ee2e4a15da1c98b3 (patch) | |
tree | 8b405a9337c27c2ae7b64080a88806f88d8c7363 /drivers/firmware/efi/runtime-map.c | |
parent | 98b228f55014870092c15d7d168fecac69f2f12a (diff) |
efi: Fix error handling in add_sysfs_runtime_map_entry()
I spotted two (difficult to hit) bugs while reviewing this.
1) There is a double free bug because we unregister "map_kset" in
add_sysfs_runtime_map_entry() and also efi_runtime_map_init().
2) If we fail to allocate "entry" then we should return
ERR_PTR(-ENOMEM) instead of NULL.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Guangyu Sun <guangyu.sun@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'drivers/firmware/efi/runtime-map.c')
-rw-r--r-- | drivers/firmware/efi/runtime-map.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/firmware/efi/runtime-map.c b/drivers/firmware/efi/runtime-map.c index 87b8e3b900d2..5c55227a34c8 100644 --- a/drivers/firmware/efi/runtime-map.c +++ b/drivers/firmware/efi/runtime-map.c | |||
@@ -120,7 +120,8 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr) | |||
120 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); | 120 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
121 | if (!entry) { | 121 | if (!entry) { |
122 | kset_unregister(map_kset); | 122 | kset_unregister(map_kset); |
123 | return entry; | 123 | map_kset = NULL; |
124 | return ERR_PTR(-ENOMEM); | ||
124 | } | 125 | } |
125 | 126 | ||
126 | memcpy(&entry->md, efi_runtime_map + nr * efi_memdesc_size, | 127 | memcpy(&entry->md, efi_runtime_map + nr * efi_memdesc_size, |
@@ -132,6 +133,7 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr) | |||
132 | if (ret) { | 133 | if (ret) { |
133 | kobject_put(&entry->kobj); | 134 | kobject_put(&entry->kobj); |
134 | kset_unregister(map_kset); | 135 | kset_unregister(map_kset); |
136 | map_kset = NULL; | ||
135 | return ERR_PTR(ret); | 137 | return ERR_PTR(ret); |
136 | } | 138 | } |
137 | 139 | ||
@@ -195,8 +197,6 @@ out_add_entry: | |||
195 | entry = *(map_entries + j); | 197 | entry = *(map_entries + j); |
196 | kobject_put(&entry->kobj); | 198 | kobject_put(&entry->kobj); |
197 | } | 199 | } |
198 | if (map_kset) | ||
199 | kset_unregister(map_kset); | ||
200 | out: | 200 | out: |
201 | return ret; | 201 | return ret; |
202 | } | 202 | } |