regmap: debugfs: check count when read regmap file
authorPeng Fan <peng.fan@nxp.com>
Fri, 13 Mar 2020 01:58:07 +0000 (09:58 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 31 Jul 2020 16:47:16 +0000 (18:47 +0200)
commitaf5b25c4dbbcc33fed592d6640c54bd675d1a3b4
tree30d29618a554abec9193f0e13e382b4663a53706
parentaddf0dfbe249e5f2062eefdc953c656ddd406b99
regmap: debugfs: check count when read regmap file

commit 74edd08a4fbf51d65fd8f4c7d8289cd0f392bd91 upstream.

When executing the following command, we met kernel dump.
dmesg -c > /dev/null; cd /sys;
for i in `ls /sys/kernel/debug/regmap/* -d`; do
echo "Checking regmap in $i";
cat $i/registers;
done && grep -ri "0x02d0" *;

It is because the count value is too big, and kmalloc fails. So add an
upper bound check to allow max size `PAGE_SIZE << (MAX_ORDER - 1)`.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Link: https://lore.kernel.org/r/1584064687-12964-1-git-send-email-peng.fan@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/regmap/regmap-debugfs.c