Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4742976pja; Fri, 22 Nov 2019 01:08:03 -0800 (PST) X-Google-Smtp-Source: APXvYqytPJvHYhNamVBgzXbJdcjXgtfWbcFLGxXWgU+ZY7SkbssKKoOp5yVt6uqimxQh83/p3w3J X-Received: by 2002:a17:906:2344:: with SMTP id m4mr6150124eja.110.1574413683669; Fri, 22 Nov 2019 01:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574413683; cv=none; d=google.com; s=arc-20160816; b=Bcilp44351whFIoUxLNWslLEpdD6bhJtnDyvA7tbDwO+3vVc8HMl03X3Y1YD+I6Pyk p/JU1pdqe1YtGR+QXlRZCi8NBPXhxa5pBwg+rUSXWu0nwzTUGn9D4hgeO/d2yO8mcJJ4 ylfg9jx3WVyvvxlrTgR7I2mnnjA9/KMtkMA2Dg3kigBNUC/2AMnMiGuVddgH63GBJR7k DTS3KeNgfx3uL4eqUvYVO+ycOBGXqqNHVFon+NUi/tJ4Kg/5wRxpIGl5UYfrXCRsrvrF rM8i1OvhdH92Gnv61c8Hu+6R9gV7NF1ApsQXW5sf5sFpO+7xhlIr1K9w5C+6HMLearbD fzoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject; bh=Nf3kSA3hvbFKpVNXqMsfEdpGB5UW14apon950jWNL9E=; b=nCWo2DAO23QX1o+XVEzyEpEgyPsjrX5GwSBBYtIkULpPFpHBSA28qgLQ/C2giQKTph cgl1I8Qn8llB/OKo8v2FMSaAOj85D5lDeJpY4am2061NVOtzb/nMg6zZqYm3IDH3Jym/ ysoCpi70pZLLvEXkdHErc+B+TztAaPX2Mh/zO95m85quN5fSdqwh4WGzoVfF9qPgXdHC VFOvBq5UbgXn9Xanr0Ee6Z+Qn98i4VwxTnM6oJCcFR5ABs9eZweyVL6BF4mkt87o/v86 TUZbLi98whEVwZoMEt+NEBRQYthx4kqgv+ermVEoRsH3W8bFBfhPqVw7uykCDwytd/Mh 7teA== ARC-Authentication-Results: i=1; mx.google.com; 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 hh7si1950817ejb.57.2019.11.22.01.07.38; Fri, 22 Nov 2019 01:08:03 -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; 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 S1726698AbfKVJFQ (ORCPT + 99 others); Fri, 22 Nov 2019 04:05:16 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36044 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726417AbfKVJFQ (ORCPT ); Fri, 22 Nov 2019 04:05:16 -0500 Received: by mail-wm1-f68.google.com with SMTP id n188so4744056wme.1 for ; Fri, 22 Nov 2019 01:05:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=Nf3kSA3hvbFKpVNXqMsfEdpGB5UW14apon950jWNL9E=; b=TbxIAmMxNABfZYJt/RJFw60qI+pWyDY8DiH3dOIz3vdMuY6ZNYCYIl+QFNcCBFFBAR 7qL6J02c092o7pGx0DHlGzU0oyH/GjBVgwdnCCNaojB5Fstju3IkIrfSs4tC91Hgpd5Z KlLmc4sJWFk3W8BZ2lQbVr5lZpazhiwyhPQgStUXYxnPV7ToCMapJPXH+/F7cLDgAK+b 7UDo21U2IbixBlCL3xrSoXZpeoKrbdDQoP54XC2MkDVX33KjzmWGA+lEntCSwfkK2GtZ wFAZAYChPunt8iPgJkMi9L8D6MCCqHDmJSzdwEaQN2I8O4owTxc5ZcLFcBkSm0rBjXYc RNfw== X-Gm-Message-State: APjAAAUKhwdAU18ff3hXn4m/F81742QZDbXSTKRqYM/b83lyrITqf2NB EOcu+DbWCMqKrdrAKbL20+OWasdvu3c= X-Received: by 2002:a1c:30b:: with SMTP id 11mr14406639wmd.171.1574413511454; Fri, 22 Nov 2019 01:05:11 -0800 (PST) Received: from [192.168.1.49] (185-219-167-24-static.vivo.cz. [185.219.167.24]) by smtp.gmail.com with ESMTPSA id y8sm2731141wmi.9.2019.11.22.01.05.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Nov 2019 01:05:10 -0800 (PST) Subject: Re: [PATCH v2 2/2] tty: use tty_init_dev_retry() to workaround a race condition To: Sudip Mukherjee , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org References: <20191121152239.28405-1-sudipm.mukherjee@gmail.com> <20191121152239.28405-2-sudipm.mukherjee@gmail.com> <20191121164138.GD651886@kroah.com> <20191121210155.limd7v6cpd5yz2e7@debian> From: Jiri Slaby Autocrypt: addr=jslaby@suse.com; prefer-encrypt=mutual; keydata= mQINBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6F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Mq0nQ/yNh3s/WBlv0XCP1gvGOGf+x UiE2YQEsGgjs8v719sguok8eADBbfmumerh/8RhPKRuTWxrXdNq/pu0n7hA6Btx7NYjBnnD8 lV8Qlb0lencEUBXNFDmdWussMAlnxjmKhZyb30m1IgjFfG30UloZzUGCyLkr/53JMovAswmC IHNtXHwb58Ikn1i2U049aFso+WtDz4BjnYBqCL1Y2F7pd8l2HmDqm2I4gubffSaRHiBbqcSB lXIjJOrd6Q66u5+1Yv32qk/nOL542syYtFDH2J5wM2AWvfjZH1tMOVvVMu5Fv7+0n3x/9shY ivRypCapDfcWBGGsbX5eaXpRfInaMTGaU7wmWO44Z5diHpmQgTLOrN9/MEtdkK6OVhAMVenI w1UnZnA+ZfaZYShi5oFTQk3vAz7/NaA5/bNHCES4PcDZw7Y/GiIh/JQR8H1JKZ99or9LjFeg HrC8YQ1nzkeDfsLtYM11oC3peHa5AiXLmCuSC9ammQ3LhkfET6N42xTu2A== Message-ID: Date: Fri, 22 Nov 2019 10:05:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20191121210155.limd7v6cpd5yz2e7@debian> Content-Type: text/plain; charset=iso-8859-2 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. >>> '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. 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? thanks, -- js suse labs