Skip to contentSkip to conversation

media: dvb: mb86a16: fix array overflow in mb86a16_set_fe()

PATCH New Ilya Krutskih 1 participant 1 message Mar 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 media: dvb: mb86a16: fix array overflow in mb86a16_set_fe()

The size of prev_swp_freq[] is a fixed constant unrelated to the number of possible detection attempts. Index 'prev_freq_num' of array 'prev_swp_freq' is incremented by each step in cycle. If index exceeds the total length of array, an out-of-bounds access might happen, in case of repeated unsuccessful signal acquisition. Add check to prevent this.

Fixes 41e840b13e11 ("V4L/DVB (13699): [Mantis, MB86A16] Initial checkin: Mantis, MB86A16")

---
v2: Add check for array's length on each cycle step, edit patch description, edit tag 'fixes'.
https://lore.kernel.org/all/[email protected]/
v3: Edit condition to > ARRAY_SIZE() - 1, add a reason because of overflow can happen in description of patch
v4: Edit condition to >= ARRAY_SIZE()
v5: delete unnecessary check after incrementing

 drivers/media/dvb-frontends/mb86a16.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/dvb-frontends/mb86a16.c +4 -0
index 9033e39d75f4..5fabb6b884b5 100644
@@ -1157,6 +1157,10 @@ static int mb86a16_set_fe(struct mb86a16_state *state)
 		v = 0;
 
 		while (loop == 1) {
+			if (prev_freq_num >= ARRAY_SIZE(prev_swp_freq)) {
+				dprintk(verbose, MB86A16_ERROR, 1, "Signal detection retry attempts failed");
+				return -1;
+			}
 			swp_info_get(state, fOSC_start, state->srate,
 				     v, R, swp_ofs, &fOSC,
 				     &afcex_freq, &AFCEX_L, &AFCEX_H);
Signature · 1 line
2.43.0