From patchwork Wed Aug 22 08:54:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 10572751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D078112E for ; Wed, 22 Aug 2018 08:54:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02A2A2B018 for ; Wed, 22 Aug 2018 08:54:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA6A32B03D; Wed, 22 Aug 2018 08:54:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A58A62B017 for ; Wed, 22 Aug 2018 08:54:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1203989CD5; Wed, 22 Aug 2018 08:54:21 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id ACD0889C61 for ; Wed, 22 Aug 2018 08:54:17 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id f38-v6so896319edd.8 for ; Wed, 22 Aug 2018 01:54:17 -0700 (PDT) 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=z4YaKXzJ/DownRwu4yv1jXZW8lTAGwrCMpU9ehgypc4=; b=p5z1KMwps5N+SOtO31/w1SzYTJHMZDlX/2+fOa8oI0PMLN1YMq2B5kW2lgsMezb2Wc D3lMe+SW0dONV4VvECzzNFL6gQVIoJGrL5sjySOjIu8V6y9Vecoz+K1xCkTyHduXkhBG fzc8tLFBglE6DvV4cE/dFE1PvzYWpn6SSj9KSlPcPVn+9NtZYE9bEjhXZZ2mVNKTmKL+ vRBV6nK9/wG4GUhWxMeHJyh6HuDghBhOKqwervQzPsCxM+Q0CmC+QpH9bgsPSgO2s2iO wr9qGbNxoRXQGpHLGorwLbG6PFf0S31NurmcKbCY8UrCx1o8Yewi2MSsL5Q224xyTQAf /F4A== X-Gm-Message-State: AOUpUlHhDbuLAEC4ucdFehX3A7krE5VLWBB9TMjieakVS0JfZLayTk1U rXq6kmun5V9ciR/vkZvMMLYHew== X-Google-Smtp-Source: AA+uWPzAaBN0YUaOkXa9n2AysLGFpumX2evUm4a/aTID+b2O4fqiFRFgv06TKiNogRx4zNQGMA/g0g== X-Received: by 2002:a50:b8c5:: with SMTP id l63-v6mr64588855ede.80.1534928056364; Wed, 22 Aug 2018 01:54:16 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-109.fiber7.init7.net. [212.51.149.109]) by smtp.gmail.com with ESMTPSA id r21-v6sm636418eds.7.2018.08.22.01.54.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Aug 2018 01:54:15 -0700 (PDT) From: Daniel Vetter To: DRI Development Date: Wed, 22 Aug 2018 10:54:04 +0200 Message-Id: <20180822085405.10787-3-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180822085405.10787-1-daniel.vetter@ffwll.ch> References: <20180822085405.10787-1-daniel.vetter@ffwll.ch> Subject: [Intel-gfx] [PATCH 3/4] fbdev: Add FBINFO_HIDE_SMEM_START flag X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, Kees Cook , Bartlomiej Zolnierkiewicz , Daniel Vetter , Intel Graphics Development , LKML , Daniel Vetter MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP DRM drivers really, really, really don't want random userspace to share buffer behind it's back, bypassing the dma-buf buffer sharing machanism. For that reason we've ruthlessly rejected any IOCTL exposing the physical address of any graphics buffer. Unfortunately fbdev comes with that built-in. We could just set smem_start to 0, but that means we'd have to hand-roll our own fb_mmap implementation. For good reasons many drivers do that, but smem_start/length is still super convenient. Hence instead just stop the leak in the ioctl, to keep fb mmap working as-is. A second patch will set this flag for all drm drivers. Cc: Bartlomiej Zolnierkiewicz Cc: Kees Cook Cc: Daniel Vetter Cc: linux-fbdev@vger.kernel.org Signed-off-by: Daniel Vetter Acked-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/core/fbmem.c | 4 ++++ include/linux/fb.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 609438d2465b..549d0f86fcf3 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1116,6 +1116,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, if (!lock_fb_info(info)) return -ENODEV; fix = info->fix; + if (info->flags & FBINFO_HIDE_SMEM_START) + fix.smem_start = 0; unlock_fb_info(info); ret = copy_to_user(argp, &fix, sizeof(fix)) ? -EFAULT : 0; @@ -1326,6 +1328,8 @@ static int fb_get_fscreeninfo(struct fb_info *info, unsigned int cmd, if (!lock_fb_info(info)) return -ENODEV; fix = info->fix; + if (info->flags & FBINFO_HIDE_SMEM_START) + fix.smem_start = 0; unlock_fb_info(info); return do_fscreeninfo_to_user(&fix, compat_ptr(arg)); } diff --git a/include/linux/fb.h b/include/linux/fb.h index fa8c6f9c9c3a..f42b09ca71f8 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -456,6 +456,13 @@ struct fb_tile_ops { * and host endianness. Drivers should not use this flag. */ #define FBINFO_BE_MATH 0x100000 +/* + * Hide smem_start in the FBIOGET_FSCREENINFO IOCTL. This is used by modern DRM + * drivers to stop userspace from trying to share buffers behind the kernel's + * back. Instead dma-buf based buffer sharing should be used. + */ +#define FBINFO_HIDE_SMEM_START 0x200000 + struct fb_info { atomic_t count;