Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2305845ima; Sat, 2 Feb 2019 19:31:26 -0800 (PST) X-Google-Smtp-Source: AHgI3IZGxH/bqnG+OOwWiCnWu8ExcVQoNJqhttOkrv6PkLlyRnFrcagfijeXr+7kjrS8CVG3bR66 X-Received: by 2002:a65:620a:: with SMTP id d10mr2819683pgv.75.1549164686326; Sat, 02 Feb 2019 19:31:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549164686; cv=none; d=google.com; s=arc-20160816; b=GfP07ua1wNHgA0Tdyr69do8C3F4eGLeTJRZXbnVjnGF8j0FI+uhI2Qc2jqdu//Gd7/ voJ0ycXCbwh1mwgyXlN9tqf9DnyfY5WNt2MNbWByR3NFWodJv5AN0UteZOFY0o9N/5sy n1cm2SoCkIxDUAkiUjzSjXC+Io12IYrsB4/CUmZjiJiWgD3tp3p2etjeN1Cy/sEWuXCj gU2rlifJcGhFMfE7gA/Ce0wtgXE5xyeWmOGh1yWxp8f5G+HSh9FIXWx8HljoGcA7A/v1 Fsb5tDej1yOC42lHGx+Xd/EvIj897VJ3Sk4F5N+vRK+Cpyxy47oZH80e0tdqSPyQW6J3 yXgw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IhwZrh8KG3wLPMVgZRFj0uWRKgE0nMItZX7H2lN+yUs=; b=IrcRsSHSGJZ6mgXg9ssaVYigtahOPMbFE37yXXCbMQ/52+2xek0STZ4EHV5rVd8MdT t0Hof+f6lREWixvvQckgQEz4r0zOjVTUhgJCvDsjFtIeKs3RepL+/+WCguavenLfEZw0 GXQthZodO2Xlf8C6Ez0/2eA526pmrlEyfxDwdkLHx6VrTeoqZmNwZaL53kFBnSDuWxFA i7+As4N/kJlc8spatxyHZ/a1HQP6EmYuQHyjSqUhAGmy5++r40ygdrc/vHoE4AAXMwUZ 1BVV6mc8mkrGdajLuFsHcuRQc3FyhW4lUlClJvirxb/ibB6Aip3FGIS7SjV9ImR2fuki FcEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MmbLeWl5; 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 g1si11432929pgj.34.2019.02.02.19.30.39; Sat, 02 Feb 2019 19:31:26 -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=MmbLeWl5; 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 S1726703AbfBCDag (ORCPT + 99 others); Sat, 2 Feb 2019 22:30:36 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35689 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbfBCDag (ORCPT ); Sat, 2 Feb 2019 22:30:36 -0500 Received: by mail-pg1-f193.google.com with SMTP id s198so4794304pgs.2; Sat, 02 Feb 2019 19:30:35 -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:content-transfer-encoding:in-reply-to :user-agent; bh=IhwZrh8KG3wLPMVgZRFj0uWRKgE0nMItZX7H2lN+yUs=; b=MmbLeWl5KImC++p41acG61HIGFFcemopUSbwGonaEYOj6Cch5wfLAEhE00aNsrgLpl m+3632j5iSpEmScj0aJfONDnC+h1qcl9hbn2BxxLf5oliyKMHLogU1SJS2HTVXIFoZFE Oz+vogXKxh09G8CmQYWHUpy7PQAh38MKFwkIrxzztPU8PCOQMzNzb+39tPsP4EqgDsbx ABS/JHewoCykrIzxE/6OOG5MMd5IJdnDdgj2d+zsQZPJ4aqVt9MfkFHLVPQhf4CS6LzU +JJ8AM1ua0yG84n0PcnwecP/89djDLDi5mIGKr5w/ePAiyHmgAM3hy1n/MVCwtEq9jVV xBGg== 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:content-transfer-encoding :in-reply-to:user-agent; bh=IhwZrh8KG3wLPMVgZRFj0uWRKgE0nMItZX7H2lN+yUs=; b=ot8A46R3TqAYrCC+rfyIJjMl7Ic2Gxnj1EwEYtHy2S3u9FqX5We+BZ1tsRmp1shYCk ywJdIk/SNqoobe8tCEVFUlYP4EJ1O8Xa8iIHTwXhzJ+IzzMPpa9dwr4C20k+/tPIcWDm QMkKzuzjwcMO3QDKUjIeS3HFYojhMegQKpKxWfHlFaLv7iF9I0Xyv1k+IdHteOnDVpSx XGyqeEvy3iy9UpmDj8GbAjy4joflP0Hw+eTF+afEdB5ARclbucXtbg4y+qWCkYX9xpN2 tS/UiyT7W/tQ3w1rCQe9EvWIlzFFTZr7tQGMigVA4c84Zqfxx7POY/It8DDhVhzjpRuh YXHQ== X-Gm-Message-State: AJcUukdJ7n5MJOhRgEeOimn5MF6zDr5j4t2YtxEP59A1nk5mDup82qVr YkHH9Mw9OB1vrf9FOow+/uY= X-Received: by 2002:a62:1b50:: with SMTP id b77mr46166253pfb.36.1549164635217; Sat, 02 Feb 2019 19:30:35 -0800 (PST) Received: from myunghoj-Precision-5530 (cpe-76-176-3-80.san.res.rr.com. [76.176.3.80]) by smtp.gmail.com with ESMTPSA id z62sm22276974pfi.4.2019.02.02.19.30.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Feb 2019 19:30:35 -0800 (PST) Date: Sat, 2 Feb 2019 19:30:32 -0800 From: Myungho Jung To: Marcel Holtmann Cc: Johan Hedberg , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] Bluetooth: hci_uart: Switch pty driver to slave side in tty_set_termios() Message-ID: <20190203033032.GA21013@myunghoj-Precision-5530> References: <20190202072816.GA15630@myunghoj-Precision-5530> <3EC8C1C2-27AE-46B7-A345-860A87B94E6B@holtmann.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3EC8C1C2-27AE-46B7-A345-860A87B94E6B@holtmann.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 02, 2019 at 01:15:16PM +0100, Marcel Holtmann wrote: > Hi Myungho, > > > tty_set_termios() should be called with slave side of pty driver. So, If > > tty driver is pty master, it needs to be switched to ->link. > > > > Reported-by: syzbot+a950165cbb86bdd023a4@syzkaller.appspotmail.com > > Signed-off-by: Myungho Jung > > --- > > drivers/bluetooth/hci_ldisc.c | 27 ++++++++++++++++++++++----- > > 1 file changed, 22 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c > > index fbf7b4df23ab..0f6e70ea1dc3 100644 > > --- a/drivers/bluetooth/hci_ldisc.c > > +++ b/drivers/bluetooth/hci_ldisc.c > > @@ -299,10 +299,21 @@ static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb) > > return 0; > > } > > > > +/* If pty master, return slave side */ > > +static struct tty_struct *hci_uart_get_real_tty(struct tty_struct *tty) > > +{ > > + if (tty->driver->type == TTY_DRIVER_TYPE_PTY && > > + tty->driver->subtype == PTY_TYPE_MASTER) > > + tty->link; > > + > > + return tty; > > +} > > + > > /* Flow control or un-flow control the device */ > > void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) > > { > > struct tty_struct *tty = hu->tty; > > + struct tty_struct *real_tty; > > struct ktermios ktermios; > > int status; > > unsigned int set = 0; > > @@ -314,11 +325,14 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) > > return; > > } > > > > + /* termios should be set from slave side if tty driver is pty */ > > + real_tty = hci_uart_get_real_tty(tty); > > + > > if (enable) { > > /* Disable hardware flow control */ > > - ktermios = tty->termios; > > + ktermios = real_tty->termios; > > ktermios.c_cflag &= ~CRTSCTS; > > - status = tty_set_termios(tty, &ktermios); > > + status = tty_set_termios(real_tty, &ktermios); > > BT_DBG("Disabling hardware flow control: %s", > > status ? "failed" : "success"); > > > > @@ -350,9 +364,9 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) > > BT_DBG("Setting RTS: %s", status ? "failed" : "success"); > > > > /* Re-enable hardware flow control */ > > - ktermios = tty->termios; > > + ktermios = real_tty->termios; > > ktermios.c_cflag |= CRTSCTS; > > - status = tty_set_termios(tty, &ktermios); > > + status = tty_set_termios(real_tty, &ktermios); > > BT_DBG("Enabling hardware flow control: %s", > > status ? "failed" : "success"); > > } > > @@ -367,9 +381,12 @@ void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, > > > > void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed) > > { > > - struct tty_struct *tty = hu->tty; > > + struct tty_struct *tty; > > struct ktermios ktermios; > > > > + /* termios should be set from slave side if tty driver is pty */ > > + tty = hci_uart_get_real_tty(hu->tty); > > + > > didn’t we conclude that allowing the HCI line discipline on a PTY master isn't worth the effort? The ptm_unix98_ops doesn’t have the .set_termios and thus, just check that ops->set_termios is present in hci_uart_tty_open and if not fail with EOPNOTSUPP like we do for missing ops->write. > > Regards > > Marcel > Hi Marcel, I thought there might be some cases that reach here even returning error in hci_uart_tty_open(). Let me fix it from hci_uart_tty_open. Thanks, Myungho