Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1914673imm; Thu, 24 May 2018 02:51:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqHVc1tQ94NXfUrHUiYiOC60SeVtW60X//7k3ysXA76SXMZ6fTHNTy8PJKKrJa+af7KY1tO X-Received: by 2002:a65:64c7:: with SMTP id t7-v6mr5339809pgv.274.1527155501141; Thu, 24 May 2018 02:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155501; cv=none; d=google.com; s=arc-20160816; b=wBo6+WUIhADUwSKRomm0yc5ON1zmqj4D51x4tradzYQEDtMpfiyR0lx6ApPeA7bJCF X9j0E8eLEUnwfensEErLpE1a+RT9sdhkaDMsYDC4YaAot8UgqnZNzrk3qgWk9CVztL2s I7ToYya4v9xoNswZXdYMrssVGylfb8vlLA0efZCd9cTW2Iaw/wklkBpX3g/kCvbCz8BU p/WzH1H+C7WITqz26FnN/rInEB1mnGnu0llE13TSQCId3TpFxNPcfmofKCAfpWPh63PC GQzkwLlGXcVpZRa03JXIgsb4AS672l4OoxyHSAieUd0o3i1tl+52WJftE0PfrImhpSuT AClA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=3IVZ6e7hrpKB8cZioekUOHoL+K2qy6BOp3Gv/s8nBSs=; b=qjB+AMAUMyumc48jAxrGQSapMJdLGykGD7PJFFzcUHpvG2O1lK5n6fLrN6INqTB84Y +vfixfCSnvOcGKdt8ZExc4jk7FYrkx12oxWCKUu3Bm48M8oKcUhWtzud8UEzNN4t0tL7 qd1bF4Tgi4Q21bUjOAx0OuRTQql4P4bUOjkoz3Ju1Pw4RQ2T3+z4+AnodLvy0BRIaiL8 ZpMGrQpcjNiCgTAlrVTN+ljZyoqv66nzX91ndrXfwHS0tg1xPXMCaPzAZOOKAJC37CMc Q/AcK9vnkRQ9AD3znN2xvTAhM9FJMNXT2oxQmiDVviZehZSPUp4PL0Klmh24M3IJKIEP WcAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eiWyYSPE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k191-v6si16239443pgc.203.2018.05.24.02.51.26; Thu, 24 May 2018 02:51:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eiWyYSPE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966120AbeEXJug (ORCPT + 99 others); Thu, 24 May 2018 05:50:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:41834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967553AbeEXJuc (ORCPT ); Thu, 24 May 2018 05:50:32 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 935CC20870; Thu, 24 May 2018 09:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155432; bh=TfbyRYEPC4q4+UfWrUweS1dUHEbBi1tXQCj/Rdg/tmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eiWyYSPEtvXWjHBiolVwqN12KansTRvDKDMIyiBQ5U6JeizDWVxIvvKQNhPpjku7M KotauORNF6ylTsWu11Ev1GmX77PEXFVCSpAEiILaQfRNxHMxVAPsSDcDjAsDudLor4 3wbsDRA4xuUWS5aH+aTZwLIrk3li4u9Im8J4D2FQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Laurent Pinchart , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 83/96] media: s3c-camif: fix out-of-bounds array access Date: Thu, 24 May 2018 11:39:06 +0200 Message-Id: <20180524093610.159820625@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnd Bergmann [ 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 Reviewed-by: Laurent Pinchart Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/s3c-camif/camif-capture.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/media/platform/s3c-camif/camif-capture.c +++ b/drivers/media/platform/s3c-camif/camif-capture.c @@ -1256,16 +1256,17 @@ static void __camif_subdev_try_format(st { const struct s3c_camif_variant *variant = camif->variant; const struct vp_pix_limits *pix_lim; - int i = ARRAY_SIZE(camif_mbus_formats); + unsigned int i; /* FIXME: constraints against codec or preview path ? */ pix_lim = &variant->vp_pix_limits[VP_CODEC]; - while (i-- >= 0) + for (i = 0; i < ARRAY_SIZE(camif_mbus_formats); i++) if (camif_mbus_formats[i] == mf->code) break; - mf->code = camif_mbus_formats[i]; + if (i == ARRAY_SIZE(camif_mbus_formats)) + mf->code = camif_mbus_formats[0]; if (pad == CAMIF_SD_PAD_SINK) { v4l_bound_align_image(&mf->width, 8, CAMIF_MAX_PIX_WIDTH,