[PATCH v3] media: dvb: mb86a16: fix array overflow in mb86a16_set_fe()

From: Ilya Krutskih

Date: Mon Feb 09 2026 - 12:59:43 EST


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.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: 41e840b13e11 ("V4L/DVB (13699): [Mantis, MB86A16] Initial checkin: Mantis, MB86A16")
Signed-off-by: Ilya Krutskih <devsec@xxxxxx>
---
v2: Add check for array's length on each cycle step,
edit patch description, edit tag 'fixes'.
https://lore.kernel.org/all/20251211172251.852254-1-devsec@xxxxxx/
v3: Edit condition to >= ARRAY_SIZE(). Move condition at cycle
beginning to prevent border check error.

drivers/media/dvb-frontends/mb86a16.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/media/dvb-frontends/mb86a16.c b/drivers/media/dvb-frontends/mb86a16.c
index 9033e39d75f4..5fabb6b884b5 100644
--- a/drivers/media/dvb-frontends/mb86a16.c
+++ b/drivers/media/dvb-frontends/mb86a16.c
@@ -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);
--
2.43.0