Received: by 10.192.165.148 with SMTP id m20csp3701606imm; Mon, 23 Apr 2018 10:49:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/3QeWMApj1ekaDPn3okPqqsO5td/kTwlXXp+P+WsJGNBoHDpbVNdzwbEqPYd0VjFxdPboE X-Received: by 10.98.16.74 with SMTP id y71mr13324858pfi.188.1524505751993; Mon, 23 Apr 2018 10:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524505751; cv=none; d=google.com; s=arc-20160816; b=ReW4csAiaXABp7ZSNlzwd/3qEcG1U2FJtuCRDMxESS0oj65EzyWCabmkeJrmDPOJfe yChmJvEU6ggLB0VBkpX2zwdd1WccRlK1BvVg0xuX8XFs8xFILiRKHbz+FJaIJjPXJUcZ 731e7hnX9NwjniugSjZplR2GRxaTJgcGSU330QiMgK4CCxGsVeN0pFT1Ss38PZfZyiDF 1xHCQLOQu7x3TQZHvu0C444JoCcK9QOHb4hn+HBYAnZ2jC5gSaVSj7aQ09GTJ5YZyVrW e3avi26QoCxNm2NYHBV2tEzVfHhh+I7eGj2lyzGwU4JLcm0tL99fJNdbUkTIlpM/umuM niuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=5ncFnWHRFzhfUcYdl81s3ZChKRBBDUToOTcCWKuw3yc=; b=U/suVoOp6NFilzRTiS3PqPV3M66YbQLSKnATiaMl3KE4R/EoJqYNg8btWA0SlRpTm9 4hhBIf18uRBFB4V2VkdWYl6e6TJKCkqP65pXZmNK59GgBIk+9MT/Edc3uCZDDfM1rKWd he71jx/vff/jcefi31z5js78anNpe0aEtH0bCIOghkSvyoPEKJc/Ipb3r8VqQ6mzUrPc 5ZT3Xte7hNLmvxg1DyaF3xCPDar2Geb4v7FRrKOaaIs9PkYhGHKwDwRgN8X3zIIK3hUo LNr2PFrPSegdXJYbAyE5AKZFbzndU83n8yOFOnyHyXc7s2jPn8zv84OtGqBq6ShiTy1Y lt1Q== ARC-Authentication-Results: i=1; mx.google.com; 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 x9-v6si11936355pln.508.2018.04.23.10.48.57; Mon, 23 Apr 2018 10:49:11 -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; 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 S932431AbeDWRrZ (ORCPT + 99 others); Mon, 23 Apr 2018 13:47:25 -0400 Received: from gateway32.websitewelcome.com ([192.185.145.184]:40953 "EHLO gateway32.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932421AbeDWRrW (ORCPT ); Mon, 23 Apr 2018 13:47:22 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 684798784B for ; Mon, 23 Apr 2018 12:47:21 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id AfYffZSrk6il3AfYffZzDS; Mon, 23 Apr 2018 12:47:21 -0500 X-Authority-Reason: nr=8 Received: from [189.145.48.65] (port=49584 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1fAfYe-0004i9-S3; Mon, 23 Apr 2018 12:47:21 -0500 Date: Mon, 23 Apr 2018 12:47:20 -0500 From: "Gustavo A. R. Silva" To: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , Dan Carpenter Cc: Niklas =?iso-8859-1?Q?S=F6derlund?= , linux-renesas-soc@vger.kernel.org Subject: [PATCH 06/11] rcar-v4l2: fix potential Spectre variant 1 Message-ID: <45621d4cd0639906cf16c4b4d666e8cd0e1c3694.1524499368.git.gustavo@embeddedor.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.145.48.65 X-Source-L: No X-Exim-ID: 1fAfYe-0004i9-S3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.145.48.65]:49584 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 46 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org f->index can be controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. Smatch warning: drivers/media/platform/rcar-vin/rcar-v4l2.c:344 rvin_enum_fmt_vid_cap() warn: potential spectre issue 'rvin_formats' Fix this by sanitizing f->index before using it to index rvin_formats. Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Cc: stable@vger.kernel.org Reported-by: Dan Carpenter Signed-off-by: Gustavo A. R. Silva --- drivers/media/platform/rcar-vin/rcar-v4l2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index b479b88..bbfc3b8 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -22,6 +22,8 @@ #include "rcar-vin.h" +#include + #define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV #define RVIN_MAX_WIDTH 2048 #define RVIN_MAX_HEIGHT 2048 @@ -340,7 +342,7 @@ static int rvin_enum_fmt_vid_cap(struct file *file, void *priv, { if (f->index >= ARRAY_SIZE(rvin_formats)) return -EINVAL; - + f->index = array_index_nospec(f->index, ARRAY_SIZE(rvin_formats)); f->pixelformat = rvin_formats[f->index].fourcc; return 0; -- 2.7.4