Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658609pxa; Mon, 17 Aug 2020 15:45:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXoj6sCRF95dwBrhLTjgYJsAfbgevVu4fPxNz+8yu6VP1b2+Kew9+WjO51Cuf0wJff3Sdv X-Received: by 2002:a17:906:2801:: with SMTP id r1mr16755622ejc.17.1597704338678; Mon, 17 Aug 2020 15:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704338; cv=none; d=google.com; s=arc-20160816; b=O+KAsu885poOyoUoDlfLfvwdDXfVtiIhT17ZjbTPrui58TvckjHdeTdgIapcLmIv+J Yv3o5cbd8/GaKkewMt2usHcoj0WYCandSkvWnKDA3ifj3qu34mhsMWkh1QTcLD2WvTHS sNx85j9wcASDy5EDPXw0P0qOVnZNzyWecJwBY9yxfC5uMYhp0m3KKTQsNWtiGQWkV50V dMXykkhyP78eFrhtCkTg2drnI/7VUZNjONfJkiyV0IFstCKG88zSSuxb5SRdWn9acJEH wcC8p4ZU60dustFxRn46PQCx7NI1cg9s1s5G5dG/ObXHidSVuP4mO5GgD2vwsJJFGRuP v8nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ed1AeV5ik6GWx/wcFsktKitFZ+K7nX4ShNXeze0658A=; b=TWhQjWIjtPUkVAN0Vtj1QhcvoYCa7eIGjVekdXKZQ2Ip52EOs5qAMyoZTAQ8/wxBuN m/fEtGtgzxn2BnAenfY5HLC1OP2gmHOMsUCOWcaZV2H+X9r9c0hII0A8nin1MSVj470a Vys5ZGw8rwTuD6iIOLrmyRTD2vS5FReqX/EvNaL3KDYUe7nycLZFKUEsydFGOpqo0+oY RHh42sJH+cWTHKARWqoJ+LiSAczew+VpdRfvqNfgTPHr1squTxHkdHrJDj8EJXWmoR1I LIuh63tjZIuTk0W2tmbBnwVl8tICOdCVwJJERMskNfnFGEmZVBTuKTFsHoqULfWGvgZw QeSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1/B21mjs"; 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=fail (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 k22si11752833edx.491.2020.08.17.15.45.15; Mon, 17 Aug 2020 15:45:38 -0700 (PDT) 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=@kernel.org header.s=default header.b="1/B21mjs"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392138AbgHQTNK (ORCPT + 99 others); Mon, 17 Aug 2020 15:13:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:49008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730673AbgHQPk3 (ORCPT ); Mon, 17 Aug 2020 11:40:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1B5A020760; Mon, 17 Aug 2020 15:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678829; bh=tEM0h2Eeq0xk2+/KRcSElEjI+YzKG8o5jvvzr5kp4tU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1/B21mjsG7s7rqvzQJ7pDFidC8FWKn20dis7Bd+gxzx4YDZQBoJksEAKXW2de62VK Q1uheGmuKsEMDP+cEMeelQ6/BmKPawY4PR9TZxi4Ig4Ub7VGdRMrIF3qOrPPD1fVlG UvCY6k+zAC4xRt9BGh+F9rimxJssvk+BSR+qlcI4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksandr Andrushchenko , Juergen Gross Subject: [PATCH 5.8 455/464] xen/gntdev: Fix dmabuf import with non-zero sgt offset Date: Mon, 17 Aug 2020 17:16:48 +0200 Message-Id: <20200817143855.571323313@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksandr Andrushchenko commit 5fa4e6f1c2d8c9a4e47e1931b42893172d388f2b upstream. It is possible that the scatter-gather table during dmabuf import has non-zero offset of the data, but user-space doesn't expect that. Fix this by failing the import, so user-space doesn't access wrong data. Fixes: bf8dc55b1358 ("xen/gntdev: Implement dma-buf import functionality") Signed-off-by: Oleksandr Andrushchenko Acked-by: Juergen Gross Cc: Link: https://lore.kernel.org/r/20200813062113.11030-2-andr2000@gmail.com Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/xen/gntdev-dmabuf.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -613,6 +613,14 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_ goto fail_detach; } + /* Check that we have zero offset. */ + if (sgt->sgl->offset) { + ret = ERR_PTR(-EINVAL); + pr_debug("DMA buffer has %d bytes offset, user-space expects 0\n", + sgt->sgl->offset); + goto fail_unmap; + } + /* Check number of pages that imported buffer has. */ if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) { ret = ERR_PTR(-EINVAL);