git: bae776b8a5bc - main - shm: Fix a shm object refcount leak in shm_rename(SHM_RENAME_EXCHANGE)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 22 Nov 2026 17:41:30 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=bae776b8a5bc9cb0896a14c88bd2aa5458755304
commit bae776b8a5bc9cb0896a14c88bd2aa5458755304
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-22 15:14:20 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-22 17:41:07 +0000
shm: Fix a shm object refcount leak in shm_rename(SHM_RENAME_EXCHANGE)
With RENAME_EXCHANGE we acquire an extra ref on the destination object
so that shm_remove() doesn't free it. However, we failed to release
that ref if the rename fails.
Reported by: Laam Alif at Ibteda Digital Library
Fixes: 9afb12bab41f ("Add an shm_rename syscall")
Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61806
---
sys/kern/uipc_shm.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index c71f216fbe08..a5a95c25ad2d 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -1549,6 +1549,8 @@ kern_shm_rename(struct thread *td, const char *path_from_p,
*/
error = shm_remove(path_to, fnv_to, td->td_ucred);
if (error != 0 && error != ENOENT) {
+ if ((flags & SHM_RENAME_EXCHANGE) != 0 && fd_to != NULL)
+ shm_drop(fd_to);
shm_insert(path_from, fnv_from, fd_from);
shm_drop(fd_from);
/* Don't free path_from now, since the hash references it */