Skip to content

Commit 3af86b0

Browse files
zhou1615mchehab
authored andcommitted
media: saa7146: hexium_gemini: Fix a NULL pointer dereference in hexium_attach()
In hexium_attach(dev, info), saa7146_vv_init() is called to allocate a new memory for dev->vv_data. saa7146_vv_release() will be called on failure of saa7146_register_device(). There is a dereference of dev->vv_data in saa7146_vv_release(), which could lead to a NULL pointer dereference on failure of saa7146_vv_init(). Fix this bug by adding a check of saa7146_vv_init(). This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_VIDEO_HEXIUM_GEMINI=m show no new warnings, and our static analyzer no longer warns about this code. Link: https://lore.kernel.org/linux-media/[email protected] Signed-off-by: Zhou Qingyang <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent ce560ee commit 3af86b0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

drivers/media/common/saa7146/saa7146_fops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
521521
ERR("out of memory. aborting.\n");
522522
kfree(vv);
523523
v4l2_ctrl_handler_free(hdl);
524-
return -1;
524+
return -ENOMEM;
525525
}
526526

527527
saa7146_video_uops.init(dev,vv);

drivers/media/pci/saa7146/hexium_gemini.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
284284
hexium_set_input(hexium, 0);
285285
hexium->cur_input = 0;
286286

287-
saa7146_vv_init(dev, &vv_data);
287+
ret = saa7146_vv_init(dev, &vv_data);
288+
if (ret) {
289+
i2c_del_adapter(&hexium->i2c_adapter);
290+
kfree(hexium);
291+
return ret;
292+
}
288293

289294
vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input;
290295
vv_data.vid_ops.vidioc_g_input = vidioc_g_input;

0 commit comments

Comments
 (0)