]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
char: hpet: Fix out-of-bounds read bug
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 29 Jan 2020 02:26:13 +0000 (20:26 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Feb 2020 07:38:46 +0000 (08:38 +0100)
commitb694a3efe713b538ed14d737021dd3fec61e2c73
treece60b8cddcf42dcccfb763fbbcd8be59d77dbbf5
parentbbff9cd26170b98fa296df79bd2aec0f98e4f071
char: hpet: Fix out-of-bounds read bug

[ Upstream commit 98c49f1746ac44ccc164e914b9a44183fad09f51 ]

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: 987f028b8637c ("char: hpet: Use flexible-array member")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Eric Biggers <ebiggers@kernel.org>
Link: https://lore.kernel.org/r/20200129022613.GA24281@embeddedor.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/char/hpet.c