From: Eslam Khafagy <eslam.medhat1993@gmail.com>
To: anna-maria@linutronix.de, frederic@kernel.org,
tglx@linutronix.de, gorcunov@gmail.com
Cc: eslam.medhat1993@gmail.com, syzkaller-bugs@googlegroups.com,
linux-kernel@vger.kernel.org,
syzbot+9c47ad18f978d4394986@syzkaller.appspotmail.com
Subject: [PATCH v2] posix-timers: Fix potential memory leak in do_timer_create()
Date: Fri, 14 Nov 2025 14:27:39 +0200 [thread overview]
Message-ID: <20251114122739.994326-1-eslam.medhat1993@gmail.com> (raw)
potential memory leak may happen if user space pointer created_timer_id
is invallid. or the value it points to is invalid. the call will
prematurely return.
However it doesn't free the memory it allocates with
alloc_posix_timer(). This patch attempts to fix that by moving parameter
check before alloc_posix_timer().
Reported-by: syzbot+9c47ad18f978d4394986@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/69155df4.a70a0220.3124cb.0017.GAE@google.com/T/
Fixes: ec2d0c04624b3 ("posix-timers: Provide a mechanism to allocate a given timer ID")
Suggested-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Eslam Khafagy <eslam.medhat1993@gmail.com>
---
v2:
* Move parameters check before new timer allocation, no need for new
code.
v1: https://lore.kernel.org/all/20251114050621.875131-1-eslam.medhat1993@gmail.com/T/
---
kernel/time/posix-timers.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index aa3120104a51..56e17b625c72 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -475,12 +475,6 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
if (!kc->timer_create)
return -EOPNOTSUPP;
- new_timer = alloc_posix_timer();
- if (unlikely(!new_timer))
- return -EAGAIN;
-
- spin_lock_init(&new_timer->it_lock);
-
/* Special case for CRIU to restore timers with a given timer ID. */
if (unlikely(current->signal->timer_create_restore_ids)) {
if (copy_from_user(&req_id, created_timer_id, sizeof(req_id)))
@@ -490,6 +484,12 @@ static int do_timer_create(clockid_t which_clock, struct sigevent *event,
return -EINVAL;
}
+ new_timer = alloc_posix_timer();
+ if (unlikely(!new_timer))
+ return -EAGAIN;
+
+ spin_lock_init(&new_timer->it_lock);
+
/*
* Add the timer to the hash table. The timer is not yet valid
* after insertion, but has a unique ID allocated.
--
2.43.0
next reply other threads:[~2025-11-14 12:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 12:27 Eslam Khafagy [this message]
2025-11-14 13:52 ` [PATCH v2] posix-timers: Fix potential memory leak in do_timer_create() Frederic Weisbecker
2025-11-14 16:02 ` [tip: timers/urgent] posix-timers: Plug " tip-bot2 for Eslam Khafagy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114122739.994326-1-eslam.medhat1993@gmail.com \
--to=eslam.medhat1993@gmail.com \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=gorcunov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+9c47ad18f978d4394986@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.