]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
media: s3c-camif: fix out-of-bounds array access
authorArnd Bergmann <arnd@arndb.de>
Tue, 16 Jan 2018 21:52:15 +0000 (16:52 -0500)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 14 Aug 2018 10:29:38 +0000 (12:29 +0200)
commitee15c953f5e1e60d86c0e815694ee00e82a19c37
treebe83dccb00421559a818ac188e3e8623608e1f06
parentbabd09d33582e90b6b78163cc53545283f73098e
media: s3c-camif: fix out-of-bounds array access

BugLink: http://bugs.launchpad.net/bugs/1783418
[ Upstream commit a398e043637a4819a0e96467bfecaabf3224dd62 ]

While experimenting with older compiler versions, I ran
into a warning that no longer shows up on gcc-4.8 or newer:

drivers/media/platform/s3c-camif/camif-capture.c: In function '__camif_subdev_try_format':
drivers/media/platform/s3c-camif/camif-capture.c:1265:25: error: array subscript is below array bounds

This is an off-by-one bug, leading to an access before the start of the
array, while newer compilers silently assume this undefined behavior
cannot happen and leave the loop at index 0 if no other entry matches.

As Sylvester explains, we actually need to ensure that the
value is within the range, so this reworks the loop to be
easier to parse correctly, and an additional check to fall
back on the first format value for any unexpected input.

I found an existing gcc bug for it and added a reduced version
of the function there.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69249#c3
Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series camera interface")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/media/platform/s3c-camif/camif-capture.c