Re: [PATCH v3] test_firmware: fix end of loop test in upload_read_show()

From: Luis Chamberlain
Date: Mon May 09 2022 - 18:37:50 EST


On Fri, May 06, 2022 at 09:55:15AM +0300, Dan Carpenter wrote:
> 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: a31ad463b72d ("test_firmware: Add test support for firmware upload")
> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
> Reviewed-by: Russ Weight <russell.h.weight@xxxxxxxxx>

Acked-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>

Luis