Skip to content

Commit

Permalink
media: saa7146: hexium_gemini: Fix a NULL pointer dereference in hexi…
Browse files Browse the repository at this point in the history
…um_attach()

[ Upstream commit 3af86b046933ba513d08399dba0d4d8b50d607d0 ]

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/20211203154030.111210-1-zhou1615@umn.edu
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
zhou1615 authored and gregkh committed Jan 27, 2022
1 parent 6f391d8 commit a7ca0aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/media/common/saa7146/saa7146_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
ERR("out of memory. aborting.\n");
kfree(vv);
v4l2_ctrl_handler_free(hdl);
return -1;
return -ENOMEM;
}

saa7146_video_uops.init(dev,vv);
Expand Down
7 changes: 6 additions & 1 deletion drivers/media/pci/saa7146/hexium_gemini.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
hexium_set_input(hexium, 0);
hexium->cur_input = 0;

saa7146_vv_init(dev, &vv_data);
ret = saa7146_vv_init(dev, &vv_data);
if (ret) {
i2c_del_adapter(&hexium->i2c_adapter);
kfree(hexium);
return ret;
}

vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input;
vv_data.vid_ops.vidioc_g_input = vidioc_g_input;
Expand Down

0 comments on commit a7ca0aa

Please sign in to comment.