Skip to content

Commit 98c49f1

Browse files
GustavoARSilvagregkh
authored andcommitted
char: hpet: Fix out-of-bounds read bug
Currently, there is an out-of-bounds read on array hpetp->hp_dev in the following for loop: 870 for (i = 0; i < hdp->hd_nirqs; i++) 871 hpetp->hp_dev[i].hd_hdwirq = hdp->hd_irq[i]; This is due to the recent change from one-element array to flexible-array member in struct hpets: 104 struct hpets { ... 113 struct hpet_dev hp_dev[]; 114 }; This change affected the total size of the dynamic memory allocation, decreasing it by one time the size of struct hpet_dev. Fix this by adjusting the allocation size when calling struct_size(). Fixes: 987f028 ("char: hpet: Use flexible-array member") Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Tetsuo Handa <[email protected]> Acked-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 15d6632 commit 98c49f1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/char/hpet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ int hpet_alloc(struct hpet_data *hdp)
855855
return 0;
856856
}
857857

858-
hpetp = kzalloc(struct_size(hpetp, hp_dev, hdp->hd_nirqs - 1),
858+
hpetp = kzalloc(struct_size(hpetp, hp_dev, hdp->hd_nirqs),
859859
GFP_KERNEL);
860860

861861
if (!hpetp)

0 commit comments

Comments
 (0)