Skip to content

Commit a260bd2

Browse files
minipli-ossbrauner
authored andcommitted
media: mc: fix potential use-after-free in media_request_alloc()
Commit 6f504cb ("media: convert media_request_alloc() to FD_PREPARE()") moved the call to fd_install() (now hidden in fd_publish()) before the snprintf(), making the later write to potentially already freed memory, as userland is free to call close() concurrently right after the call to fd_install() which may end up in the request_fops.release() handler freeing 'req'. Fixes: 6f504cb ("media: convert media_request_alloc() to FD_PREPARE()") Signed-off-by: Mathias Krause <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 8f0b4cc commit a260bd2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/media/mc/mc-request.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)
315315

316316
fd_prepare_file(fdf)->private_data = req;
317317

318-
*alloc_fd = fd_publish(fdf);
319-
320318
snprintf(req->debug_str, sizeof(req->debug_str), "%u:%d",
321-
atomic_inc_return(&mdev->request_id), *alloc_fd);
319+
atomic_inc_return(&mdev->request_id), fd_prepare_fd(fdf));
322320
dev_dbg(mdev->dev, "request: allocated %s\n", req->debug_str);
323321

322+
*alloc_fd = fd_publish(fdf);
323+
324324
return 0;
325325

326326
err_free_req:

0 commit comments

Comments
 (0)