liveupdate: luo_file: don't use invalid list iterator
Subsystems (2)
PATCH 1/1 liveupdate: luo_file: don't use invalid list iterator
If we exit a list_for_each_entry() without hitting a break then the list iterator points to an offset from the list_head. It's a non-NULL but invalid pointer and dereferencing it isn't allowed.
Introduce a new "found" variable to test instead.
---
Presumably, this going to be folded into the original patch. I just added the tags because they are harmless.
kernel/liveupdate/luo_file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/liveupdate/luo_file.c +5 -2
@@ -561,17 +561,20 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, {struct liveupdate_file_op_args args = {0 };struct luo_file *luo_file; +bool found = false;int err;if (list_empty (&file_set->files_list))return -ENOENT ;list_for_each_entry (luo_file, &file_set->files_list, list) { -if (luo_file->token == token) +if (luo_file->token == token) { + found = true;break ; + } } -if (luo_file->token != token) +if (!found)return -ENOENT ;guard (mutex)(&luo_file->mutex);
Signature · 1 line
2.51.0
Quoted 10 lines · Dan Carpenter
If we exit a
list_for_each_entry()without hitting a break then the list iterator points to an offset from thelist_head. It's a non-NULL but invalid pointer and dereferencing it isn't allowed.Introduce a new "found" variable to test instead.
Fixes 3ee1d673194e ("liveupdate: luo_file: implement file systems callbacks")Reported-by kernel test robot <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
Quoted 37 lines
---
Presumably, this going to be folded into the original patch. I just added the tags because they are harmless.kernel/liveupdate/luo_file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/liveupdate/luo_file.c +5
-2@@ -561,17 +561,20 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token, {struct liveupdate_file_op_args args = {0 };struct luo_file *luo_file; +bool found = false;int err;if (list_empty (&file_set->files_list))return -ENOENT ;list_for_each_entry (luo_file, &file_set->files_list, list) { -if (luo_file->token == token) +if (luo_file->token == token) { + found = true;break ; + } } -if (luo_file->token != token) +if (!found)return -ENOENT ;guard (mutex)(&luo_file->mutex);Signature · 1 line
2.51.0
Signature · 2 lines
Sincerely yours, Mike.
Quoted 4 lines
Fixes 3ee1d673194e ("liveupdate: luo_file: implement file systems callbacks")Reported-by kernel test robot <[email protected]>Signed-off-by Dan Carpenter <[email protected]>
Thank you,
Pasha
Pasha Tatashin
maintainerQuoted 7 lines · Pasha Tatashin
Quoted 5 lines
Fixes 3ee1d673194e ("liveupdate: luo_file: implement file systems callbacks")Reported-by kernel test robot <[email protected]>Signed-off-by Dan Carpenter <[email protected]>Reviewed-by Pasha Tatashin <[email protected]>
Given that this patch is already in nonmm-stable, it should be OK to apply this fix in one of the RCs.
Quoted 3 lines
Thank you,
Pasha