Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3518482pxf; Mon, 15 Mar 2021 11:19:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRXZ8f/CC6Jo1udZWBFsSsGFLWmCKZ00GFBXejV91C1toJoxuETM80/jwo83y+RvjP5PYA X-Received: by 2002:aa7:c0c7:: with SMTP id j7mr31400114edp.298.1615832397829; Mon, 15 Mar 2021 11:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832397; cv=none; d=google.com; s=arc-20160816; b=d/2DuiK9HV+5noDxTUc1Praj0fI8v9SrqWuFX1ECZ0IaD/ixToymJlLNmLarFqMWG0 4rJHPBin+Ckkk1ngPIsqXZTh43jqukwlbXmKyEPixsSmVmkD+8yqZylkoYCNp7wZaVSi BpMwtH4DWioH9abCAikTvbkerZXSJQB7O2ti8Or2/P6astytXxw2sXF6HdVb7/aSEBvN sKQ3xFLH4HtMZgBShv2tmYoYj4qUtwKhKeRWq5n8lznoSYO4XBxiZMmH9+vskr1r0CDD KyCVuxbcPA8S86RLbgArlEP8SMrATKkuflIHDhzq7dIOWnh9vhzYpHx/FyjYa4geyq4I LOBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Mi0iIGvaILvIL/j9w+3S45z+2sR0iRAdDR1evzJfYi8=; b=PRMj+YYGkYU7G5JV/FrdPZZFS81UTK6FZ1yhLz0a+EuNXfVJ+fO8Q51w4LHnW2+/58 FTss66JTh//G1ik+IxUAppxVDUfWewfQFgGSG7nH33fGLXSM7UNZC3aOb3xmFBX1TlGG 6InTpBcYfeFrESs6KzfuMRAprVc7py8M4OaJgcdv27SjxJG+BXrU41aTeeyN9ssmiiUZ +jPfJIj3lKlUXQqo9g5QeC6vRIGVcZ46FmkGwLlQKIbB+WQJ73XSy2kx87m1zVhMHVg0 BFfcTrmEX6cJN/jBQoJY2bQoyqWjej/8IhAbI/TAxhpR00+ncaLMkqOG83zInpV2P6hC NW4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aZPPZqrT; 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=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 d21si11188223ejm.343.2021.03.15.11.19.35; Mon, 15 Mar 2021 11:19:57 -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=@linuxfoundation.org header.s=korg header.b=aZPPZqrT; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237036AbhCOORL (ORCPT + 99 others); Mon, 15 Mar 2021 10:17:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:37670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232693AbhCON7b (ORCPT ); Mon, 15 Mar 2021 09:59:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 057E564F44; Mon, 15 Mar 2021 13:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816749; bh=3tyspyjzAbsdhvZijLJLGF2xWOnIl0YKzRxdLyY00iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aZPPZqrTSdGirJQkMxyuKiPmO26DZ1Wldz+ZtxYqNYAoy5JBmMW6zI1moqxg9MCnV 2KqcpRKOkyE0ZoQnJ9+nlsZWBNMo6WUaulCi9Cla2rOcZKWVgIDEvNjbZ7fy8oXrd5 W2h6iFj1TncrNrnxg7kA/40o9DxmbztpUqQSjmdI= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Neil Roberts , Steven Price , Maarten Lankhorst Subject: [PATCH 5.10 092/290] drm/shmem-helper: Check for purged buffers in fault handler Date: Mon, 15 Mar 2021 14:53:05 +0100 Message-Id: <20210315135545.025811771@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Neil Roberts commit d611b4a0907cece060699f2fd347c492451cd2aa upstream. When a buffer is madvised as not needed and then purged, any attempts to access the buffer from user-space should cause a bus fault. This patch adds a check for that. Cc: stable@vger.kernel.org Fixes: 17acb9f35ed7 ("drm/shmem: Add madvise state and purge helpers") Signed-off-by: Neil Roberts Reviewed-by: Steven Price Signed-off-by: Steven Price Link: https://patchwork.freedesktop.org/patch/msgid/20210223155125.199577-2-nroberts@igalia.com Signed-off-by: Maarten Lankhorst Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_gem_shmem_helper.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -534,14 +534,24 @@ static vm_fault_t drm_gem_shmem_fault(st struct drm_gem_object *obj = vma->vm_private_data; struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); loff_t num_pages = obj->size >> PAGE_SHIFT; + vm_fault_t ret; struct page *page; - if (vmf->pgoff >= num_pages || WARN_ON_ONCE(!shmem->pages)) - return VM_FAULT_SIGBUS; + mutex_lock(&shmem->pages_lock); - page = shmem->pages[vmf->pgoff]; + if (vmf->pgoff >= num_pages || + WARN_ON_ONCE(!shmem->pages) || + shmem->madv < 0) { + ret = VM_FAULT_SIGBUS; + } else { + page = shmem->pages[vmf->pgoff]; - return vmf_insert_page(vma, vmf->address, page); + ret = vmf_insert_page(vma, vmf->address, page); + } + + mutex_unlock(&shmem->pages_lock); + + return ret; } static void drm_gem_shmem_vm_open(struct vm_area_struct *vma)