Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1087697pxa; Wed, 12 Aug 2020 23:25:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXCeFtWU5Cs8X9g/OkdHafoS5ecftSUdijQrwr0Ig2nujjqsIARK4f1uZukXtfQkUvrFb0 X-Received: by 2002:a17:906:4a07:: with SMTP id w7mr3221391eju.269.1597299927117; Wed, 12 Aug 2020 23:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597299927; cv=none; d=google.com; s=arc-20160816; b=Fo/+Lu+IzhseyCDve1FkZ7gML9nR8eKCxqE9GakaPizOZMFUtAoE7opXYvDR67aiIr 7sQionNH3VBLed2zUZxriEMZKctFPP1kTgwa2ibDZPoCnPlb17vr2x5YrqHww5h4IuC5 vhBA5YveJaYoRd7UUmaZLzwDxbgiovsYMPpjg41VkMoEfUtZ3D2XB2ziPovaTgxuqoF2 Gur8l/pWcKvLfXODw5nmJPJuO46agzB+duftu5co1AEtyGTxVNrXtbFWX2VHzyn3Moh7 X5lNaX5Ih8KwHl8sFYQDRtcHxdKhxs1FejTuNcU2vb3mb09c/IHY0I/cFqU2Cf92dsIN amHA== 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=C9rQWo6syT3cF37ubQbW7IMBpmbXyJ1+Ny4Hmm3+D9g=; b=ZVyGgbXDuYtXZ+5LhGRstYf9dDC47jsMIs90fTcl9KfhQ/AMa1DCXD4dPvXy7CxeXO ZGbrdniUuIuqGR1061QMN/WkPHVhnhUshhyUzVcWxWmbCSxUTK+EgCwn7lqnDf9Q21NQ toV7jSJf5Tlp/yNDy0mp94gO1N2nykBqpuCL9O96p1V2FCR9qN88kKd5gmuN0nUeWJOO 8Tz+H7DH9mDB4VIli/S10jdkfSZuyRIczdGpqEm4wckqNwALLuiLcFvI4qXhQLHj0Do8 u3g7A1MJqU5+Jtk1kqrmUKxlCzkKQthuO2z4o79L+komWuVwz6TbRJ0GRCOiOwXLKUKK Isew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IdrdS+jh; 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 s16si2860062ejm.36.2020.08.12.23.25.02; Wed, 12 Aug 2020 23:25:27 -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=IdrdS+jh; 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 S1726253AbgHMGVT (ORCPT + 99 others); Thu, 13 Aug 2020 02:21:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgHMGVS (ORCPT ); Thu, 13 Aug 2020 02:21:18 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70CBBC061757; Wed, 12 Aug 2020 23:21:18 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id t23so4927940ljc.3; Wed, 12 Aug 2020 23:21:18 -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=C9rQWo6syT3cF37ubQbW7IMBpmbXyJ1+Ny4Hmm3+D9g=; b=IdrdS+jhl4Oa2APlUEh5hsmWHLnjlvcEeLbNwd/9wCAajQpSXHE0zHJiFdgcdiK26J WFO1pugdzNj04qdFOagFuIp86Sv+478MpJWML1/H1kFhojn/ZOWrcGdudLoSBrsxQlzR EcAC59A3E3nwwwp9ENtv3ctQM7YTyIq69C2d3wIoR6R4PQMfsF7LGC2lLBut5bKO3Zu/ 4WoL1gVFon0Xdx/deulTB/UQkk/ztsecEql/JO68s3NP1mEPDzfT/LNeQz9VllyIv0PT 9Tj8AssK9SOO8AwcvjXm8WGOQKyaIJFbORNO4CgMimKGYH01+Ebjmr55PZr3TuSs8iQd jupg== 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=C9rQWo6syT3cF37ubQbW7IMBpmbXyJ1+Ny4Hmm3+D9g=; b=WtgnzLvqqWqZnrjILqTcDglSxU4ppYZL3X68FCFQS7LwVAAT5EBRwtxZMTTZdk1M9K 9lAKTF1KzSxl5N1RUuFQqPn5eGkpcYjqoXcPqjLfQYLvkkOxOaV6aoD1QoDXnLe4Gyf+ Q85Ukd2+3sJGRpADmWPXL4wi05grGDQydKsbWsTfYi9CK4gqcfs5NTnYnW5qAc7LgTCq mGsvL+vEPYPYO37/8uAtA5fHH7q+hUPlcK8fqYTkEB8CHgP3yRKZeY3y9pm8HTKpfhVv cvRvE1hJAbVI/bAvZJKp1SaL014lvkHUv6OT4aJyGX9tZ1mUm3P6mm8cs1WEbtjFnATT 5lOg== X-Gm-Message-State: AOAM530WIYNmiPw6HP/MhJtwLvprnEAl2bCG6FHdEY5j69MN1VGhVo7q jEuwQYKYZHrYHPtbMVIO+S0= X-Received: by 2002:a2e:8098:: with SMTP id i24mr1308903ljg.50.1597299676613; Wed, 12 Aug 2020 23:21:16 -0700 (PDT) Received: from a2klaptop.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id f14sm964060lfd.2.2020.08.12.23.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 23:21:16 -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 , stable@vger.kernel.org Subject: [PATCH v2 1/5] xen/gntdev: Fix dmabuf import with non-zero sgt offset Date: Thu, 13 Aug 2020 09:21:09 +0300 Message-Id: <20200813062113.11030-2-andr2000@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200813062113.11030-1-andr2000@gmail.com> References: <20200813062113.11030-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: bf8dc55b1358 ("xen/gntdev: Implement dma-buf import functionality") Signed-off-by: Oleksandr Andrushchenko Acked-by: Juergen Gross Cc: --- 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