From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 BE63678F26 for ; Sun, 3 May 2026 10:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777803101; cv=none; b=J7LwRyhTFJoUEtRjMcsJ80ZfeOCc2VZ7/HTicO2Et3iitRtHBbA3Gd33nlZmBjYopw9ebkn2v/fP7iSFt3Y3gVlTTC+djCdqcFwPqEwQzyFtNjYTNJuBOHiarbDy/2u5WRmCJuD7O21Fpiv2Wxmj36CybQHgHGk/P+sQggPZrac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777803101; c=relaxed/simple; bh=KIKMUxDpQCsLvBWp4JG9SnSys7QNcNS46U9GQYrcIdQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=FBTwfglGLCqVtL5yPoV2fWkdAtcwO1pI+XSR4/Hz05bWQmt3Z0yJKv7bJMxI/3Hh6VnNblt2fIaKE2VESOCKsBz5aWdUSfFAKPxOdPp2hvTHeXL39sUI+aP7OnWeW9hCpoEt435WaP61vnO2/Il8sW24pac6zx2lInr9CvO2yl8= 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=IPwPQ5L+; arc=none smtp.client-ip=209.85.210.181 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="IPwPQ5L+" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-827270d50d4so2911939b3a.3 for ; Sun, 03 May 2026 03:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777803099; x=1778407899; 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=5xCacUd2m+kW9j9AErELnT773G4xdbyDO277gi3+z60=; b=IPwPQ5L+CeRIPd7neojbM/mTYmGuxsnTgr1KpRSkQBZZlk8PwZfh8gbmxrd3c4pThf HCIoIbKVfvWwTkMsZJ3brNcMs9VO2BAIHFob5vhhSbVtC/lXyYXcCz/mRaonArzVxLbw L1n2y0R0y3g5iTX/pzags6TxnMRHWQZZParCSVz31bMpo1lqVJKDp8enGbRXA5+KBYL3 tS1ofqH9Jt0Ii2jHs6dy9k+mXDh1CVU3KZvQQnpb7WrckYajycOyS7g3p9oWuWILT2CM zvqgmbm4lWDFshVLzpTEKT+4ux+QP8Rfy+I6DXJZcYlTlGDr8uZZzbLGwcveV6KVqaBp VOtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777803099; x=1778407899; 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=5xCacUd2m+kW9j9AErELnT773G4xdbyDO277gi3+z60=; b=AHI4dnOA/6LBrL2iWTyVVtPAWn0LcxYx3fsBrA/ABunVy7eiJogiev19B6Ovl9P1Jt oFwdPLnTLPc7Fe8RW9OO9CV6i9dvq84y08c03lkBb6cHznU2x9vpSRS9+Nu9TBvMu1Cc gqaGv3OpBsahCG5lHZGh07ZW/+1ckN+fweUisWfAiQ8nkqekijw82o0WpzzWPcei+wIh +oOtNpmGigsAvLUZPaJuzkY0K0O5Qi9Hh6bd3hgEf5kXsg4AkiG3JOhTzKe6FXwgvfkO 57+SkuP+xdYwklZ1qrdsNl3HkViBm7he92qwCTBctKlJu6F94lyH3QOmLB9RzIf85NZa eajg== X-Gm-Message-State: AOJu0Yy6naN9Nzl07Z2jfXwCNsQrgzzKhCLSQAgeUg3JZ/eO+UIA/J3c ZmOIwj6SvnwlZkVxVRBVpoxA43fY44OOMQ0gXi2rujsG0NzoynNGJELk X-Gm-Gg: AeBDiesAPBd//jOuLL/jAayqRR7DpPJhCLfJHXtPKkJyza12o1BjtaCuc+gtjG5k00g H7BvbWJUorQbXvhuP9r3xJoYL/GD8zQ1QXfQ+7ArpU7pWncFSRjAMa4CnnTN1FKLLlN7t/dvvSq LKZ46M+twixHKEpl1EQSdI7DbDqqPJhOv2uT4YkPfUf8pVfrpX76zdAtk1jfs0cq6BsNCojd4uF NUMoS3xvpvl0HdPCLAsC0mehzp/5loyfDmQHHExJ3SQKFqTZ66cIv+FCwiDux2BnSOj2HqGREqc QmbHqajA2+f1q3LrzISXVnja3LicR/hKmRSqxLHMbviF2KeLNza8dcNZEbJ1q7blsua7kW9ylwd nKX7QJHoL6XeiwnZeNlWSNN0kEeKmY67EDTlV4F9/u9Q/ug2G3tl00a4Z2w/JeDS4tgKarWNPX4 bUrc1YGhhy08ipPdJaubfXHtYrOlcnZ28hWxesEvg35X2mmuCuneiszLt5ysMfHXUvuLRk X-Received: by 2002:a05:6a00:181b:b0:823:d2c:b156 with SMTP id d2e1a72fcca58-8352d037329mr6078482b3a.5.1777803099081; Sun, 03 May 2026 03:11:39 -0700 (PDT) Received: from localhost.localdomain ([59.27.113.201]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83659d38ed3sm865162b3a.52.2026.05.03.03.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2026 03:11:38 -0700 (PDT) From: James Kim To: markgross@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, James Kim Subject: [PATCH] char: tlclk: fix use-after-free in tlclk_cleanup() Date: Sun, 3 May 2026 19:11:31 +0900 Message-Id: <20260503101131.64219-1-james010kim@gmail.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch improves the module cleanup process in the tlclk driver to prevent potential use-after-free and race conditions. Currently, the file_operations structure does not specify the .owner field, which could allow the module to be unloaded while user-space processes are still interacting with the device. Additionally, the tlclk_cleanup() function frees the alarm_events memory before ensuring that blocked processes in the waitqueue are fully awakened and that the switchover_timer has completed. To address these cases, this patch: - Sets '.owner = THIS_MODULE' in tlclk_fops to safely defer module unloading while the device is in use. - Updates tlclk_cleanup() to explicitly wake up all blocked readers (wake_up_all), properly release hardware I/O regions, and safely delete the timer (timer_delete_sync) prior to freeing memory. Fixes: 1a80ba882730 ("[PATCH] Telecom Clock Driver for MPCBL0010 ATCA computer blade") Signed-off-by: James Kim --- drivers/char/tlclk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c index 677d230a226c..dd45fe5eb6f2 100644 --- a/drivers/char/tlclk.c +++ b/drivers/char/tlclk.c @@ -264,6 +264,7 @@ static ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count, } static const struct file_operations tlclk_fops = { + .owner = THIS_MODULE, .read = tlclk_read, .open = tlclk_open, .release = tlclk_release, @@ -837,6 +838,9 @@ static void __exit tlclk_cleanup(void) misc_deregister(&tlclk_miscdev); unregister_chrdev(tlclk_major, "telco_clock"); + got_event = 1; + wake_up_all(&wq); + release_region(TLCLK_BASE, 8); timer_delete_sync(&switchover_timer); kfree(alarm_events); -- 2.37.1 (Apple Git-137.1)