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=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 87BC4C433E0 for ; Mon, 22 Feb 2021 22:52:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FDC564E4B for ; Mon, 22 Feb 2021 22:52:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FDC564E4B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE2C06B0005; Mon, 22 Feb 2021 17:51:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A92CF6B006C; Mon, 22 Feb 2021 17:51:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A8206B006E; Mon, 22 Feb 2021 17:51:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id 85F9A6B0005 for ; Mon, 22 Feb 2021 17:51:59 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3F7828792 for ; Mon, 22 Feb 2021 22:51:59 +0000 (UTC) X-FDA: 77847403158.25.5669949 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 40AAC138 for ; Mon, 22 Feb 2021 22:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614034317; 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=IeOmZDa1bOPIMQzG/nbsYMjhwjT+YmoDCx3V7/KXAWw=; b=d4k+FBqBmMhZiV2ynM9QFFMYLp89+b/6TtFnVY3Vx12nDV6GHHCKUm8iI1GT1uqtwBqyDs FGXYIKPnwIYr3yQaa5QL5X4b9XSHqNnkhz267TfMQnTppEtqPOgUfJCYK6D7N2d6Gntt+m y1sFU2b0COQfn49+9y1ctE+XbM8qUr8= 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-22-24CZabi4MriFpACI1S0xMg-1; Mon, 22 Feb 2021 17:51:48 -0500 X-MC-Unique: 24CZabi4MriFpACI1S0xMg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EECD618D6A22; Mon, 22 Feb 2021 22:51:46 +0000 (UTC) Received: from omen.home.shazbot.org (ovpn-112-255.phx2.redhat.com [10.3.112.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2353648A1; Mon, 22 Feb 2021 22:51:45 +0000 (UTC) Date: Mon, 22 Feb 2021 15:51:45 -0700 From: Alex Williamson To: Dan Carpenter Cc: kbuild@lists.01.org, Steve Sistare , lkp@intel.com, kbuild-all@lists.01.org, Linux Memory Management List , Cornelia Huck Subject: Re: [kbuild] [linux-next:master 6931/12022] drivers/vfio/vfio_iommu_type1.c:1093 vfio_dma_do_unmap() warn: impossible condition '(size > (~0)) => (0-u32max > u32max)' Message-ID: <20210222155145.50e2d513@omen.home.shazbot.org> In-Reply-To: <20210222141043.GW2222@kadam> References: <20210222141043.GW2222@kadam> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=alex.williamson@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 40AAC138 X-Stat-Signature: 9yof9ii9m9af1q8y13ne9a8tnh8xn4u7 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614034318-656579 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 22 Feb 2021 17:10:43 +0300 Dan Carpenter wrote: > tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master > head: 37dfbfbdca66834bc0f64ec9b35e09ac6c8898da > commit: 0f53afa12baec8c00f5d1d6afb49325ada105253 [6931/12022] vfio/type1: unmap cleanup It's always the patches that claim no functional change... ;) > config: i386-randconfig-m021-20210222 (attached as .config) > compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot > Reported-by: Dan Carpenter > > New smatch warnings: > drivers/vfio/vfio_iommu_type1.c:1093 vfio_dma_do_unmap() warn: impossible condition '(size > (~0)) => (0-u32max > u32max)' > > vim +1093 drivers/vfio/vfio_iommu_type1.c > > 73fa0d10d077d9 Alex Williamson 2012-07-31 1071 static int vfio_dma_do_unmap(struct vfio_iommu *iommu, > 331e33d2960c82 Kirti Wankhede 2020-05-29 1072 struct vfio_iommu_type1_dma_unmap *unmap, > 331e33d2960c82 Kirti Wankhede 2020-05-29 1073 struct vfio_bitmap *bitmap) > 73fa0d10d077d9 Alex Williamson 2012-07-31 1074 { > c086de818dd81c Kirti Wankhede 2016-11-17 1075 struct vfio_dma *dma, *dma_last = NULL; > 331e33d2960c82 Kirti Wankhede 2020-05-29 1076 size_t unmapped = 0, pgsize; > 0f53afa12baec8 Steve Sistare 2021-01-29 1077 int ret = -EINVAL, retries = 0; > 331e33d2960c82 Kirti Wankhede 2020-05-29 1078 unsigned long pgshift; > 0f53afa12baec8 Steve Sistare 2021-01-29 1079 dma_addr_t iova = unmap->iova; > 0f53afa12baec8 Steve Sistare 2021-01-29 1080 unsigned long size = unmap->size; > ^^^^^^^^^^^^^^^^^^ > > 73fa0d10d077d9 Alex Williamson 2012-07-31 1081 > cade075f265b25 Kirti Wankhede 2020-05-29 1082 mutex_lock(&iommu->lock); > cade075f265b25 Kirti Wankhede 2020-05-29 1083 > 331e33d2960c82 Kirti Wankhede 2020-05-29 1084 pgshift = __ffs(iommu->pgsize_bitmap); > 331e33d2960c82 Kirti Wankhede 2020-05-29 1085 pgsize = (size_t)1 << pgshift; > cade075f265b25 Kirti Wankhede 2020-05-29 1086 > 0f53afa12baec8 Steve Sistare 2021-01-29 1087 if (iova & (pgsize - 1)) > cade075f265b25 Kirti Wankhede 2020-05-29 1088 goto unlock; > cade075f265b25 Kirti Wankhede 2020-05-29 1089 > 0f53afa12baec8 Steve Sistare 2021-01-29 1090 if (!size || size & (pgsize - 1)) > cade075f265b25 Kirti Wankhede 2020-05-29 1091 goto unlock; > 73fa0d10d077d9 Alex Williamson 2012-07-31 1092 > 0f53afa12baec8 Steve Sistare 2021-01-29 @1093 if (iova + size - 1 < iova || size > SIZE_MAX) > > size is unsigned long and SIZE_MAX is ULONG_MAX so "size > SIZE_MAX" > does not make sense. I think it made sense before the above commit, where unmap->size is a __u64 and a user could provide a value that exceeds SIZE_MAX on ILP32. Seems like the fix is probably to use a size_t for the local variable and restore this test to compare (unmap->size > SIZE_MAX). Steve? > Is the " - 1" intentional on the other overflow check? As in it's okay > to wrap around to zero but not further than that? Sometimes this is > intentional but it requires more subsystem expertise than I possess. Yes, since we're dealing with a start + length we need to account for the -1 in the end value, otherwise the user could never unmap the last page of the address space. Thanks for the report! Alex > cade075f265b25 Kirti Wankhede 2020-05-29 1094 goto unlock; > 73fa0d10d077d9 Alex Williamson 2012-07-31 1095 > 331e33d2960c82 Kirti Wankhede 2020-05-29 1096 /* When dirty tracking is enabled, allow only min supported pgsize */ > 331e33d2960c82 Kirti Wankhede 2020-05-29 1097 if ((unmap->flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) && > 331e33d2960c82 Kirti Wankhede 2020-05-29 1098 (!iommu->dirty_page_tracking || (bitmap->pgsize != pgsize))) { > 331e33d2960c82 Kirti Wankhede 2020-05-29 1099 goto unlock; > 331e33d2960c82 Kirti Wankhede 2020-05-29 1100 } > 73fa0d10d077d9 Alex Williamson 2012-07-31 1101 > 331e33d2960c82 Kirti Wankhede 2020-05-29 1102 WARN_ON((pgsize - 1) & PAGE_MASK); > 331e33d2960c82 Kirti Wankhede 2020-05-29 1103 again: > 1ef3e2bc04223f Alex Williamson 2014-02-26 1104 /* > > --- > 0-DAY CI Kernel Test Service, Intel Corporation > https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org