Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp27359pxa; Fri, 31 Jul 2020 05:51:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq6FNiGlv6++foKvaxZvE+bR13SmbGeGPUd2U2DABBXqBw4pwbKjTKtzqaiXhhWH06h+bS X-Received: by 2002:a17:906:d786:: with SMTP id pj6mr3907761ejb.261.1596199915512; Fri, 31 Jul 2020 05:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596199915; cv=none; d=google.com; s=arc-20160816; b=MSD9o9D2mSwJGnGtxVa08aaahGJMNzjZWJRlRUnOO2SL+TqD0JkofSWeOQnuHua3RF 6Eu0s7i0LCBVLmSbf9K8dwjSRImVYm/m46DWr6wtdaPRYlcLyVzU1rsORH/xgypq4tjP 81ERRj46td8IbdbJLFWLOeNpYwocoAuIG5nesUvJDhkRJU4kC+pXW0S41n5boaG4VTBM zydlaXkorR1DBYGJMZV31IkT6ZGQ9gSTvJGg8LG6A9bEWYR1YOqeDZyweBn4jz1KE5n2 6A7+QrB9ykyPB5v25YiFcenrG/7GxGWdZZ+qKFMdhj12sdrX6GrFA5ONwyFTtgiM4kio XRkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=P8zgpF044pgTW1uK5Q8AXrv/7bel3rEWKcAtjS7WDeo=; b=nDRGxtNFoQDBSqsamG8mhdgNaqcFm4jicHy4VJau356QXMyqP1lRrZDHkAOB7u59uf hC8YxPXLW9y5PMET5gHMUbO7K5FQoj4oaJElrhjDZd51Od4sNVeZCUS7RLO2WEFMpfPt H7ladQ3CYtHxZ9utcrG0PacMLh2KCxZr9+O5Ujkku6Co0ITQoHGk46qnqcNG/wml9YP4 08BNy1kdyNiQS8rJRiHbH2Uj9eSc4C9CmY7YFKE/aCw76GWn2XqjQW4ou5K5z0+hpYmQ l+kiOdHC1w+549kkY0iaOFAhd94hY5OQhbWbZ05po5l9B4zneEsa2ZLPR4Ro7jagFxEy JXhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WgUyGPBf; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v12si4735805ejc.292.2020.07.31.05.51.33; Fri, 31 Jul 2020 05:51:55 -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=@gmail.com header.s=20161025 header.b=WgUyGPBf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730435AbgGaMvT (ORCPT + 99 others); Fri, 31 Jul 2020 08:51:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbgGaMvP (ORCPT ); Fri, 31 Jul 2020 08:51:15 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C177C061574 for ; Fri, 31 Jul 2020 05:51:15 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id b30so16780139lfj.12 for ; Fri, 31 Jul 2020 05:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P8zgpF044pgTW1uK5Q8AXrv/7bel3rEWKcAtjS7WDeo=; b=WgUyGPBfwmJ9bTlFZ1iykzmaC+/eyxO2mETTCyh0EN7DEuu6cfihmRQOfjN0UX17KJ 1XK/aClkr4jouIfR2Uq33SHtLP56E4y8DgZ87NMJDRnE/5HMKnL0qQRmTaRqEurFsoxI D/R3+eHgdIAl42+OdJRKAhPJheLy6IATe2ljDZKS9Ir/9TnHfgeT9ND6Q078g/e5NeAs I2W7ZBR4JYFb7XWCyVQlSdl0Ydv93Ytn/B8SI+DrRwYKxIF7FMjE6FYcroqJuyHyrA1S e7Z785IPUZkU0urptiMhDbgonuN0KgLkpcNKcT+5pvixgh0YZDlTJ29FOCn97utl+t8+ hahQ== 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:in-reply-to :references; bh=P8zgpF044pgTW1uK5Q8AXrv/7bel3rEWKcAtjS7WDeo=; b=H894F2bk6Yn3Pq7QQU/bYRpdyu80j9P+EnobJTaoV+HY+HCG9fudD4gHUoXVBqs+OR DQMFUK54ZoUMQ4bPsiKIdjn/rYoNi3l5K1fA3RqCXgyN05XdGPRtS7oIs1/ri7+TH2T/ C0q60GfgOlVSq5Ue/3NU2qSZ1DrqPXVxzWoLzFan7QzBEKXZIqn2Ya6qasrm+yvrGH12 MnX8M1qomR/o1jnaVSggDQTGYwMZRJ1mrLV6Sti/neVtp7RePzFuts/M8VmU6+DGoPxz lNYYIkpencfCoJSy7c6CT3e30FudLhZWW8SwU1jZaI/Ig4VW6v5IR6YPooKW0IolvVej 8rhQ== X-Gm-Message-State: AOAM533x82gWZrORc9cKdtVqlykSfBjZr+7LUPoK06Es1Kf9HY0WnHve IIaaR0V8kOkJF/b4rlt1S4E= X-Received: by 2002:ac2:5683:: with SMTP id 3mr1948307lfr.69.1596199873919; Fri, 31 Jul 2020 05:51:13 -0700 (PDT) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id s2sm1923362lfs.4.2020.07.31.05.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:51:13 -0700 (PDT) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, boris.ostrovsky@oracle.com, jgross@suse.com, airlied@linux.ie, daniel@ffwll.ch Cc: sstabellini@kernel.org, dan.carpenter@oracle.com, intel-gfx@lists.freedesktop.org, Oleksandr Andrushchenko Subject: [PATCH 1/6] xen/gntdev: Fix dmabuf import with non-zero sgt offset Date: Fri, 31 Jul 2020 15:51:04 +0300 Message-Id: <20200731125109.18666-2-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200731125109.18666-1-andr2000@gmail.com> References: <20200731125109.18666-1-andr2000@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksandr Andrushchenko 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: 37ccb44d0b00 ("xen/gntdev: Implement dma-buf import functionality") Signed-off-by: Oleksandr Andrushchenko --- drivers/xen/gntdev-dmabuf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c index 75d3bb948bf3..b1b6eebafd5d 100644 --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -613,6 +613,14 @@ dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev, 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); -- 2.17.1