From patchwork Mon Jan 22 10:37:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10178167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BAD6A60224 for ; Mon, 22 Jan 2018 10:37:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA88726E79 for ; Mon, 22 Jan 2018 10:37:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F19727F85; Mon, 22 Jan 2018 10:37:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 509AA26E79 for ; Mon, 22 Jan 2018 10:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751143AbeAVKh2 (ORCPT ); Mon, 22 Jan 2018 05:37:28 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:42038 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751093AbeAVKh0 (ORCPT ); Mon, 22 Jan 2018 05:37:26 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0MAb6HZ018935; Mon, 22 Jan 2018 10:37:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=dblmvBNA9suD6xW63LlcAwCQ1sZoTrbJSheIHeAQ70I=; b=b35DvGe80Oeb9COYDxm7Dz8cr6xT/cmBDk96WcNXN31mcL8L9zicaf+9r2YkYjpyHru1 Tx6O+Fq3RyCwPquArpTg8wlElJyNZlHQspZl0263u7crGfjAHuhQZo5sVd7Mqu5tOTVo 4zfFXFmqISQpAUuWlNkeYLN3J3ejGfQXbluBHUmTNG+Li5cT2HJp1ayP+DBOVbGy73PD NR6Q4Lb6L1WOxHFt4V7zJKwc+gGZnwlTNUEs4vlXAWr4lMct9lqoGM2tUHnLyL/A2v1r 7RG17CvBk/LrS3WEgJXGeh0ic2qSQTRC0CHNx0nnL0ElxWdqylDS2z8KIxzBoI9v3BNK wQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fne8s814a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jan 2018 10:37:23 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0MAbML7016933 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Jan 2018 10:37:22 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0MAbL2K014297; Mon, 22 Jan 2018 10:37:22 GMT Received: from mwanda (/41.202.241.56) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Jan 2018 02:37:21 -0800 Date: Mon, 22 Jan 2018 13:37:14 +0300 From: Dan Carpenter To: Sylwester Nawrocki Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] [media] s3c-camif: array underflow in __camif_subdev_try_format() Message-ID: <20180122103714.GA25044@mwanda> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.9.2 (2017-12-15) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8781 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=883 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801220153 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The while loop is a post op, "while (i-- >= 0)" so the last iteration will read camif_mbus_formats[-1] and then the loop will exit with "i" set to -2 and so we do: "mf->code = camif_mbus_formats[-2];". I've changed it to a pre-op, I've added a check to ensure we found the right format and I've removed the "mf->code = camif_mbus_formats[i];" because that is a no-op anyway. Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series camera interface") Signed-off-by: Dan Carpenter diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c index 437395a61065..012f4b389c55 100644 --- a/drivers/media/platform/s3c-camif/camif-capture.c +++ b/drivers/media/platform/s3c-camif/camif-capture.c @@ -1261,11 +1261,11 @@ static void __camif_subdev_try_format(struct camif_dev *camif, /* FIXME: constraints against codec or preview path ? */ pix_lim = &variant->vp_pix_limits[VP_CODEC]; - while (i-- >= 0) + while (--i >= 0) if (camif_mbus_formats[i] == mf->code) break; - - mf->code = camif_mbus_formats[i]; + if (i < 0) + return; if (pad == CAMIF_SD_PAD_SINK) { v4l_bound_align_image(&mf->width, 8, CAMIF_MAX_PIX_WIDTH,