From ebed52c790b6ff26d7d501022d483e09b1a943a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Mon, 26 Feb 2024 09:22:30 +0100 Subject: [PATCH] zink: Return early if the file descriptor could not have been duplicated/acquired MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not continue and call drmIoctl on an invalid file descriptor. Fix defect reported by Coverity Scan. Argument cannot be negative The negative argument will be interpreted as a very large unsigned value. CID: 1544377 Cc: mesa-stable Signed-off-by: Corentin Noël Part-of: (cherry picked from commit b6962bbfc803669e418e82ae5afe32046c0975c4) --- .pick_status.json | 2 +- src/gallium/drivers/zink/zink_screen.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index aabede9cd75..d7195f607e8 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1444,7 +1444,7 @@ "description": "zink: Return early if the file descriptor could not have been duplicated/acquired", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index bc014a44938..268f9b53c98 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -2277,7 +2277,7 @@ zink_screen_export_dmabuf_semaphore(struct zink_screen *screen, struct zink_reso .fd = -1, }; - int fd; + int fd = -1; if (res->obj->is_aux) { fd = os_dupfd_cloexec(res->obj->handle); } else { @@ -2288,6 +2288,11 @@ zink_screen_export_dmabuf_semaphore(struct zink_screen *screen, struct zink_reso VKSCR(GetMemoryFdKHR)(screen->dev, &fd_info, &fd); } + if (unlikely(fd < 0)) { + mesa_loge("MESA: Unable to get a valid memory fd"); + return VK_NULL_HANDLE; + } + int ret = drmIoctl(fd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &export); if (ret) { if (errno == ENOTTY || errno == EBADF || errno == ENOSYS) {