Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3465102ybc; Thu, 21 Nov 2019 08:43:21 -0800 (PST) X-Google-Smtp-Source: APXvYqw4GQ5pXM4Jb+V9zSIZ8yjJoG2OO6PSJJcJ8bJKzC1wJBJQflj3RO+LKbZ06vcyDHWghZVy X-Received: by 2002:a17:906:3606:: with SMTP id q6mr14653947ejb.307.1574354601092; Thu, 21 Nov 2019 08:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574354601; cv=none; d=google.com; s=arc-20160816; b=YqbvNdBEevo3Qcec22fwPc0Ms77tasG/Xha7oIekEUsJD99kO02px+amXWa+Uhu0sz uD3DBGW0V9+jQS/wGNx0goyLCExXljbNcpcI8GCp7ddj7Q3CvIyOx2E1pWBOjdNUDibU TO1C++ICd14nnkDav8XSGLTgAVAUB6AAlKocbIEpaST78+k7OSg2Att4s7my3iful9Z9 R0fiIW0eu6YxJuUnqAIWLWi9JoGnQZxZUu7LaWavQx80Cre9EVGBoQKSrfPHaEvn+D3l 450yMMkibkF0mN2MITzjdjULJp3gKd6Htmti1GVhBMGqNgN+DNM8LhLrJ1mdwqIwOhxZ Edyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vPXvNE/CkFdLpwrVP6aZrPNudzm2Umrjhrvffhzkxt0=; b=m6cDCdasRit+cDSeUTUGGEgIJEaMS6tNZru080xYPCIVjuL3YJUUVJATcz2gVk2yRs De1u6+dcg8vcdTybJnGKtQ3POztgxB9OwyoKiipJ1gecR7LhT1nVgdqOq0N0KduK8tov WK+fJ0x9aavNkA+Hmo28UXoVhKozzaPJIkEU03VvR0w2wD09K89FImLN3khqViyMPXvQ sNb2y5pgVGPDTqb32Fi5Lld613W8or74QvUx+st8h6+pC+m5+h9d/YBc/z/RBueSJh+R G/HsxsYYQVAA0kzxgbNoSItZSNklRTnUtegOfVdet63A3QROOo8KbJHoa0GEGvyHzszy t8Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZWeKF1wu; 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 um2si2034139ejb.64.2019.11.21.08.42.56; Thu, 21 Nov 2019 08:43:21 -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=ZWeKF1wu; 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 S1726701AbfKUQlp (ORCPT + 99 others); Thu, 21 Nov 2019 11:41:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:47746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726279AbfKUQlo (ORCPT ); Thu, 21 Nov 2019 11:41:44 -0500 Received: from localhost (unknown [217.68.49.72]) (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 1B04720672; Thu, 21 Nov 2019 16:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574354503; bh=IrWFGRzmzJof+idBR3hRRL80JDK5bEELlrtOoefbtI8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZWeKF1wuB8uwMK0EqpJQ3pOHyPA3Exyd5bnLUvSsLKoMQ10eDW9d2elW7ZFtJ+ryV MUp/SwpL64/rlW5F7Ni0/HDVhsVpnSjZTSMuFaRtYtVsZwUQs8V2RnFDTvTxBmWnQj GAZmturMvROOEGE/0MRhJyZiS6XK0Yp2ihp0/sDA= Date: Thu, 21 Nov 2019 17:41:38 +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: <20191121164138.GD651886@kroah.com> References: <20191121152239.28405-1-sudipm.mukherjee@gmail.com> <20191121152239.28405-2-sudipm.mukherjee@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191121152239.28405-2-sudipm.mukherjee@gmail.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 'tty->port' will be set by the driver and if the driver has not yet done > it before we open the tty device we can get to this situation. By adding > some extra debug prints, I noticed that: > > 6.650130: uart_add_one_port > 6.663849: register_console > 6.664846: tty_open > 6.674391: tty_init_dev > 6.675456: tty_port_link_device > > 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. This feels like it should be fixed by the caller, not in the tty core. Any reason that can not happen? thanks, greg k-h