Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751856AbeAEOPv (ORCPT + 1 other); Fri, 5 Jan 2018 09:15:51 -0500 Received: from www.llwyncelyn.cymru ([82.70.14.225]:50866 "EHLO fuzix.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbeAEOPu (ORCPT ); Fri, 5 Jan 2018 09:15:50 -0500 Date: Fri, 5 Jan 2018 14:15:04 +0000 From: Alan Cox To: "Kohli, Gaurav" Cc: jslaby@suse.com, gregkh@linuxfoundation.org, mikey@neuling.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] tty: fix data race in n_tty_receive_buf_common Message-ID: <20180105141504.0e399394@alans-desktop> In-Reply-To: References: <1514987332-14122-1-git-send-email-gkohli@codeaurora.org> <20180103193807.465e054e@alans-desktop> <0a456419-c836-08cf-070b-a254fb702b75@codeaurora.org> <20180104110920.169a1fe5@alans-desktop> <0dbd1f05-4c94-d1cc-3858-7bd4d38b9212@codeaurora.org> <20180104143716.5b09b1c7@alans-desktop> <93a7bd73-1123-90a7-b22d-02964ba29fb0@codeaurora.org> <999c5499-05c7-4702-77a7-dfb56ba577d2@codeaurora.org> <20180105133609.636b2d1f@alans-desktop> Organization: Intel Corporation X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: > But in above case , there we can hit another race, if we have a sequence > like this > tty_init_dev->alloc_tty_struct -> tty_ldisc_init -> this will initialize > ldisc , > but at this moment disc_data is still NULL > > And if flush_to_ldisc comes in between, it will take ldisc reference and > proceeds receive buffer. So you need to move the lock up one line to protect the assignment to tty->port->itty. We can do that. At that point your flush_to_ldisc should see either port->itty = NULL or a valid initialized ldisc. Alan