Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp163434pxu; Thu, 10 Dec 2020 22:13:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2Mu1Hdi2hpCsPfMgLD6V7GBVqx9PXrmKikXVQj+yitH/+7q/LcTBrVQOmkYRaC761NmEb X-Received: by 2002:aa7:c353:: with SMTP id j19mr10202501edr.204.1607667194398; Thu, 10 Dec 2020 22:13:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607667194; cv=none; d=google.com; s=arc-20160816; b=HZpym+BeQo6i6ir2GZQLZa4hUslQlTLbyCIx0bSnnqvf5uJmt4myDIWcsyqL91TMx8 PaE9okCz8eS63OD2hk2t+yCqPbqWRoNKi5NiaQf3nYHKiXnko6ml3d5fHqDdbZ6Pllzg hSEFfDkB+V19wzJLkHkof0upUJFiYfs85f1Mh1h83GdnzONbfJ3yy5rtoHtKf+h2I3+2 8DZ0XSVPAVqzlv+3LAte774p4yQgQy9B2jz4O5DXqEpzJB/3ZqL5SfDhhJenXGck+DbB c/jenjDG+yOZWOQjle5jYJOCSd7Lm2UyqbAzhsojvGgNd3+qGZH8VxIqo8zXgcxhLo9I uH0A== 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=xt3XKKnUO62f/W6XcWG4xTmAtV7Fq30dArO8+2fTzTo=; b=z5wNZBIY8D7XuOMV9Oxo79k+7KmZ9fFOxe856BbOYOjQOwkeSgceAjq2hfxTJ64vB6 UL3TeLZD0uM/WHJe67vGRC5jQyjwD059T/vYjkQ57o2JerkeQGe/1snDlOYL8RVEdv+A LjLTyiL+HewgZyYr8RGCwBJ0KE3ENV/o/1MapHiXp0ISVvl2iR6ppCZS0+14YgMQmwpr 0w+NJQLPGyOUX98QsZ68f1z7gGeXaRzV0nT4rKKg0ePpppX5QhMDmI1+++DgP/j7cyY6 45dydATYZcFwCHxtoh+x2u4w+mAfd5C0auvQQ5OeMSXEbQADLLsRKit2Uv0vSgbMV9Wq miqA== 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 mm17si3851370ejb.131.2020.12.10.22.12.51; Thu, 10 Dec 2020 22:13:14 -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 S2388963AbgLJOiC (ORCPT + 99 others); Thu, 10 Dec 2020 09:38:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:42400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390809AbgLJOeX (ORCPT ); Thu, 10 Dec 2020 09:34:23 -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.19 27/39] speakup: Reject setting the speakup line discipline outside of speakup Date: Thu, 10 Dec 2020 15:27:06 +0100 Message-Id: <20201210142603.605722932@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.272595094@linuxfoundation.org> References: <20201210142602.272595094@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 | 37 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) --- a/drivers/staging/speakup/spk_ttyio.c +++ b/drivers/staging/speakup/spk_ttyio.c @@ -47,27 +47,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); + 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; } @@ -187,9 +180,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; }