Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp53716ybg; Mon, 8 Jun 2020 16:14:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpwD8MGB1LmeK2dsB+q45tiAmSSHWJYMEPKzIEW/XgreJO8fteT216GRly2XVWGCgPPXZ8 X-Received: by 2002:a17:907:7294:: with SMTP id dt20mr22465355ejc.355.1591658047827; Mon, 08 Jun 2020 16:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591658047; cv=none; d=google.com; s=arc-20160816; b=b3s3kvDQmbjNlO3jxhARMMlEMwrNSkoC8X1b3guebnH4K9ntoaWbZIVsJAO8iH9qQ7 7xqt2HRnymovNKufAnKVzeRGZZKAFo591UFkLk19YAOLijmf4zpVFuT6E5pm1i4Q6W7H KZ4/EPzmnRJxYOR7QugwobA0BXBS9AfjfRfHMOs5BzA+NvlBeA/zCm5y9iWnguBvTwsg gMVRmkQpXP0+KTLGxO3YgKV9g/z2Ni52IN1jaJCcXx8EJxyW0+thP/F30+C1o6PYUPXG MW32yZqwl8Q3P/Ti6uh5ZuzL7k3ihKv5H9ZzQJDgylxYHobKvzG9d+KBV9oywrX5SfBq gQ6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mp+iqo6ti4lZYWcMger7Yx9OH93buSLfcWmiIH4N3ZM=; b=uSK+zqDQDRa5gKWqV2TMBXSAV3ImOXr5d+s3mQJuH4YHB7NJMHCpZ4eDfrodZ6Dxw7 Z2adLYBC7iKjFCruyKiP9DiKvfqMf9bHA3fatZZejcaqR/rqnc3H5+rhETNH+wR316AF bGUkxgpi9EHOidwKpJvXuNnNZmo1G58G5j8V/nsUTb7QfzIX+4AP5Ij/nETPWfpg9IjK 4t42wY+v9VoWndaHsczt3T1v+2UW0oVL0G5OAGG53L1KBNxfFEy5KN1mQTfCqsqYcr9q 9S8RLlqeFHkchuVWskTUJVlguqXn/a5+u2NBR1WLOv8MvN0Y6d5YsfgZFoDkm+94wSsh vUHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eli+0q8+; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc23si10385458edb.115.2020.06.08.16.13.44; Mon, 08 Jun 2020 16:14:07 -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=@kernel.org header.s=default header.b=Eli+0q8+; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728885AbgFHXLS (ORCPT + 99 others); Mon, 8 Jun 2020 19:11:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:55632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728516AbgFHXJt (ORCPT ); Mon, 8 Jun 2020 19:09:49 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B89B020B80; Mon, 8 Jun 2020 23:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657788; bh=kntZHaADtqmXEkROzUlLhxaIDHYMV/qGZ2kMk2G8Nlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eli+0q8+23VI6xuqdkBZEVpE/REEAaazVpMc7EqhQ5oI98Y8jlA4l71ACC46kRyW2 uTSlTiRkgJTrC/h9OeQMg2q3WxbfTeJoAaKb3ulQ8LZDJSot0NO8Hyqa6DublVQDig cwyyLWQE+ueArq82nz2Ept/0QKDo+ZgweM6XjpLU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ezequiel Garcia , syzbot+e3372a2afe1e7ef04bc7@syzkaller.appspotmail.com, Rodrigo Siqueira , Rodrigo Siqueira , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.7 169/274] drm/vkms: Hold gem object while still in-use Date: Mon, 8 Jun 2020 19:04:22 -0400 Message-Id: <20200608230607.3361041-169-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ezequiel Garcia [ Upstream commit 0ea2ea42b31abc1141f2fd3911f952a97d401fcb ] We need to keep the reference to the drm_gem_object until the last access by vkms_dumb_create. Therefore, the put the object after it is used. This fixes a use-after-free issue reported by syzbot. While here, change vkms_gem_create() symbol to static. Reported-and-tested-by: syzbot+e3372a2afe1e7ef04bc7@syzkaller.appspotmail.com Signed-off-by: Ezequiel Garcia Reviewed-by: Rodrigo Siqueira Signed-off-by: Rodrigo Siqueira Link: https://patchwork.freedesktop.org/patch/msgid/20200427214405.13069-1-ezequiel@collabora.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/vkms/vkms_drv.h | 5 ----- drivers/gpu/drm/vkms/vkms_gem.c | 11 ++++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index eda04ffba7b1..f4036bb0b9a8 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -117,11 +117,6 @@ struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev, enum drm_plane_type type, int index); /* Gem stuff */ -struct drm_gem_object *vkms_gem_create(struct drm_device *dev, - struct drm_file *file, - u32 *handle, - u64 size); - vm_fault_t vkms_gem_fault(struct vm_fault *vmf); int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, diff --git a/drivers/gpu/drm/vkms/vkms_gem.c b/drivers/gpu/drm/vkms/vkms_gem.c index 2e01186fb943..c541fec57566 100644 --- a/drivers/gpu/drm/vkms/vkms_gem.c +++ b/drivers/gpu/drm/vkms/vkms_gem.c @@ -97,10 +97,10 @@ vm_fault_t vkms_gem_fault(struct vm_fault *vmf) return ret; } -struct drm_gem_object *vkms_gem_create(struct drm_device *dev, - struct drm_file *file, - u32 *handle, - u64 size) +static struct drm_gem_object *vkms_gem_create(struct drm_device *dev, + struct drm_file *file, + u32 *handle, + u64 size) { struct vkms_gem_object *obj; int ret; @@ -113,7 +113,6 @@ struct drm_gem_object *vkms_gem_create(struct drm_device *dev, return ERR_CAST(obj); ret = drm_gem_handle_create(file, &obj->gem, handle); - drm_gem_object_put_unlocked(&obj->gem); if (ret) return ERR_PTR(ret); @@ -142,6 +141,8 @@ int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, args->size = gem_obj->size; args->pitch = pitch; + drm_gem_object_put_unlocked(gem_obj); + DRM_DEBUG_DRIVER("Created object of size %lld\n", size); return 0; -- 2.25.1