Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4305877pxu; Tue, 1 Dec 2020 01:26:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWG9kbbcL27szFGyxNzAsESw+KFYAm45YWOY/gA3CaRVEqZypUK82cZ/NxfljEc5WU6kLP X-Received: by 2002:a17:907:2108:: with SMTP id qn8mr2084221ejb.127.1606814778367; Tue, 01 Dec 2020 01:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606814778; cv=none; d=google.com; s=arc-20160816; b=UCUo0BAqAW6NyohdL08TD5XkezyjbL1xYUBN5MLTy0M2BLGJwo9fGuaHSlytEt3kNF 1pKB4m4G71gkVFH1HZVOz0es+WUasnyram+G0nlU4fBcOp/gXGdbP+fWqIu1sKPMDunX K/NxQ/1uJ0oQanR3tMEwMX4ibybdBWO7wPHxs6LHD8F1PF9aXM7T8wOOz5h0hH6Jasw0 SdGHInhSZhFmg42spHO4L98O8RZ3nFBTqEOHFO2SonxAwBdDEuVdzAOcM8Wl/eW5BlQ/ FOgLUCCbk+Rsdp7BO7Hd27HOhMaoqQiwUHeXJfLpoLcyBqDS+Q0eZqtxLbIMs3XqJKMh IrFg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gESkklhsNgbHqhrlSrRuIUpSjJh5jOP3MrMESWDwT6w=; b=IO9d4AKgAUx0J45QR+BiTIT5amjcwb+xB6W63rT+44gs9sDaIBYSZFNqnb83SzIB25 K6hwA7r9a6UkTHnMxBVQMzEGWQI4alenUdeOCMeOx5nQaJ4TMnITsl63QxVj1Om7Z3sn ym996D0RGS7IKtF6TNO9k2MYBNR3AoYC/KL8XbsVSgKXNPgYMwa+j0sgzIMCnpcK1POY yHSO2FR8DrT235asLABQolgYalrLSIcOQHs5UuEuArPrx1fPm6GPmN0xrvcpQIoGe27l eC/9OzhchEVP0O6bSSKOjUHZkommADR3tDGGi9D3sSHBY4RAmZ44BRMu7sE83taWRSsV Jljg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="AEd8nbK/"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec18si559455ejb.679.2020.12.01.01.25.55; Tue, 01 Dec 2020 01:26:18 -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=@linuxfoundation.org header.s=korg header.b="AEd8nbK/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389457AbgLAJJ1 (ORCPT + 99 others); Tue, 1 Dec 2020 04:09:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:45440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389180AbgLAJIQ (ORCPT ); Tue, 1 Dec 2020 04:08:16 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3AA12206C1; Tue, 1 Dec 2020 09:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813655; bh=+vy4+kGziSSOrO+QJlSV33Cm2zl4V7PffibF/R1q+Jc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AEd8nbK/pPh6Xq0HSE71fdeItgITx7xNnzE50X4uazqZp5eu3vysAubecNqKMzDcn p4w+3zWkx2cCxcig+Oq0lPwyJ3CeFAEek2elI1uyOSqWW/7J9za+j1JENv15k93OZ7 gG8woln7e9mtvGGgaTq9SlTAekIrDTtTRu2DMSmA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Di Zhu , Shiraz Saleem , Jason Gunthorpe Subject: [PATCH 5.9 007/152] RDMA/i40iw: Address an mmap handler exploit in i40iw Date: Tue, 1 Dec 2020 09:52:02 +0100 Message-Id: <20201201084712.810630197@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shiraz Saleem commit 2ed381439e89fa6d1a0839ef45ccd45d99d8e915 upstream. i40iw_mmap manipulates the vma->vm_pgoff to differentiate a push page mmap vs a doorbell mmap, and uses it to compute the pfn in remap_pfn_range without any validation. This is vulnerable to an mmap exploit as described in: https://lore.kernel.org/r/20201119093523.7588-1-zhudi21@huawei.com The push feature is disabled in the driver currently and therefore no push mmaps are issued from user-space. The feature does not work as expected in the x722 product. Remove the push module parameter and all VMA attribute manipulations for this feature in i40iw_mmap. Update i40iw_mmap to only allow DB user mmapings at offset = 0. Check vm_pgoff for zero and if the mmaps are bound to a single page. Cc: Fixes: d37498417947 ("i40iw: add files for iwarp interface") Link: https://lore.kernel.org/r/20201125005616.1800-2-shiraz.saleem@intel.com Reported-by: Di Zhu Signed-off-by: Shiraz Saleem Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/i40iw/i40iw_main.c | 5 ---- drivers/infiniband/hw/i40iw/i40iw_verbs.c | 37 +++++------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) --- a/drivers/infiniband/hw/i40iw/i40iw_main.c +++ b/drivers/infiniband/hw/i40iw/i40iw_main.c @@ -54,10 +54,6 @@ #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ __stringify(DRV_VERSION_MINOR) "." __stringify(DRV_VERSION_BUILD) -static int push_mode; -module_param(push_mode, int, 0644); -MODULE_PARM_DESC(push_mode, "Low latency mode: 0=disabled (default), 1=enabled)"); - static int debug; module_param(debug, int, 0644); MODULE_PARM_DESC(debug, "debug flags: 0=disabled (default), 0x7fffffff=all"); @@ -1580,7 +1576,6 @@ static enum i40iw_status_code i40iw_setu if (status) goto exit; iwdev->obj_next = iwdev->obj_mem; - iwdev->push_mode = push_mode; init_waitqueue_head(&iwdev->vchnl_waitq); init_waitqueue_head(&dev->vf_reqs); --- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c +++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c @@ -167,39 +167,16 @@ static void i40iw_dealloc_ucontext(struc */ static int i40iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) { - struct i40iw_ucontext *ucontext; - u64 db_addr_offset, push_offset, pfn; + struct i40iw_ucontext *ucontext = to_ucontext(context); + u64 dbaddr; - ucontext = to_ucontext(context); - if (ucontext->iwdev->sc_dev.is_pf) { - db_addr_offset = I40IW_DB_ADDR_OFFSET; - push_offset = I40IW_PUSH_OFFSET; - if (vma->vm_pgoff) - vma->vm_pgoff += I40IW_PF_FIRST_PUSH_PAGE_INDEX - 1; - } else { - db_addr_offset = I40IW_VF_DB_ADDR_OFFSET; - push_offset = I40IW_VF_PUSH_OFFSET; - if (vma->vm_pgoff) - vma->vm_pgoff += I40IW_VF_FIRST_PUSH_PAGE_INDEX - 1; - } + if (vma->vm_pgoff || vma->vm_end - vma->vm_start != PAGE_SIZE) + return -EINVAL; - vma->vm_pgoff += db_addr_offset >> PAGE_SHIFT; + dbaddr = I40IW_DB_ADDR_OFFSET + pci_resource_start(ucontext->iwdev->ldev->pcidev, 0); - if (vma->vm_pgoff == (db_addr_offset >> PAGE_SHIFT)) { - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - } else { - if ((vma->vm_pgoff - (push_offset >> PAGE_SHIFT)) % 2) - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - else - vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); - } - - pfn = vma->vm_pgoff + - (pci_resource_start(ucontext->iwdev->ldev->pcidev, 0) >> - PAGE_SHIFT); - - return rdma_user_mmap_io(context, vma, pfn, PAGE_SIZE, - vma->vm_page_prot, NULL); + return rdma_user_mmap_io(context, vma, dbaddr >> PAGE_SHIFT, PAGE_SIZE, + pgprot_noncached(vma->vm_page_prot), NULL); } /**