Skip to content

Commit 9a4e784

Browse files
author
Russell King
committed
component: fix crash on x86_64 with hda audio drivers
Maarten reports that the addition of releasing match data to the component helper results in a general protection fault on x86_64. This is caused by the devm resources being freed in reverse order to their allocation, which caused a use-after-free of the match array. Switch the match array to be a more conventional kmalloc/kfree() affair, explicitly freeing it along with the parent match data structure. Reported-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Fixes: ce657b1 ("component: add support for releasing match data") Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent ce657b1 commit 9a4e784

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎drivers/base/component.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static void component_match_release(struct device *master,
206206
if (mc->release)
207207
mc->release(master, mc->data);
208208
}
209+
210+
kfree(match->compare);
209211
}
210212

211213
static void devm_component_match_release(struct device *dev, void *res)
@@ -221,14 +223,14 @@ static int component_match_realloc(struct device *dev,
221223
if (match->alloc == num)
222224
return 0;
223225

224-
new = devm_kmalloc_array(dev, num, sizeof(*new), GFP_KERNEL);
226+
new = kmalloc_array(num, sizeof(*new), GFP_KERNEL);
225227
if (!new)
226228
return -ENOMEM;
227229

228230
if (match->compare) {
229231
memcpy(new, match->compare, sizeof(*new) *
230232
min(match->num, num));
231-
devm_kfree(dev, match->compare);
233+
kfree(match->compare);
232234
}
233235
match->compare = new;
234236
match->alloc = num;

0 commit comments

Comments
 (0)