From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91A4DC2D0A3 for ; Mon, 2 Nov 2020 21:45:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3002021D40 for ; Mon, 2 Nov 2020 21:45:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EGQaCpK/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725947AbgKBVpv (ORCPT ); Mon, 2 Nov 2020 16:45:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46244 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgKBVpu (ORCPT ); Mon, 2 Nov 2020 16:45:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604353549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ppDWZLFuLILFXtSDmcPrGG8E8KknQmLkxXAxflMcQvY=; b=EGQaCpK/0A464GsZIikOvPx6TD8urIi1aKFoY9SXe2HN7D1dRNgaC/cKfC2b6fSn3/okvB wHCdQCqNLtFDQmFF1YxShN8/DW4U0BUVMlhYDgxqrWtttAEMOSaCAhjT+vidyqIikA/Qp3 G7I+3nhCbqhgfIXWSxumNeb7gTm/TkU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-iEqOaznvOAyBP9zldyFhcQ-1; Mon, 02 Nov 2020 16:45:47 -0500 X-MC-Unique: iEqOaznvOAyBP9zldyFhcQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4794E57202; Mon, 2 Nov 2020 21:45:46 +0000 (UTC) Received: from w520.home (ovpn-112-213.phx2.redhat.com [10.3.112.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6F3E10013C0; Mon, 2 Nov 2020 21:45:45 +0000 (UTC) Date: Mon, 2 Nov 2020 14:45:38 -0700 From: Alex Williamson To: Diana Craciun Cc: Dan Carpenter , Cornelia Huck , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH 2/2] vfio/fsl-mc: prevent underflow in vfio_fsl_mc_mmap() Message-ID: <20201102144538.2871369d@w520.home> In-Reply-To: <20201023112947.GF282278@mwanda> References: <20201023112947.GF282278@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Diana, same for this one. Thanks, Alex On Fri, 23 Oct 2020 14:29:47 +0300 Dan Carpenter wrote: > My static analsysis tool complains that the "index" can be negative. > There are some checks in do_mmap() which try to prevent underflows but > I don't know if they are sufficient for this situation. Either way, > making "index" unsigned is harmless so let's do it just to be safe. > > Fixes: 67247289688d ("vfio/fsl-mc: Allow userspace to MMAP fsl-mc device MMIO regions") > Signed-off-by: Dan Carpenter > --- > drivers/vfio/fsl-mc/vfio_fsl_mc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c > index 21f22e3da11f..f27e25112c40 100644 > --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c > +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c > @@ -472,7 +472,7 @@ static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma) > { > struct vfio_fsl_mc_device *vdev = device_data; > struct fsl_mc_device *mc_dev = vdev->mc_dev; > - int index; > + unsigned int index; > > index = vma->vm_pgoff >> (VFIO_FSL_MC_OFFSET_SHIFT - PAGE_SHIFT); >