Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751833AbeACNtE (ORCPT + 1 other); Wed, 3 Jan 2018 08:49:04 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:33683 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857AbeACNtD (ORCPT ); Wed, 3 Jan 2018 08:49:03 -0500 X-MGA-submission: =?us-ascii?q?MDFEo2o0cvnOvoS1CGNx9dUTCOs3TmxvaV3a4J?= =?us-ascii?q?mQlkOwl3e1G8Jv80LPZ+mLqye0xd3rDfrPG5WeCt6BnSuwj67tGnaXzm?= =?us-ascii?q?D8o6B/UwhRiY547UMfaDZghTZHISoUpMQRLWIlTYKGoqgpDKbTLSn0eH?= =?us-ascii?q?Zz?= From: Gaurav Kohli To: jslaby@suse.com, gregkh@linuxfoundation.org, mikey@neuling.org Cc: linux-kernel@vger.kernel.org, Gaurav Kohli Subject: [PATCH] tty: fix data race in n_tty_receive_buf_common Date: Wed, 3 Jan 2018 19:18:52 +0530 Message-Id: <1514987332-14122-1-git-send-email-gkohli@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: There can be a race, if receive_buf call comes before tty initialization completes in n_tty_open and tty->disc_data may be NULL. CPU0 cpu1 ---- ---- 000|n_tty_receive_buf_common() n_tty_open() -001|n_tty_receive_buf2() tty_ldisc_open.isra.3() -002|tty_ldisc_receive_buf(inline) tty_ldisc_setup() If tty->disc_data is NULL, then return from flush_to_ldisc Signed-off-by: Gaurav Kohli diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index 25d7368..5d49183 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c @@ -35,6 +35,9 @@ static int tty_port_default_receive_buf(struct tty_port *port, if (!disc) return 0; + if (!tty->disc_data) + return 0; + ret = tty_ldisc_receive_buf(disc, p, (char *)f, count); tty_ldisc_deref(disc); -- 1.9.1