Commit d57e67e
media: atomisp: gc2235: fix UAF and memory leak
[ Upstream commit 628f763 ]
gc2235_probe() handles its error paths incorrectly.
If media_entity_pads_init() fails, gc2235_remove() is called, which
tears down the subdev and frees dev, but then still falls through to
atomisp_register_i2c_module(). This results in use-after-free.
If atomisp_register_i2c_module() fails, the media entity and control
handler are left initialized and dev is leaked.
gc2235_remove() unconditionally calls media_entity_cleanup() and
v4l2_ctrl_handler_free(), but these are not initialized at every
error path in gc2235_probe().
Replace gc2235_remove() calls in the probe error paths with explicit
unwind labels that free only the resources initialized at each point
of failure, in reverse order of initialization.
Fixes: a49d253 ("staging/atomisp: Add support for the Intel IPU v2")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
Reviewed-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 2e3e4cc commit d57e67e
1 file changed
Lines changed: 18 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
809 | 809 | | |
810 | 810 | | |
811 | 811 | | |
812 | | - | |
| 812 | + | |
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
| |||
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
| 821 | + | |
| 822 | + | |
825 | 823 | | |
826 | 824 | | |
827 | 825 | | |
828 | 826 | | |
829 | 827 | | |
830 | 828 | | |
831 | | - | |
832 | | - | |
| 829 | + | |
| 830 | + | |
833 | 831 | | |
834 | 832 | | |
835 | 833 | | |
| |||
838 | 836 | | |
839 | 837 | | |
840 | 838 | | |
841 | | - | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
842 | 844 | | |
843 | | - | |
| 845 | + | |
844 | 846 | | |
845 | | - | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
846 | 854 | | |
847 | 855 | | |
848 | | - | |
849 | 856 | | |
850 | 857 | | |
851 | 858 | | |
| |||
0 commit comments