Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp685525ybl; Thu, 12 Dec 2019 03:17:22 -0800 (PST) X-Google-Smtp-Source: APXvYqx9ZZoZw7GG3TC/pMKU4qt4qeBzflswnveppBzihmbAF+Yj+xbpHLeBh0MYtIBxkuerfvgC X-Received: by 2002:a05:6830:87:: with SMTP id a7mr7324236oto.314.1576149442771; Thu, 12 Dec 2019 03:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576149442; cv=none; d=google.com; s=arc-20160816; b=zVqA0D/eGaFzMlKNjNdbgLCPft7YY47Gfgb44Ny9tEVVfcQOOqQ+qt9aIUV9KxRt2A nr+EX+CfwTM6uTAhTq71W6mpdnSnnjP9T8zUVs83q+1IUVIUefp6icHxxB0/mYL5bP3x /s+/MNCVsCHTGHK8d3ada6YYAN08Aj2KoUYgJwI0Xh29Aq7GJqBV2TdM+3E0hvrF6+N9 zUy2mfEDjTAqp6eAEsTPJft/XtD0BHHJu2g3nJ510Z5CJk3Lm8aHgVa0hn7PM91AOzyB LOnK1H0W/3aTfd1nhrzbGt3wiKtuQnEeXJFx0MT1WHXxsdOGK2SMWzdH2FDfLyAQp3CE nJTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HSs5hYHEpxr37BLfQkOEeEosBFCrbzeSrlIMhONlo3o=; b=ztbo+tA3kf/9TGrBs5R0hgWV13ZismHlM5BY8l2sCPG+UH60U79sUvbx8TJYn8gTeq W0FDcU0VTQ43nKmq5ssI+Wr3A0UGvVSwFIooZLdUIIvQvclOUT4yR5qAe0RCk8EMQnG+ BDMgceoTNiwqDZynyIE/scBg5XAOsmPmijWg3k5hL/FA27e4SGmlMfKAS/Uqj+67bS4i s/fUvOnAyCl12OD6yDUUEQzbcHGq3xR5vaTku/UAl4ahSuBooiPMbjrU5H2OtizBSZ8p hGfzcBwZlY3u2K3hq3dRUhOUTcHOKuwfY3loQP+N7S18+DPtZN+r2DqJsP5s+O80Gtj3 nmqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mWfXnBTm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si3412170otb.26.2019.12.12.03.17.09; Thu, 12 Dec 2019 03:17:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mWfXnBTm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728923AbfLLLPW (ORCPT + 99 others); Thu, 12 Dec 2019 06:15:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:59660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728458AbfLLLPW (ORCPT ); Thu, 12 Dec 2019 06:15:22 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27ED92173E; Thu, 12 Dec 2019 11:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576149321; bh=R62Pxd3w+3RH9FdZTL+j4QV6wzEAfkES4QJQiRksmKg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mWfXnBTmjRQIJQQQi3aMbpSCrqQH0kKas2Nzx1qMFr1UoqUQVLlgZLCidSdtI03xu jWfOFzzJlen380Ol0yAA9MOnzXYRKU5vTF5Q8/Nn/YhT+8WkSvBXdxQiwESTwM4JLn uj9x5uu4+cK2BKMExef7FPqySQm1LcIxXVbmIaVk= Date: Thu, 12 Dec 2019 12:15:19 +0100 From: Greg Kroah-Hartman To: Sudip Mukherjee Cc: Jiri Slaby , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] tty: use tty_init_dev_retry() to workaround a race condition Message-ID: <20191212111519.GA1534818@kroah.com> References: <20191121152239.28405-1-sudipm.mukherjee@gmail.com> <20191121152239.28405-2-sudipm.mukherjee@gmail.com> <20191121164138.GD651886@kroah.com> <20191121210155.limd7v6cpd5yz2e7@debian> <20191210114147.ivple4ccr4bj6c4h@debian> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191210114147.ivple4ccr4bj6c4h@debian> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 10, 2019 at 11:41:47AM +0000, Sudip Mukherjee wrote: > Hi Jiri, > > On Fri, Nov 22, 2019 at 10:05:09AM +0100, Jiri Slaby wrote: > > On 21. 11. 19, 22:01, Sudip Mukherjee wrote: > > > Hi Greg, > > > > > > On Thu, Nov 21, 2019 at 05:41:38PM +0100, Greg Kroah-Hartman wrote: > > >> On Thu, Nov 21, 2019 at 03:22:39PM +0000, Sudip Mukherjee wrote: > > >>> There seems to be a race condition in tty drivers and I could see on > > >>> many boot cycles a NULL pointer dereference as tty_init_dev() tries to > > >>> do 'tty->port->itty = tty' even though tty->port is NULL. > > > >>> > > >>> uart_add_one_port() registers the console, as soon as it registers, the > > >>> userspace tries to use it and that leads to tty_open() but > > >>> uart_add_one_port() has not yet done tty_port_link_device() and so > > >>> tty->port is not yet configured when control reaches tty_init_dev(). > > >> > > >> Shouldn't we do tty_port_link_device() before uart_add_one_port() to > > >> remove that race? Once you register the console, yes, tty_open() can > > >> happen, so the driver had better be ready to go at that point in time. > > >> > > > > > > But tty_port_link_device() is done by uart_add_one_port() itself. > > > After registering the console uart_add_one_port() will call > > > tty_port_register_device_attr_serdev() and tty_port_link_device() is > > > called from this. Thats still tty core. > > > > Interferences of console vs tty code are ugly. Does it help to simply > > put tty_port_link_device to uart_add_one_port before uart_configure_port? > > sorry for the late response, got busy with an out-of-tree driver. > > It fixes the problem if I put tty_port_link_device() before > uart_configure_port(). Please check the attached patch and that > completely fixes the problem. Do you want me to send a proper patch for > it or do you want me to check more into it? This looks a lot more sane to me, can you resend it in proper format so that I can apply it? thanks, greg k-h