From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C2910A32A2 for ; Thu, 24 Oct 2019 14:11:04 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 381B11E9D6; Thu, 24 Oct 2019 14:11:04 +0200 (CEST) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by dpdk.org (Postfix) with ESMTP id 75F261E9B3 for ; Thu, 24 Oct 2019 14:11:00 +0200 (CEST) Received: by mail-lj1-f193.google.com with SMTP id d1so24711410ljl.13 for ; Thu, 24 Oct 2019 05:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AqlpZOr139OB1unsh2SClg8WVN5Fa/eQjiAu6KjjAk4=; b=0WQjtWG+POhcY/O3gO0UxgL5/qSeSK/2R5Xme/p6aBC0M9gq7rOw+ZfV5e+xC+aYFY WlFgVY6cPcDbebbZ+IUfbiwMMaA5rsKtD9/41kPOkDhZpvnhTEIb5B/iAMHYDC1mu9mC 32PHmfcb436RfXuG++erl0Dice7GDMYVXkSC866C1p8GpITwVZGxko8MowKvrCrTjGMY s/+LqRFX2uw/WZNbISttHcaI89Hbn2SiHjpf1CWGHIYPP8zkpdBJOtc+6L8NlpDjFs0k 0w60bpdpzPRG9WF8rCEriai0+bfOCDHqBZxVGLFNzdURZVB9wyUATsMaWlcJitVFl+rS KHUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AqlpZOr139OB1unsh2SClg8WVN5Fa/eQjiAu6KjjAk4=; b=FJPdV7XW9mXh6CJgl+zbhje2mj+PVuAafb+wkpvdas9IQDVw4JalKPtWSZCvL1xcRI /v7zmQxdlr3Z8SWEKQYiVgnFdLt1LHbw1UdyBGvsLIeIOXSaSpOVsbQlFs9HgjK2nHhx V0vgIs8fueitn0VnZaN3000nZD5sgGIF3ZC5392f4HBs4w7K7E0l21o2FDzeGXghHaQK z6vndNm3KEinnFQ9xydkYtLNuZPkpJGvxUlZKMB52tP4/53+ly1wJ+iaSRRQ9I84UKNp xOH3510lS1iUwZEUePq8ES5a7hIVWmtsnSocsBr7kqSm66BrwMCTbq48L6P5q1mgzM51 Ui3A== X-Gm-Message-State: APjAAAXB2q8DpTlsqeIy8Xb9d2gKOERCjKK9+hW2x5ZC3rW01EZ/jQ8g G/dSG/NbgUvDp/T5XmAf1w/lZg== X-Google-Smtp-Source: APXvYqxKLrYoS7VLQ/tho/8d+NGGpjdXBRRw+Tiipe0mpIrvJQy21W0NWhdhNEamg48gWJitPb4eXA== X-Received: by 2002:a2e:9890:: with SMTP id b16mr25828149ljj.181.1571919058497; Thu, 24 Oct 2019 05:10:58 -0700 (PDT) Received: from mkPC.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id x17sm9961845lji.62.2019.10.24.05.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 05:10:57 -0700 (PDT) From: Michal Krawczyk To: Anatoly Burakov Cc: dev@dpdk.org, igorch@amazon.com, gtzalik@amazon.com, Michal Krawczyk , rahul.lakkireddy@chelsio.com, stable@dpdk.org Date: Thu, 24 Oct 2019 14:10:46 +0200 Message-Id: <20191024121046.30244-1-mk@semihalf.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH] vfio: fix BAR offset type for 32-bit app X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" When 32-bit application is built on 64-bit system it is possible that the offset of the resource is outside of the 32-bit value. The problem with the unsigned long is, that it is 32-bit and not 64-bit when using armhf compiler. Although the system is returning u64 value, we are losing it's value if it's higher than 32-bit in the conversion process. It can further cause mmap to fail due to offset being 0 or to map not intended memory region. To make it more portable, the uint64_t value is now being used for storing offset instead of unsigned long. The size of being 32-bit seems to be fine as the 32-bit application won't be able to access bigger memory and it is further converted to size_t anyway. But for better readability and to be consistent, it's type was changed to size_t as well. Fixes: 0205f873557c ("vfio: fix overflow of BAR region offset and size") Cc: rahul.lakkireddy@chelsio.com Cc: stable@dpdk.org Signed-off-by: Michal Krawczyk --- drivers/bus/pci/linux/pci_vfio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index faf2990a7..b8faa23f8 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -451,7 +451,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, int bar_index, int additional_flags) { struct memreg { - unsigned long offset, size; + uint64_t offset; + size_t size; } memreg[2] = {}; void *bar_addr; struct pci_msix_table *msix_table = &vfio_res->msix_table; @@ -504,7 +505,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, RTE_LOG(DEBUG, EAL, "Trying to map BAR%d that contains the MSI-X " "table. Trying offsets: " - "0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", bar_index, + "0x%04" PRIx64 ":0x%04zx, 0x%04" PRIx64 ":0x%04zx\n", + bar_index, memreg[0].offset, memreg[0].size, memreg[1].offset, memreg[1].size); } else { @@ -529,8 +531,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, if (map_addr != MAP_FAILED && memreg[1].offset && memreg[1].size) { void *second_addr = RTE_PTR_ADD(bar_addr, - memreg[1].offset - - (uintptr_t)bar->offset); + (uintptr_t)(memreg[1].offset - + bar->offset)); map_addr = pci_map_resource(second_addr, vfio_dev_fd, memreg[1].offset, -- 2.20.1