forked from Minki/linux
test_firmware: fix end of loop test in upload_read_show()
If a list_for_each_entry() loop exits without hitting a break statement
then the iterator points to invalid memory. So in this code the
"tst->name" dereference is an out bounds read. It's an offset from the
&test_upload_list pointer and it will likely work fine most of the time
but it's not correct.
One alternative is to fix this this by changing the test to:
if (list_entry_is_head(tst, &test_upload_list, node)) {
But the simpler, trendy new way is just create a new variable and test
for NULL.
Fixes: a31ad463b7
("test_firmware: Add test support for firmware upload")
Reviewed-by: Russ Weight <russell.h.weight@intel.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YnTGU3UJOIA09I7e@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1f7ff11ca6
commit
185b29c615
@ -1392,7 +1392,8 @@ static ssize_t upload_read_show(struct device *dev,
|
|||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct test_firmware_upload *tst;
|
struct test_firmware_upload *tst = NULL;
|
||||||
|
struct test_firmware_upload *tst_iter;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
if (!test_fw_config->upload_name) {
|
if (!test_fw_config->upload_name) {
|
||||||
@ -1401,11 +1402,13 @@ static ssize_t upload_read_show(struct device *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&test_fw_mutex);
|
mutex_lock(&test_fw_mutex);
|
||||||
list_for_each_entry(tst, &test_upload_list, node)
|
list_for_each_entry(tst_iter, &test_upload_list, node)
|
||||||
if (tst->name == test_fw_config->upload_name)
|
if (tst_iter->name == test_fw_config->upload_name) {
|
||||||
|
tst = tst_iter;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (tst->name != test_fw_config->upload_name) {
|
if (!tst) {
|
||||||
pr_err("Firmware name not found: %s\n",
|
pr_err("Firmware name not found: %s\n",
|
||||||
test_fw_config->upload_name);
|
test_fw_config->upload_name);
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
Reference in New Issue
Block a user