Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp358216pxj; Thu, 17 Jun 2021 04:31:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzogX/IzAiLfJezBk7exgzYaBhrTcl3YWBmvS15+vt9rYN0YYRcJJZW2FzStsranAxnHAuK X-Received: by 2002:a05:6402:8d3:: with SMTP id d19mr5730068edz.321.1623929467385; Thu, 17 Jun 2021 04:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623929467; cv=none; d=google.com; s=arc-20160816; b=is8PquOaDBI9tGNUhtV7EHgDXRg/7Jg72wt+p684YIpsw4nG8HRoi6BNhH5m76Im40 18bfsKp/sDQb/FIB3jG08ktCWlG6TCHlzTzLwsFRvBVKxVI++zezUWytafG98WrpK8mG n3yIEfmsq++w70opZYRoKBvAFtJeMZe6y81xCCASJykRpkirawUv22TAreLVPFptrEu+ VA3unhDgCcxISBLwoXHsPR54JW086hLi4QsZAATu7/KY3x3nnOAGqvRub9SZrEHQBxce Q/Dum7b1EJREpwV19pKvYqRfgZ4txEZFynxmSuQTbR/f2tj0sxxFiO3kq/PimvSqCpXE MhNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HtAONl3gdZy0MSt9rHJt7WYPa//OF0XRpVJvSnGcmgU=; b=YFeIpoodhMkzfiGTJ1OhCYLEN75JuLO9bbZZwvMU+O5M1NonlhYAOlVOgrB7MoJBsg c0aVQ1q/HBqok/tj/GwsiH8onWp9whQXEEP9s5+fVmZwEpP/IlaK9GjI7rZktGweE9Ae G7xRFKU3IOs4JrEP8+2wLHpzj7Bv+XYcyWmAXRg74Ly4EjMfeZvXua2eOkcFfX9J0YXp d8aHxiwuCKObdZn1dCcFEhGhp5a+T5DGbHvpQ17CX8m+yhK5ck3jItEcBkh5A17dyqCj XLPJSrVkIvlv6uxiKoTmT2c2Hd3eQAurxAW5tR7KJcjk8OsGuASz6Wx300J5yHaxS9n+ P1oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=giJZ0vdA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l22si5970518edj.70.2021.06.17.04.30.44; Thu, 17 Jun 2021 04:31:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=giJZ0vdA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232343AbhFQLIh (ORCPT + 99 others); Thu, 17 Jun 2021 07:08:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232301AbhFQLIK (ORCPT ); Thu, 17 Jun 2021 07:08:10 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A57C0617A6; Thu, 17 Jun 2021 04:06:01 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id a127so4706485pfa.10; Thu, 17 Jun 2021 04:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HtAONl3gdZy0MSt9rHJt7WYPa//OF0XRpVJvSnGcmgU=; b=giJZ0vdAd+XM6JT6MohRbQc9SzObMOe70tLHMVdqRfspZummlknNhdlgpDSZrMm6AL WjrlN8IRbrXCjI5IIIoa9tE1DlUlAeLfzvJAXM9GAi3aiKpMb6ijQFrLkCFHaQzzUnsQ HJrAFKHCH8BuslHscKMHqKlZIjMS81fKJWgLhg5JEvvd4MFVbyKeVNt/l7aHQ4QX53QL Kj/R13QA5525o5I3U1go/ctlHB0TALNXOJjNk4tjaNEhzS7PUD163I3jFNffLqf3eAXr gDZfpA+KPaRVH8juCeerT1YifOwI/0KFe7BDvGvhVCJa7D+r1F8L2TC8CXSPRkPhY+u+ Qt9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HtAONl3gdZy0MSt9rHJt7WYPa//OF0XRpVJvSnGcmgU=; b=LSvLS3OYMyI7L7Fisthoz6KSR5mE9hos+3ynpZJk5kjby5zkrFxJ3gbZNtT/tg7oRz ny/r2+aLevadjEjrW6vGQWf9pc2KuSYObbMPxxkrSgkVFB+ikAVrZ6IuPtyIpkFUwfyc AKUucgvzPHS2oQeIs95K0UePwnlNTBgEgtt1PkdjOly7BeaSvVML1x8Zq/gV/lDLwzWT ZAUnAkDiR4Qi7fMVIyKtPc83zCOrjCfveQeOYo2msn0PL49waRSJrwF/rRK2m28zIFTE gTkjwcjpqN7IiGCGn3pBfa4fSWNH2z/eAD/Bt5OT/WrJWYLOYrpAKlhxDK0lFQMKaFDG dRvQ== X-Gm-Message-State: AOAM532RhZavCCtT6TgCtP7WIAs6PcadfFnkkmtPpWGvk0Pb5iRux4AE 8hgJY9RxgXfIq/ZVmvDQ7vg= X-Received: by 2002:a63:e44e:: with SMTP id i14mr4530000pgk.80.1623927961206; Thu, 17 Jun 2021 04:06:01 -0700 (PDT) Received: from vessel.. ([103.242.196.232]) by smtp.gmail.com with ESMTPSA id mg22sm4762073pjb.26.2021.06.17.04.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:06:00 -0700 (PDT) From: Saubhik Mukherjee To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: Saubhik Mukherjee , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, andrianov@ispras.ru Subject: [PATCH] tty: serial: owl: Fix data race in owl_uart_remove Date: Thu, 17 Jun 2021 16:34:43 +0530 Message-Id: <20210617110443.6526-1-saubhik.mukherjee@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Suppose the driver is registered and a UART port is added. Once an application opens the port, owl_uart_startup is called which registers the interrupt handler owl_uart_irq. We could have the following race condition: When device is removed, owl_uart_remove is called, which calls uart_remove_one_port, which calls owl_uart_release_port, which writes NULL to port->membase. At this point parallely, an interrupt could be handled by owl_uart_irq which reads port->membase. This is because it is possible to remove device without closing a port. Thus, we need to check it and call owl_uart_shutdown in owl_uart_remove. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Saubhik Mukherjee --- drivers/tty/serial/owl-uart.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c index 91f1eb0058d7..ac4e3aae2719 100644 --- a/drivers/tty/serial/owl-uart.c +++ b/drivers/tty/serial/owl-uart.c @@ -751,8 +751,15 @@ static int owl_uart_probe(struct platform_device *pdev) static int owl_uart_remove(struct platform_device *pdev) { struct owl_uart_port *owl_port = platform_get_drvdata(pdev); + struct uart_port *port = &owl_port->port; - uart_remove_one_port(&owl_uart_driver, &owl_port->port); + /* It is possible to release device without closing a port. + * Thus, need to check it and call shutdown. + */ + if (owl_uart_read(port, OWL_UART_CTL) & OWL_UART_CTL_EN) + owl_uart_shutdown(port); + + uart_remove_one_port(&owl_uart_driver, port); owl_uart_ports[pdev->id] = NULL; clk_disable_unprepare(owl_port->clk); -- 2.30.2