Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp363705pxj; Thu, 17 Jun 2021 04:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLaFwjgM15avCSGGS2ze9+yxCWQ0K8JwY5Hx9VHL096CunBLF9ph1N73sAwI2Wpa71PrFn X-Received: by 2002:a17:907:98ae:: with SMTP id ju14mr4681261ejc.173.1623929975777; Thu, 17 Jun 2021 04:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623929975; cv=none; d=google.com; s=arc-20160816; b=kaI7GQ07oMkQHD5jHVoX6C52xL5FPTAUlJehTt/BvxxmbLjVLSKn3d+F9WmzDmA9Zk UGEUawh7Bbjl0m26P0ytAKs03tWkPXU/u+8CWqNSGAHlJSme0bNfLo3X7BQ2Zj1c/ek4 uwb4v5RtX1RX+rnDWCk4IPVpeJ7pylfteMmZiDRMuoH8F0Lx7pfn+EqJzQcRT5yz7sAZ B95XMBhyCwTbob7H5TUlSOhsDKfEbEqJQp3zc4HlV6I0ORxkXQPfZT2a+eMqmc6ei+th XTF5SM0PVB0GHpn1pXJ/VZR6GkpnNOCvx0fVOAl2oRNbyyXRJt5qFU76XPTHafJzpUoT IPwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Mq4CkksR66uVUiZnCda5roKUSaOiCd83IpkK6qCYr6U=; b=FaNoIIX4wzyY4/8tv4C/yH8EekMAW9E0yx5G3FR2vAg2h5I/DjV9M3/2mAAVmWVxBo qshchtUj7YQuinWiUdVGnScPBdefdjZFoKRKEeRyn6sV5I98CcjBXAyt7KcRCTrBnBsW rDSusE2FF0kslg6pG9CxDe9UBy8njexhXeR64S2VvTA2pmQZY0487DBu3BeEZvNc0if/ BvDZ9KIoE5hIFADjMOxHpVBJXTMbtU7T8n88zVxZd4d+8WtfBJKvqnGdlGJCOW2mN+aS KXtZN5AxBbDnzlrr5tGwWmyWDf/3RnjEEHp+aCMbB1bvpwjGKDrlGG1pj4UobzI5bC47 OwsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="lAHH/dgt"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si1048068eds.410.2021.06.17.04.39.12; Thu, 17 Jun 2021 04:39:35 -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=@linuxfoundation.org header.s=korg header.b="lAHH/dgt"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232525AbhFQLYm (ORCPT + 99 others); Thu, 17 Jun 2021 07:24:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:55106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232530AbhFQLYk (ORCPT ); Thu, 17 Jun 2021 07:24:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8CCEA613BF; Thu, 17 Jun 2021 11:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623928953; bh=7W6ZUJUgvAuyObY+Gwz9gOCcH56okP5pyM7YKdKyOxQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lAHH/dgtPd9TF6pgepsFS3oIce5b/X13/xa4cXrZijhnfCujrutwtL+w/5QqaFKqj fNxiZSUO/wGfLHgifF5FtVPwbYcOykde0m2ZAPmCZTVEcZ8cKGX1Yt9WTyh0oEyvDh RMjF4Kb74h8ho702XmfG/6m778hgdk0njFLmxqJY= Date: Thu, 17 Jun 2021 13:22:30 +0200 From: Greg KH To: Saubhik Mukherjee Cc: jirislaby@kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, andrianov@ispras.ru Subject: Re: [PATCH] tty: serial: owl: Fix data race in owl_uart_remove Message-ID: References: <20210617110443.6526-1-saubhik.mukherjee@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210617110443.6526-1-saubhik.mukherjee@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 17, 2021 at 04:34:43PM +0530, Saubhik Mukherjee wrote: > 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); How is this read determining if the device is here or not? And what happens if the state change happens right _after_ the check? Also, your comment style is for networking, not the rest of the kernel :) thanks, greg k-h