lib: Verify array index is correct before using it
PATCH 1/1 lib: Verify array index is correct before using it
This code reads from the array before verifying that "c" is a valid index. Move test array offset code before use to fix it.
Fixes 2da572c959dd ("lib: add software 842 compression/decompression")
Signed-off-by Huang Guobin <[email protected]>
--- lib/842/842_compress.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
lib/842/842_compress.c +5 -2
@@ -222,12 +222,13 @@ static int add_bits(struct sw842_param *p, u64 d, u8 n)static int add_template (struct sw842_param *p,u8 c) {int ret, i, b =0 ; -u8 *t = comp_ops[c]; +u8 *t =NULL ;bool inv = false;if (c >=OPS_MAX )return -EINVAL ; + t = comp_ops[c];pr_debug ("template %x\n" , t[4 ]); ret =add_bits (p, t[4 ],OP_BITS );
@@ -379,12 +380,14 @@ static int add_end_template(struct sw842_param *p)static bool check_template (struct sw842_param *p,u8 c) { -u8 *t = comp_ops[c]; +u8 *t =NULL ;int i, match, b =0 ;if (c >=OPS_MAX )return false; + t = comp_ops[c]; +for (i =0 ; i <4 ; i++) {if (t[i] &OP_ACTION_INDEX ) {if (t[i] &OP_AMOUNT_2 )
Signature · 1 line
2.17.1
Quoted 5 lines · Huang Guobin
This code reads from the array before verifying that "c" is a valid index. Move test array offset code before use to fix it.
Fixes 2da572c959dd ("lib: add software 842 compression/decompression")Signed-off-by Huang Guobin <[email protected]>
Hi,
Why shouldn't these locations use array_index_nospec() from #include <linux/nospec.h>
?
Quoted 30 lines
--- lib/842/842_compress.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)lib/842/842_compress.c +3
-2@@ -222,12 +222,13 @@ static int add_bits(struct sw842_param *p, u64 d, u8 n)static int add_template (struct sw842_param *p,u8 c) {int ret, i, b =0 ; -u8 *t = comp_ops[c]; +u8 *t =NULL ;bool inv = false;if (c >=OPS_MAX )return -EINVAL ; + t = comp_ops[c];pr_debug ("template %x\n" , t[4 ]); ret =add_bits (p, t[4 ],OP_BITS );@@ -379,12 +380,14 @@ static int add_end_template(struct sw842_param *p)static bool check_template (struct sw842_param *p,u8 c) { -u8 *t = comp_ops[c]; +u8 *t =NULL ;
lib/842/842_compress.c static int add_end_template(struct sw842_param *p) · line 393
Quoted 10 lines
lib/842/842_compress.c +2
-0int i, match, b =0 ;if (c >=OPS_MAX )return false; + t = comp_ops[c]; +for (i =0 ; i <4 ; i++) {if (t[i] &OP_ACTION_INDEX ) {if (t[i] &OP_AMOUNT_2 )
thanks.
Signature · 1 line
~Randy