Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5708100imu; Wed, 30 Jan 2019 02:10:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN4bOo19/C16I4upUWBR4BSATyH70h7tKv5T7acWpAgGLV985hLAxNwkqlBLvrq9L1uPwIuP X-Received: by 2002:a17:902:45:: with SMTP id 63mr28651972pla.272.1548843009013; Wed, 30 Jan 2019 02:10:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548843008; cv=none; d=google.com; s=arc-20160816; b=wqdIy78nhhtIcdWA9x5T6jN4lEGcwDKjrpcK9IxHShc3MkxqxvqXUYB/IE3h4yGYRD ux92Uq7Gw32w+OlVt2jOa6hQs8+t77iFsMlmJsa+tU1nuQqelyxr3PLdU4i2cyE+Wisu rjNXoJ4UFFyYzNYBFf0gpL5xtNgI5W7iZ9770HHMROI2XqSOfD3hHQErScntQsQgmR93 iktf7VM6pOv+Jrl00skNuttWMrybGb25K+VuhcgFRVl8Ce13nky5+PmzAgUoWeNF1pT6 ZIbZPHlkTvVe5GQ6d9PNHwGhANMnUKhKULa2vsVAi5S2goc+KWXqq6OpalUOeo3Q5NWK Wx4A== 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; bh=kN/2wSUiHLI2WtXBOwgOk4c/eaZ2luQazEMp69syOrg=; b=uGMC78/EsmdfrS4FAbkfzdrhrq9ZZ0wEfQiJdE28Ta17rXQk72WFQ495DgyVgEorNb M5krxV0+nq6ZD/fxyNPbL9Nmec4HWhJcm0kKoJQ1JydMOAQgczFgcD7ty3pY3chSiKzX qichz+E+g/7EDmJ+C/L4ShgR6SDWiAXtlhrLaC8oMaoDV9Cg3pQ612+0i+G34lecHXXT +t0XKqI5oQIyl3AmByg5rsXFUDatuN/fpdxg+y41h+zQdzhkEWAh7lgm4Nbh6JOuBuNe wKHBJeIlplFj+sZkqG8LcJtZCQQMK/Ia3mN8Yu/dFhUV2HNHOgL5ULWzSKL562fxVAI3 4kOw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si1086805plr.186.2019.01.30.02.09.53; Wed, 30 Jan 2019 02:10:08 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729299AbfA3KHq (ORCPT + 99 others); Wed, 30 Jan 2019 05:07:46 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41203 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726406AbfA3KHp (ORCPT ); Wed, 30 Jan 2019 05:07:45 -0500 Received: by mail-lj1-f194.google.com with SMTP id k15-v6so20164053ljc.8; Wed, 30 Jan 2019 02:07:44 -0800 (PST) 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=kN/2wSUiHLI2WtXBOwgOk4c/eaZ2luQazEMp69syOrg=; b=M7SmFJscLqKuyXAU7FbaI1uEiA5WWYQthvE/tijrbzjX6SID9ynPvSt6lvklYjotpR kLeFEt1lulru0Di7Sz7kl/e4t/Kc0/qS9XWygOfTZKkVmJW6vm0BxL22XO4w0xWKx/cn fB8/DY7JOWzw1S91pskcet02C8AhvEJaTVwkNHbeXL2OiIWUTQ5bYQTTXwfV/Vanr0Dr l4iQnXUzaMZn5/RtBxtgZXLCFze3Gigb7GA6iN0DWduWNwhZtJS4dvk8Igxja1m0+DlZ zeJjlzEck0CvREyG6u0s6jHbLAyzmQmjNaIH+MP6WO0BQ2MP5Z3Q8XFX9fLSbhw2KCHq 8NRQ== X-Gm-Message-State: AJcUukdP9BkCID7ZEhwLOlMlObAMMi4a/fQSNPPOQFBi47NBzDu+/8cz 74ApZdlUjYki9KzKJR4xwXw= X-Received: by 2002:a2e:86ca:: with SMTP id n10-v6mr21308598ljj.49.1548842862949; Wed, 30 Jan 2019 02:07:42 -0800 (PST) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id a18-v6sm195865ljk.86.2019.01.30.02.07.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 02:07:42 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1gommQ-0001EZ-8l; Wed, 30 Jan 2019 11:07:38 +0100 Date: Wed, 30 Jan 2019 11:07:38 +0100 From: Johan Hovold To: Myungho Jung Cc: Marcel Holtmann , Johan Hedberg , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Bluetooth: hci_uart: Switch pty driver to slave side in tty_set_termios() Message-ID: <20190130100738.GQ3691@localhost> References: <20190128065259.GA2976@myunghoj-Precision-5530> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190128065259.GA2976@myunghoj-Precision-5530> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 27, 2019 at 10:53:02PM -0800, Myungho Jung wrote: > 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. I'm not sure that's the right solution. PTYs are virtual devices used for IPC and neither end (master or slave) have support for modem control or baud rates. > Reported-by: syzbot+a950165cbb86bdd023a4@syzkaller.appspotmail.com > Signed-off-by: Myungho Jung > --- > drivers/bluetooth/hci_ldisc.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c > index fbf7b4df23ab..90c5ea8c399b 100644 > --- a/drivers/bluetooth/hci_ldisc.c > +++ b/drivers/bluetooth/hci_ldisc.c > @@ -299,10 +299,18 @@ static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb) > return 0; > } > > +/* If driver is pty master, return slave side */ > +static struct tty_struct *hci_uart_get_real_tty(struct tty_struct *tty) > +{ > + return (tty->driver->type == TTY_DRIVER_TYPE_PTY && > + tty->driver->subtype == PTY_TYPE_MASTER) ? tty->link : 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 +322,12 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) > return; > } > > + 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"); So instead of these pointless calls to set the slave termios and modem-control state, you might as well bail out early above (and similarly in set_baudrate()). Using n_hci for a master pty really makes no sense at all, so we could even bail out at ldisc open, but perhaps that can be discussed and addressed later. Johan