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 8A0D93009EF; Tue, 2 Sep 2025 13:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756819867; cv=none; b=PkN+fEHNsPgaevwsiB3VfQH3Y1K5Ts55u5CQqNs37OMdjlhdYSl4v9lj8pEdAWmoP0z+MBLL5H3ZI7kUwsSL/KMPScikpywmxGSZ4QbqlVM/tczKJmE7RAxDCBIK0xmya0ipvVujkpYuqSWfZSDEnPBp4vckkSB8i9HFUUUBPC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756819867; c=relaxed/simple; bh=p6I7KygETCE2yZBTayXyYizquha/Br0puwe5bWuXQfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AEDomUtUpQ4hLZOY3dzs6/04Gi1dBpc53rUe4IEw72qX9XhIJUIuL8z0bJsTkzl0oM5MDGyABDbCcI8csp3uKnCTFPjjV+0XYFw7Rd/Ur0LofG03thFGdS+DpxSf4LwGTlU+tXDCYRAoFwxhbGE739/ktjRpdLsTrB/5iNa2TF8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PDl95BKZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PDl95BKZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FF7EC4CEED; Tue, 2 Sep 2025 13:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756819867; bh=p6I7KygETCE2yZBTayXyYizquha/Br0puwe5bWuXQfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDl95BKZ8ybccIBGFNmQJ/0MMFwZDMC53Qk/jmqrNpX4uBk7zLpboC00ifL+rKzbc 8LP11wri/uSf3X/ep5hj7NzGhCOj9ZdMvMgvD10nbJgKBuHU90MlEbYKLT6xGKiAbH P+UDZwRfDelUdEpFjuF+le+38VKYSK3npA0ayEF0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Carpenter , Rob Clark , Sasha Levin Subject: [PATCH 6.12 20/95] drm/msm: Defer fd_install in SUBMIT ioctl Date: Tue, 2 Sep 2025 15:19:56 +0200 Message-ID: <20250902131940.388602075@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250902131939.601201881@linuxfoundation.org> References: <20250902131939.601201881@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rob Clark [ Upstream commit f22853435bbd1e9836d0dce7fd99c040b94c2bf1 ] Avoid fd_install() until there are no more potential error paths, to avoid put_unused_fd() after the fd is made visible to userspace. Fixes: 68dc6c2d5eec ("drm/msm: Fix submit error-path leaks") Reported-by: Dan Carpenter Signed-off-by: Rob Clark Patchwork: https://patchwork.freedesktop.org/patch/665363/ Signed-off-by: Sasha Levin --- drivers/gpu/drm/msm/msm_gem_submit.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 4b3a8ee8e278f..3eee6517541e3 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -879,12 +879,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, if (ret == 0 && args->flags & MSM_SUBMIT_FENCE_FD_OUT) { sync_file = sync_file_create(submit->user_fence); - if (!sync_file) { + if (!sync_file) ret = -ENOMEM; - } else { - fd_install(out_fence_fd, sync_file->file); - args->fence_fd = out_fence_fd; - } } if (ret) @@ -912,10 +908,14 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, out_unlock: mutex_unlock(&queue->lock); out_post_unlock: - if (ret && (out_fence_fd >= 0)) { - put_unused_fd(out_fence_fd); + if (ret) { + if (out_fence_fd >= 0) + put_unused_fd(out_fence_fd); if (sync_file) fput(sync_file->file); + } else if (sync_file) { + fd_install(out_fence_fd, sync_file->file); + args->fence_fd = out_fence_fd; } if (!IS_ERR_OR_NULL(submit)) { -- 2.50.1