Skip to content

Commit 458ea1c

Browse files
committed
media: av7110: fix a spectre vulnerability
As warned by smatch: drivers/staging/media/av7110/av7110_ca.c:270 dvb_ca_ioctl() warn: potential spectre issue 'av7110->ci_slot' [w] (local cap) There is a spectre-related vulnerability at the code. Fix it. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 2aee207 commit 458ea1c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

drivers/staging/media/av7110/av7110.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct infrared {
8888
u32 ir_config;
8989
};
9090

91+
#define MAX_CI_SLOTS 2
92+
9193
/* place to store all the necessary device information */
9294
struct av7110 {
9395
/* devices */
@@ -163,7 +165,7 @@ struct av7110 {
163165

164166
/* CA */
165167

166-
struct ca_slot_info ci_slot[2];
168+
struct ca_slot_info ci_slot[MAX_CI_SLOTS];
167169

168170
enum av7110_video_mode vidmode;
169171
struct dmxdev dmxdev;

drivers/staging/media/av7110/av7110_ca.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,28 @@
2626

2727
void CI_handle(struct av7110 *av7110, u8 *data, u16 len)
2828
{
29+
unsigned slot_num;
30+
2931
dprintk(8, "av7110:%p\n", av7110);
3032

3133
if (len < 3)
3234
return;
3335
switch (data[0]) {
3436
case CI_MSG_CI_INFO:
35-
if (data[2] != 1 && data[2] != 2)
37+
if (data[2] != 1 && data[2] != MAX_CI_SLOTS)
3638
break;
39+
40+
slot_num = array_index_nospec(data[2] - 1, MAX_CI_SLOTS);
41+
3742
switch (data[1]) {
3843
case 0:
39-
av7110->ci_slot[data[2] - 1].flags = 0;
44+
av7110->ci_slot[slot_num].flags = 0;
4045
break;
4146
case 1:
42-
av7110->ci_slot[data[2] - 1].flags |= CA_CI_MODULE_PRESENT;
47+
av7110->ci_slot[slot_num].flags |= CA_CI_MODULE_PRESENT;
4348
break;
4449
case 2:
45-
av7110->ci_slot[data[2] - 1].flags |= CA_CI_MODULE_READY;
50+
av7110->ci_slot[slot_num].flags |= CA_CI_MODULE_READY;
4651
break;
4752
}
4853
break;
@@ -262,15 +267,19 @@ static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
262267
case CA_GET_SLOT_INFO:
263268
{
264269
struct ca_slot_info *info = (struct ca_slot_info *)parg;
270+
unsigned int slot_num;
265271

266272
if (info->num < 0 || info->num > 1) {
267273
mutex_unlock(&av7110->ioctl_mutex);
268274
return -EINVAL;
269275
}
270-
av7110->ci_slot[info->num].num = info->num;
271-
av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
272-
CA_CI_LINK : CA_CI;
273-
memcpy(info, &av7110->ci_slot[info->num], sizeof(struct ca_slot_info));
276+
slot_num = array_index_nospec(info->num, MAX_CI_SLOTS);
277+
278+
av7110->ci_slot[slot_num].num = info->num;
279+
av7110->ci_slot[slot_num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
280+
CA_CI_LINK : CA_CI;
281+
memcpy(info, &av7110->ci_slot[slot_num],
282+
sizeof(struct ca_slot_info));
274283
break;
275284
}
276285

0 commit comments

Comments
 (0)