From patchwork Mon May 13 23:58:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Lutomirski X-Patchwork-Id: 2563121 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 83F793FC5A for ; Tue, 14 May 2013 06:38:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A94CE6017 for ; Mon, 13 May 2013 23:38:31 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-da0-f41.google.com (mail-da0-f41.google.com [209.85.210.41]) by gabe.freedesktop.org (Postfix) with ESMTP id 17245E5FAC for ; Mon, 13 May 2013 16:59:25 -0700 (PDT) Received: by mail-da0-f41.google.com with SMTP id y19so3916200dan.28 for ; Mon, 13 May 2013 16:59:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=9/tnnrx0d9SXwj+qFVvKA5KvNkk0eT2Kmqqu71BcNys=; b=N6TV/mcz2Lh1Lg/wIy5yNFQUYMp6g6fLQLIwzlYrEmi6Xvicum65K6sKvtwk9eiEQs qQqPVt2jqZHXqdtPIkfwzb7sA0HWkTPmJShKMz0n6MVkhm44fPr9D1dgQOVWtmmkdaIH G5hqVorXPTSzwghWqVkKldCCqWlfbKJly7BIOIjaypGM75WmObl3/JPmtE7t6JqtohAa DEafR4JcfMBP+FHy/VB+lbWZST+ISFx/QSTBJhaL2fTC474QtBNl426JeAa2R+fiL45k T/drC8QIg1Od24EEsAkKVAyfLD4PRMsdWtTWEFcEfI9hpg7NwSUsPb60KE2t1w87iOT/ m/Nw== X-Received: by 10.68.129.10 with SMTP id ns10mr31604206pbb.13.1368489564890; Mon, 13 May 2013 16:59:24 -0700 (PDT) Received: from localhost (50-76-60-73-ip-static.hfc.comcastbusiness.net. [50.76.60.73]) by mx.google.com with ESMTPSA id xu10sm4416126pab.3.2013.05.13.16.59.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 13 May 2013 16:59:23 -0700 (PDT) From: Andy Lutomirski To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Subject: [PATCH v3 9/9] drm: Don't leak phys_wc "handles" to userspace Date: Mon, 13 May 2013 16:58:48 -0700 Message-Id: <49cb9bfb3edeaf86ec659f1722893ddbd31075c4.1368485053.git.luto@amacapital.net> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQmq8Gj/OKgUBBAKQT1hYgrBSnxxQVycTNZ7tZ2eF1nT40vVj0zTWirOoUJ65W0sEdt56D+G X-Mailman-Approved-At: Mon, 13 May 2013 23:16:58 -0700 Cc: Daniel Vetter , Andy Lutomirski X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org I didn't fix this in the earlier patch -- it would have broken the build due to the now-deleted garbage in drm_os_linux.h. Reviewed-by: Daniel Vetter Signed-off-by: Andy Lutomirski --- drivers/gpu/drm/drm_bufs.c | 9 +++++++++ drivers/gpu/drm/drm_ioctl.c | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c index 0190fce..5a4dbb4 100644 --- a/drivers/gpu/drm/drm_bufs.c +++ b/drivers/gpu/drm/drm_bufs.c @@ -414,6 +414,15 @@ int drm_addmap_ioctl(struct drm_device *dev, void *data, /* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */ map->handle = (void *)(unsigned long)maplist->user_token; + + /* + * It appears that there are no users of this value whatsoever -- + * drmAddMap just discards it. Let's not encourage its use. + * (Keeping drm_addmap_core's returned mtrr value would be wrong -- + * it's not a real mtrr index anymore.) + */ + map->mtrr = -1; + return 0; } diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index e77bd8b..ffd7a7b 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -38,6 +38,9 @@ #include #include +#ifdef CONFIG_X86 +#include +#endif /** * Get the bus id. @@ -181,7 +184,17 @@ int drm_getmap(struct drm_device *dev, void *data, map->type = r_list->map->type; map->flags = r_list->map->flags; map->handle = (void *)(unsigned long) r_list->user_token; - map->mtrr = r_list->map->mtrr; + +#ifdef CONFIG_X86 + /* + * There appears to be exactly one user of the mtrr index: dritest. + * It's easy enough to keep it working on non-PAT systems. + */ + map->mtrr = phys_wc_to_mtrr_index(r_list->map->mtrr); +#else + map->mtrr = -1; +#endif + mutex_unlock(&dev->struct_mutex); return 0;