Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3743685ybc; Thu, 21 Nov 2019 13:03:35 -0800 (PST) X-Google-Smtp-Source: APXvYqw1+d917mKbnK5vmyRstRtRqpCfUoTAHnxjgt5SlE7v/5SBoX2s1mW0WBWgOp4CXXKugiIq X-Received: by 2002:adf:ec89:: with SMTP id z9mr13460675wrn.153.1574370215497; Thu, 21 Nov 2019 13:03:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574370215; cv=none; d=google.com; s=arc-20160816; b=gSfPPGaNnAts4Tw+GrVo+J9l9TtpArBqFgQ6DiB5Xj9vBkah/dod5BHsRMLnFDBBl/ UpJBhTpyv/i+UNZ1pAbvYNc5hFvRGtKxz536Oe9RAGMfUsJXKd64AJUOEhlFIO3ISBDK 5RaA0lxXpF1tBR9cy4444d3bToAVTRrTNgnqOXDhe39RgvcNudGivyt0ETC49efctX07 WL7U/QN/0177ttC7PQ0C2s8t9VotGJ0VooEBTUlREXjytHNzFngBfImgHpiUsxlw00g+ 7Yl6SYZEdFF8p38SS0HPFwk+J/StIXlGE+ZoQ/b5Grgih9qZv9I9qNb31eTb/+bBBoOi FGuQ== 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=KhhCdcenu8JT9fVRRF+JElxTcseh8uLlM6hjFlflU3o=; b=0Av8fIbZdX9tdvVhFP28Df8f7CytmyKp3NNZf0XtskV20OHjvFOlDpW3dhXsaSlsm7 e/LQzRO5HKXff6Mrduq5tmlC+4CH11gI5iHdk3cGFxAanWhbPdPuPhWytSq2+2g9Q6T+ ifJQEQqLXA+zzdefPh0jFe0wbsauhAy3m0JdKpwpqpartnm4Ur3rREwpUV4ciKo2LNUX czotXs/7uPrN3aS5s1mfs2QKUV+cwGikCGmMyjTqqAtTbeFLUCVo62Cor/az+1xfDSBQ kOW4A95O02jp8jD0+0WPzzkbCOdlO6AhmEzKQeTrivNX9BIZZrju4qvT5j0ECSn9tFMi WW5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aQ5UutHQ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h22si3291423edb.346.2019.11.21.13.03.09; Thu, 21 Nov 2019 13:03:35 -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=@gmail.com header.s=20161025 header.b=aQ5UutHQ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726803AbfKUVCA (ORCPT + 99 others); Thu, 21 Nov 2019 16:02:00 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34084 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbfKUVCA (ORCPT ); Thu, 21 Nov 2019 16:02:00 -0500 Received: by mail-wr1-f68.google.com with SMTP id t2so6183793wrr.1 for ; Thu, 21 Nov 2019 13:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=KhhCdcenu8JT9fVRRF+JElxTcseh8uLlM6hjFlflU3o=; b=aQ5UutHQBuXkrv9M84UPYripNNscWYe6D13MxWHjk1yqKjMHcqyiq6aOOKc7twFITr v6qQ/921HHCLC8jz+0Lv9qhOrEeRjUoikbD7v/mNzQ8LZJpZ8QDleBG0ObYgmAMiHXw4 /tjkR9NGqco19+mI33LsgYoqb28/yZTX0Q4gm1uzwVPnmuezCKjH7+YxY724AXP2puic E+5XILxRfNM33WJZIx+05j1jwD6hhkNQuoXoooDP4aAtcTm4sVARmS8QM+14W3JiUfn8 +pDy+jMS1GUj/SR62zTSSCeLoSdlPN373bXVmEuNDgYBouon4iThZlmAf0+sYabxK5mX 11RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=KhhCdcenu8JT9fVRRF+JElxTcseh8uLlM6hjFlflU3o=; b=TBa3RdZyigNAY6L2rQudf6GqJ1vf4CpeD372Uh3hqmEcXTy7hjtOpthysCiVKQcSRf bJzWuHk3tNyPXVHrX1Coyq10lIwozO+WCME2UXJmFLtkEc63axv15kspCFwsFRFhbgOP iL2o5n7zyfDtRxoOo8nN3EVGrwOJdOOj9lzP1XnQ8qOdTJrUlqGAf04I9pQidkiZOR4D siI8zvL64NYVoqTkS0cCzqT7fJ4ou8DcqpXZtfklCRYIN55IBXoZux7t9FrILanByNpd Xsx08TkM31nTmAmYCEgZFsBe5yrliyTPiv+CbngTRu+rjZlsGuGGCcufZAKoU6NzuWJo rOQg== X-Gm-Message-State: APjAAAXHsWEBOXN82pwqFv7vCO+iw84dIA+G7Bl5b9AxlGwhvf5CKrr7 pKPNtNE5/BYveu2+XeeWmmYddUBQ X-Received: by 2002:adf:f18c:: with SMTP id h12mr13597678wro.122.1574370118024; Thu, 21 Nov 2019 13:01:58 -0800 (PST) Received: from debian (host-78-144-219-162.as13285.net. [78.144.219.162]) by smtp.gmail.com with ESMTPSA id x13sm911927wmc.19.2019.11.21.13.01.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Nov 2019 13:01:57 -0800 (PST) Date: Thu, 21 Nov 2019 21:01:55 +0000 From: Sudip Mukherjee To: Greg Kroah-Hartman 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: <20191121210155.limd7v6cpd5yz2e7@debian> References: <20191121152239.28405-1-sudipm.mukherjee@gmail.com> <20191121152239.28405-2-sudipm.mukherjee@gmail.com> <20191121164138.GD651886@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191121164138.GD651886@kroah.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > '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. > 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. > This feels like it should be fixed by the caller, not in the tty core. > Any reason that can not happen? tty_port_register_device_attr_serdev() is part of tty core. Or is my above understanding wrong? -- Regards Sudip