From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EDC52F24 for ; Wed, 12 Apr 2023 08:54:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD5E9C433D2; Wed, 12 Apr 2023 08:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1681289653; bh=cATfKN99cZpHvzM06QWxClbFUtIhxUZr8cGzUjM7Geg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ruefjy4GwYoFS+SRqLsTuihF4g5Mur6nK4Hj3h9+zSK/O3rlKSeXgFQ64Y2n+vmmS Mp1640zTN9bsoMto6oextFBSwqfcbRbVbLBvkUkQt17B7X6p+0GYV4PHVH7ZtFFWxR ti4BiIP5z4ot3IRPyzcUclUp5ykc0BwDaUxMtHcI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Min Li , Andi Shyti , Umesh Nerlige Ramappa , Tvrtko Ursulin , Jani Nikula Subject: [PATCH 6.2 150/173] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl Date: Wed, 12 Apr 2023 10:34:36 +0200 Message-Id: <20230412082844.162389237@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412082838.125271466@linuxfoundation.org> References: <20230412082838.125271466@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Min Li commit dc30c011469165d57af9adac5baff7d767d20e5c upstream. Userspace can guess the id value and try to race oa_config object creation with config remove, resulting in a use-after-free if we dereference the object after unlocking the metrics_lock. For that reason, unlocking the metrics_lock must be done after we are done dereferencing the object. Signed-off-by: Min Li Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface") Cc: # v4.14+ Reviewed-by: Andi Shyti Reviewed-by: Umesh Nerlige Ramappa Signed-off-by: Tvrtko Ursulin Link: https://patchwork.freedesktop.org/patch/msgid/20230328093627.5067-1-lm0963hack@gmail.com [tursulin: Manually added stable tag.] (cherry picked from commit 49f6f6483b652108bcb73accd0204a464b922395) Signed-off-by: Jani Nikula Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/i915_perf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -4612,13 +4612,13 @@ int i915_perf_add_config_ioctl(struct dr err = oa_config->id; goto sysfs_err; } - - mutex_unlock(&perf->metrics_lock); + id = oa_config->id; drm_dbg(&perf->i915->drm, "Added config %s id=%i\n", oa_config->uuid, oa_config->id); + mutex_unlock(&perf->metrics_lock); - return oa_config->id; + return id; sysfs_err: mutex_unlock(&perf->metrics_lock);