Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp502034pxu; Fri, 11 Dec 2020 07:22:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXHtsn4DTvQ4Qf7LkGyGVTUjtpF17JO/q4+uIC0p/gLnpoSwRYVo9+x246aYbF8MLFGk61 X-Received: by 2002:a17:906:ce23:: with SMTP id sd3mr11427464ejb.69.1607700171284; Fri, 11 Dec 2020 07:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607700171; cv=none; d=google.com; s=arc-20160816; b=c2hG1gZbUd+5KkWfeSxjPH8p/h2NDLMC1gW683/AK3Ud7T/mvq9lKzkcXJPl90zEPI dRNRmyRAauc+YTpQrgF1cqhNhw+c3BCmY7X27ExgZVmWgn6s3vk4jYw1l4+TbITj0ie2 OAWOcGQX7Cak/SEJ6EqnuoCt3SokaTkgMhAyH9mBitLmEjXPdCK37fx0xDUzBygn8eFq uqJug0oSJYiBx2MlyZD/Sve7ZC2OL+HFqOsGIiTr5vIc7uJWos9WxY44ORl3QaKplafB fWPNR9Na3N8hODEMhXL78LInPpXUGr+DsGSTdqHOXtQi1JtxoeZOGqa1Q9lUN/gUkyrT 4FeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=qzkLuU4v7hvY/R3eHEMGomAgdm08Qeu+6u3TQVfS+DM=; b=cYZVU0+mM4h3CxKlbxJtao25qobAlEC5Vb0OZIPa597LivhJ7cftUU9UpeX7SA2WmL a+rh29ulh0zgJ+Gj5JdIiD0XTFMMruh3ux8mxDOsU9mVKMTypNwvctFZEjp0EJblAF/R dSblVoHlGZK8665aXgB3FfJDc9cc2qIzZe+OXqHoLyO1eBX82miULVdgbHPZYt0fYbQT WajdDCaTmZtXhsx6XypI27QOyzIp0o+D2TG0wD303id+ZiudEauVO9hGniWi3wx6kH3u LmqQSbpUescylixO1wgh/w3FMdRqS70eVUiCvofb41nqc7c90SPc1giqexAZokUgw6n1 uPag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd3si4808895edb.589.2020.12.11.07.22.26; Fri, 11 Dec 2020 07:22:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393145AbgLJSuw (ORCPT + 99 others); Thu, 10 Dec 2020 13:50:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:39508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389254AbgLJOb6 (ORCPT ); Thu, 10 Dec 2020 09:31:58 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shisong Qin , Samuel Thibault Subject: [PATCH 4.14 21/31] speakup: Reject setting the speakup line discipline outside of speakup Date: Thu, 10 Dec 2020 15:26:58 +0100 Message-Id: <20201210142603.152343956@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.099683598@linuxfoundation.org> References: <20201210142602.099683598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Samuel Thibault commit f0992098cadb4c9c6a00703b66cafe604e178fea upstream. Speakup exposing a line discipline allows userland to try to use it, while it is deemed to be useless, and thus uselessly exposes potential bugs. One of them is simply that in such a case if the line sends data, spk_ttyio_receive_buf2 is called and crashes since spk_ttyio_synth is NULL. This change restricts the use of the speakup line discipline to speakup drivers, thus avoiding such kind of issues altogether. Cc: stable@vger.kernel.org Reported-by: Shisong Qin Signed-off-by: Samuel Thibault Tested-by: Shisong Qin Link: https://lore.kernel.org/r/20201129193523.hm3f6n5xrn6fiyyc@function Signed-off-by: Greg Kroah-Hartman --- drivers/staging/speakup/spk_ttyio.c | 38 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) --- a/drivers/staging/speakup/spk_ttyio.c +++ b/drivers/staging/speakup/spk_ttyio.c @@ -46,28 +46,20 @@ static int spk_ttyio_ldisc_open(struct t { struct spk_ldisc_data *ldisc_data; + if (tty != speakup_tty) + /* Somebody tried to use this line discipline outside speakup */ + return -ENODEV; + if (tty->ops->write == NULL) return -EOPNOTSUPP; - mutex_lock(&speakup_tty_mutex); - if (speakup_tty) { - mutex_unlock(&speakup_tty_mutex); - return -EBUSY; - } - speakup_tty = tty; - ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL); - if (!ldisc_data) { - speakup_tty = NULL; - mutex_unlock(&speakup_tty_mutex); - pr_err("speakup: Failed to allocate ldisc_data.\n"); + if (!ldisc_data) return -ENOMEM; - } sema_init(&ldisc_data->sem, 0); ldisc_data->buf_free = true; - speakup_tty->disc_data = ldisc_data; - mutex_unlock(&speakup_tty_mutex); + tty->disc_data = ldisc_data; return 0; } @@ -184,9 +176,25 @@ static int spk_ttyio_initialise_ldisc(st tty_unlock(tty); + mutex_lock(&speakup_tty_mutex); + speakup_tty = tty; ret = tty_set_ldisc(tty, N_SPEAKUP); if (ret) - pr_err("speakup: Failed to set N_SPEAKUP on tty\n"); + speakup_tty = NULL; + mutex_unlock(&speakup_tty_mutex); + + if (!ret) + /* Success */ + return 0; + + pr_err("speakup: Failed to set N_SPEAKUP on tty\n"); + + tty_lock(tty); + if (tty->ops->close) + tty->ops->close(tty, NULL); + tty_unlock(tty); + + tty_kclose(tty); return ret; }