Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9982imu; Thu, 24 Jan 2019 19:56:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN5HQMPDTQqnJjayqzaRv+isf5B9CEGJOkUz1dhRIBsZfmRCA2Cjpb7oS/VtnOVUU0uesDVP X-Received: by 2002:a17:902:e28e:: with SMTP id cf14mr9472633plb.311.1548388617391; Thu, 24 Jan 2019 19:56:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548388617; cv=none; d=google.com; s=arc-20160816; b=lCJJav47LApAEgR3awKMcOR0HF9CV7xK1K1HoGKn7Q/OFs00BZRVs12nwvTOktq4a4 /TTtDolQTTHZkqylQ7VDem3fEbYzl7Q1vCWI/Dcd4U+sXrkLAF6auRGDWgQ37N23uJYa ySjlvKUCLwJNisipdCnJw3UMKtqENA+3MQIJ6v3qqQ8+mXDkx/xxmzlBSRGFc+h+qJKA Wn4OsyX6/XELZ6PZkKy3cAQ7YKQF1dPlhzT0m1X3zDHVKY+sE0inJz98nbfUyh4Al9xX bmWJMSYQhxXvHxu+Ai+S3R0kr56jNC1OyUcZpLezQ19AZZ6cywj9NpjKQeHQhklSPtQp RL8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=Cybw0B3smWl3ggaY2rGioXhyGSgdUMHQ0vjwYWmqmf0=; b=T3Dip4KE0QEw/8SU8V1EbA06isH2s3WAglzqq61SgCrDh0fPSkt3ADOgo9wLsJ11Mv iPI5INcO6YL9kG6nz7ehrLhYZUMpFMZBxikcJoN7pyv7opXxm+guimiz7T9SeqTr74by C6+A9WZUcvtf8TOIIDuojrHeuIh9I2s4+Iu4RdiY3eIxHcw4K3WoTdiGdl9UEB+0ZduM 13mbIkySU3EGTnLyyW0bO11PjLVXvAJPf4rzdN9r0d2NP44KmK28CMPw7zHPyIzIECDM kR4LZjixAj5DedwcNICQdQ4t1zrCm32xboR53HQJ5ObKdR5JDXI2/SDs1lH11AMWc5Os 3zZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GVWkWsJN; 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 d127si22703705pfg.255.2019.01.24.19.56.41; Thu, 24 Jan 2019 19:56:57 -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=GVWkWsJN; 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 S1728895AbfAYDzR (ORCPT + 99 others); Thu, 24 Jan 2019 22:55:17 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39607 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbfAYDzQ (ORCPT ); Thu, 24 Jan 2019 22:55:16 -0500 Received: by mail-pf1-f193.google.com with SMTP id r136so4090315pfc.6; Thu, 24 Jan 2019 19:55:16 -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:mime-version:content-disposition :user-agent; bh=Cybw0B3smWl3ggaY2rGioXhyGSgdUMHQ0vjwYWmqmf0=; b=GVWkWsJNMgzCrXLMTjpxfZpFJ5zk5a3yPOROBFpUjCyFTd6OebkvUS6jeX/WU8HbPt a3VFZBLx6Ll4TWwqnGNEdCndAlQ7zw6Qyb2CMJY8UR/lCYXxGSRbCOu9/OJ34o3yIJeo sZ2vvXfkcV3bAM2ZYVsiiP93u9xyr8b02Z8JtWuAvN3HKcbBh0c4LE9Ay3n96rfG/1wh qWUb8n9To8dEACaeIGZmuqzIWyP3NgLNXNTneUCs3G4sJLRAFBaMTcWprKMvmBk4syzV OrsWxxXoqGF2UT/QOKNQ5BmA2TQqGkr2MQxc37tBFiOCAa5rl+QABQ5qxU/IQI1nlKXW nRhg== 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:mime-version :content-disposition:user-agent; bh=Cybw0B3smWl3ggaY2rGioXhyGSgdUMHQ0vjwYWmqmf0=; b=mDQtEnJ9vNfsR6r6hxar4brfFi4ye1VvO1Wodf2/5e2AiWRK2bOKSdQziRdpeIeiCD 4yi4MQjElG+cI3MrVmVSknoLozxJn/FBWp1UEIy5/DAwfCEV19TYbDIWbseaP+PnRXYE fHdsP1t62hB4vUElCLAKnG+tm52vVJV565g69CI6ACsO900sWS1Ih07MKVHd4IfLkINf NCOgOvn18s6hbcUjBeYF6WamcfhaMmazAhrj6frkc9AGF7fuQ7KUtS7y4ud6KTbIsS9+ xB3mpQg0uLXTKic4bbHQyiRRzdrU3ka/HBongqgsr0oIEOOoJDJSzrQ/iz1NlgoHvjPl 4Y/Q== X-Gm-Message-State: AJcUukeXri2jzLKKy1OsHmhZ8tpU1R7qLVCej2lO4SxJ/rcnTE2Z5p0o BF8GerOUvOZWTDDiCzp9u/7J1Aj1 X-Received: by 2002:a63:2586:: with SMTP id l128mr8671573pgl.104.1548388515745; Thu, 24 Jan 2019 19:55:15 -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 i193sm77952257pgc.22.2019.01.24.19.55.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Jan 2019 19:55:15 -0800 (PST) Date: Thu, 24 Jan 2019 19:55:12 -0800 From: Myungho Jung To: Marcel Holtmann , Johan Hedberg Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: hci_ldisc: Fix for pty driver Message-ID: <20190125035510.GA21654@myunghoj-Precision-5530> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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. Also, tiocmget() and tiocmset() operations are optional so we need NULL check for some drivers missing the operations like pty. Reported-by: syzbot+a950165cbb86bdd023a4@syzkaller.appspotmail.com Signed-off-by: Myungho Jung --- drivers/bluetooth/hci_ldisc.c | 76 +++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index fbf7b4df23ab..169dde91b3d3 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,45 +322,52 @@ 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"); - /* Clear RTS to prevent the device from sending */ - /* Most UARTs need OUT2 to enable interrupts */ - status = tty->driver->ops->tiocmget(tty); - BT_DBG("Current tiocm 0x%x", status); - - set &= ~(TIOCM_OUT2 | TIOCM_RTS); - clear = ~set; - set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | - TIOCM_OUT2 | TIOCM_LOOP; - clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | - TIOCM_OUT2 | TIOCM_LOOP; - status = tty->driver->ops->tiocmset(tty, set, clear); - BT_DBG("Clearing RTS: %s", status ? "failed" : "success"); + if (tty->driver->ops->tiocmget && tty->driver->ops->tiocmset) { + /* Clear RTS to prevent the device from sending */ + /* Most UARTs need OUT2 to enable interrupts */ + status = tty->driver->ops->tiocmget(tty); + BT_DBG("Current tiocm 0x%x", status); + + set &= ~(TIOCM_OUT2 | TIOCM_RTS); + clear = ~set; + set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | + TIOCM_OUT2 | TIOCM_LOOP; + clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | + TIOCM_OUT2 | TIOCM_LOOP; + status = tty->driver->ops->tiocmset(tty, set, clear); + BT_DBG("Clearing RTS: %s", status ? "failed" : + "success"); + } } else { - /* Set RTS to allow the device to send again */ - status = tty->driver->ops->tiocmget(tty); - BT_DBG("Current tiocm 0x%x", status); - - set |= (TIOCM_OUT2 | TIOCM_RTS); - clear = ~set; - set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | - TIOCM_OUT2 | TIOCM_LOOP; - clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | - TIOCM_OUT2 | TIOCM_LOOP; - status = tty->driver->ops->tiocmset(tty, set, clear); - BT_DBG("Setting RTS: %s", status ? "failed" : "success"); + if (tty->driver->ops->tiocmget && tty->driver->ops->tiocmset) { + /* Set RTS to allow the device to send again */ + status = tty->driver->ops->tiocmget(tty); + BT_DBG("Current tiocm 0x%x", status); + + set |= (TIOCM_OUT2 | TIOCM_RTS); + clear = ~set; + set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | + TIOCM_OUT2 | TIOCM_LOOP; + clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | + TIOCM_OUT2 | TIOCM_LOOP; + status = tty->driver->ops->tiocmset(tty, set, clear); + 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 +382,10 @@ 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; + tty = hci_uart_get_real_tty(hu->tty); ktermios = tty->termios; ktermios.c_cflag &= ~CBAUD; tty_termios_encode_baud_rate(&ktermios, speed, speed); -- 2.17.1