From nobody Sun Feb 8 13:48:21 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3483014B950 for ; Fri, 14 Nov 2025 12:27:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763123266; cv=none; b=Rf+YpqsfI1DaDXDP/5cr1tL2dmuwc/W2UiH0l934zgnSqb3mPiMXeH+BFscgBaEWVyf2bxIWvUcyd+9IpVngB4/FkiCT/3uGEQJJrfHBSz5+Ro2uSX50grDfdjTPjSGSxTn5hXIMs9ogUhqnfhFKuMFLA6qg3cgdKNbkicXpvqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763123266; c=relaxed/simple; bh=3qSBkn75oqaTChEqs3dJW9jITLKSCy3c/GXwZkrIxBw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YaaWYq+3e8xyOpYXXutvTCuPBVLYAxdf7g5bXd3KS5zAGg6ZxZ5GDVJPxz36AUXb0hQ/iylIfzCWJ7w2SgijZt7ML+35oP6WmVTg3qbJqLuUh84TjMl161px7bILkoHAo2qTLc8owMzBgFoSG0Km3H+eIeKRgf6VeaLHqu/fX7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LAsb8C26; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LAsb8C26" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-47790b080e4so2739885e9.3 for ; Fri, 14 Nov 2025 04:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763123263; x=1763728063; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RXl1VAMnvevXUxwcL423m9iAC+LorYpY6CoM/SwYv0A=; b=LAsb8C26C3YRfhTOPaF8xayx+i/bg4T7Oa9eH6SyG3OzPxZT2s1sf0h6l+wfaiKC1m YLlqONJOJ4jP8K6Q2w5YaMskvgZKXnutQ595KMl0gdfN2VhV9NcSWAk/e9R2C+4FrEeg 8ir6o8mrwQhuKkCUf8NEtaYUFT971HBb44cg327Sr1gfKtk2AZaXTB+PLqJqmmaRKGvf eIfTQRT5iNMU6mH5/Jjq0LvuMkBvVesevZ1Nd00xJJIDva81QH/mSuOlMWsIEbNqOvAM i65qfvyCRwRww5CFqrh5i1bQ2f3AKaGZ1LPVD6p/M/DlpBavotjKkeGMWscRzLa6E5+N hgjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763123263; x=1763728063; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RXl1VAMnvevXUxwcL423m9iAC+LorYpY6CoM/SwYv0A=; b=V/WcAp3kLxaLpaocpkfmXIhNvTYltrPWpQBAuiILXidEzqin2aByTc+cXhmBoSwyLO xGLYPWIdIdrR//Vvvh/WHggbXrOpxwM1Zaj67VUqt+tlYfawgDbITiwyILKNkbpgT+3c Ru6Tt4mU1HUllkkrlMAgKNRo2e7cUXMXzJI56Jm/yys7p0+beQtTd9FaC+JNibEmDpWm iZWeUPEPHoloZkdSxD5LhzXvOUVHjZrwJBQ3pv03QykVP7kfr7vBHzHmT7HsXzdp397J cAYeiwPSxppY0okbWR+7KMGtVexYTFT952ID3Te2H8NZo2cCHqqNWjB/1ArFcUzLTugV ffJQ== X-Forwarded-Encrypted: i=1; AJvYcCXysfhK7wETbUiwsyL0iKqEy5By0IT6EtGkJ+gyj/55r1ijZr9Af0swwQzVgjNeAraB3ImhFkyQO9roFRM=@vger.kernel.org X-Gm-Message-State: AOJu0YxFsC0yDWHxesSGGZlblX2B0DWqOt+lcP70UROyhQDyf9fQ9uyV daZUrlio1mvsdl8E72Wu/eRHNd5d6ppvI5VHoTGNY5wLS09CYgXjjMLl X-Gm-Gg: ASbGnctdc9ZNmfK6/vHXWS+jZ6bOOduV3TPOFsINvTh1hSJTTpJdVU4W7UQRbJaRzjS gPNUdqmRZKrBxXYxNG9nd3t8+APnclGCPzb69sSZNTBibpzbSm3NByvrGejmbzZTXQ/f23IH2LR vpCeRX3SR9pSxFstIbmlv9Pg7XYR1VC9wLJusuTZrrZtEE2QPwyZ8zzVQONmt+1lHX9AJmvo4Tc GIbYcR5B4Tw0FagI1SYgXtbsiw9789NHItmhBuxMii+60sAGlM/B8+Wnc/OU6qCXX6UC578az2J 4fsPYG4+9652hDD9/mjE69k7oXQpzrr9pV+89Lq4I30Ijx341DlwHB7Ed5ZFE9UglERARZRSKfm VlIIDsWFqns9Rmt3VkE7JtmJUfpxVrJxVu7uQ5WOyV9id4KIonxGuC2ZYyjZDVzJy1Q69S88OaG FTfBW3c/aMpC4g8quywg== X-Google-Smtp-Source: AGHT+IGj2iNxQFSWzci+XhRyE/mq5TBeOOu+M9rwYnmqZxX09BpL97y8NeMj0GsDqjGUbmsrlCNOjQ== X-Received: by 2002:a05:600c:c177:b0:471:13dd:baef with SMTP id 5b1f17b1804b1-4778fea3048mr22884585e9.26.1763123263432; Fri, 14 Nov 2025 04:27:43 -0800 (PST) Received: from ekhafagy-ROG-Strix.. ([197.46.78.60]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47787daab3fsm164927235e9.0.2025.11.14.04.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 04:27:43 -0800 (PST) From: Eslam Khafagy 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 Message-ID: <20251114122739.994326-1-eslam.medhat1993@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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@googl= e.com/T/ Fixes: ec2d0c04624b3 ("posix-timers: Provide a mechanism to allocate a give= n timer ID") Suggested-by: Cyrill Gorcunov Signed-off-by: Eslam Khafagy Reviewed-by: Frederic Weisbecker --- v2: * Move parameters check before new timer allocation, no need for new code. v1: https://lore.kernel.org/all/20251114050621.875131-1-eslam.medhat1993@gm= ail.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, stru= ct sigevent *event, if (!kc->timer_create) return -EOPNOTSUPP; =20 - new_timer =3D 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, stru= ct sigevent *event, return -EINVAL; } =20 + new_timer =3D 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. --=20 2.43.0