Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp53021pxb; Mon, 2 Nov 2020 13:48:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMPpzIdG2BsITQ8oMVnk2Ul+PCgbxNbIS1yRn5QaGCkp0pCDOF1MVAc/RPR0vLQaXDOA3o X-Received: by 2002:a17:906:66c9:: with SMTP id k9mr4485635ejp.204.1604353699628; Mon, 02 Nov 2020 13:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604353699; cv=none; d=google.com; s=arc-20160816; b=FHrD3uVaejxC3V++6BLI5p07fzYrwI9EVjPg7QuSrQci1MB2bxzFkb48h+y1rvfiMh 6KDpiQbWI7YmfNm+2qcapGW+sQBhVAzgkLkbWMXxepv+rt50U0SgQ/akAZKK28C09S7R QQnDAFK5Be9XQsT3cfRTOdxAaNImGutY4gPrCiBFZQh8CM8s4j1X2p2fhcZWu3SQ95rQ wfL5yuiFPJionorvZe2Q8jqXf2w59qswwGfK89AXMOCDTjya+T1PhKJOtF0eXbmtiiNG 53yj9o93DwtPoSw+BXDvowc3dwuQp8EDGL3gXHzI+DlhndYdQkfckzttn0wQG9ZeDb7S LYsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ppDWZLFuLILFXtSDmcPrGG8E8KknQmLkxXAxflMcQvY=; b=RYC0/QuLfFXsInmy+T66MoWlCMJYmGsvehdcalDbEpxnYM3qnZ6hL5p96wcZjRF9Je /cRp0WOfi7M5QWhm6RxgJ9bImeyaEWtgyQQ8sKk4xrHy2S5SXtZdCXKH8cMuyck+N0zn PnX8nJRPNVE2XKXn1KGgtqqy55tlP++L+R3LFJvaogTVCrDMO0XSaDyWitdiaUUZ/k5H ARngv+G/qf++/700/pR1/qFrz+E+BSVT6eWJUDk6qXUZK+5pzJkA9xKWSIbG78IrS/tF dslY1r0WdB83Xu4zKgRZBPZMPkOECEgxG/u63fusb3PAkGQ1GmKxe060AUXIncSBR7HI 5tig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="EGQaCpK/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si3366958eds.368.2020.11.02.13.47.56; Mon, 02 Nov 2020 13:48:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="EGQaCpK/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725952AbgKBVpv (ORCPT + 99 others); Mon, 2 Nov 2020 16:45:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21301 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbgKBVpu (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: linux-kernel@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); >