Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp830581pxu; Mon, 23 Nov 2020 05:24:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxycx4oLCEIExMPJxW3MDuMvOtPvwXBCLP9Wne1lKuX7hAk2fRH1xKmoFO74i7ojjVPT9fb X-Received: by 2002:aa7:cb4c:: with SMTP id w12mr46747800edt.309.1606137858218; Mon, 23 Nov 2020 05:24:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606137858; cv=none; d=google.com; s=arc-20160816; b=G245thDq8iAUvC3Zv1qFqbgbQgu7C0oac9GxtrSU+288OJ8xpYsM3q77Dcr/E67J+o GbYbyYWkJFsXD5itBYT50GFnyt7oxkoZvVkgtieoJdAmiF/aTJ6C5pNw8jCUCbtviGFs lREd19EpXhMMnQcurFFDI8orhTfXqg9TLe5rxh6/1cqFJJ+wBwgvP/pSN7xEOCmvZdFO h1S4v5Gj1w0udVXiZ/2PSO2e3cQuoh6QVZqbOheZdrIfK6b1udb5lFV5M50o/CdLoAak xHBEqzv/iFfmx90ofK5SwFXpC0yQzzn6h+UNDkaX2SJ/i1nFThwM9J2kzI0FP5qrplrh Oq3g== 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:dkim-signature; bh=Ekb34xa+FW3sQjyn62uw8/WR5/snXmlKlPcTSW5xyqo=; b=LUMnJWUBga0AhvxqYHjTyHK2gPSXeVfReYmpB/cgwGsybxo1jIficmnc4YTImkEFFb kJAtWlg6Rwgy0AuTFngWXyvXam/eBj64fbTHXvfMZnkm8iFNxMPNiTc6I+Aop2vyq0cO 16MhYeRTsk6WEB7iV0qQ8oeo79iqdyft+Sft1/B4OWyV570ikCYgePCRzCO/8y1erFN3 Ai33ln/CJ4wtP8fK0ofdgj+ntKyQaZCNEONPFYAPwHK5MDJ4KXsdIQNa7QPuVWHW/Hs0 YIi2dsOQEB2Y7fj7TkFYbsvHNy8zkiDTdeinW76o4P0UBmtEyhOtQAi4s9wmcYiXhVGt Mn+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pHNLca9G; 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=pass (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 cf17si5325185ejb.541.2020.11.23.05.23.51; Mon, 23 Nov 2020 05:24:18 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pHNLca9G; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732252AbgKWMjZ (ORCPT + 99 others); Mon, 23 Nov 2020 07:39:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:51566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732148AbgKWMi4 (ORCPT ); Mon, 23 Nov 2020 07:38:56 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B88920732; Mon, 23 Nov 2020 12:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135134; bh=S8qnBqdIWsjGrOzv3NoC7r6Vj3YqVQD4bARnwBc9ugI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pHNLca9G+QUia5i83SWiNHYn5YE250jCSEthbRGkz1UVU/vilfsj83uJOUM1WtHQB 5zatLIBAmGZ2fYqJRO6GxEKqR7S12pE888/oK2B9nP+lINdiRJzdqjkFSP64DcWt0o SvP4k3vfl0ESSHJj3lJlZ9W1r2c6Iu0Vvh4hMdyU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?=E7=A7=A6=E4=B8=96=E6=9D=BE?= , Samuel Thibault Subject: [PATCH 5.4 116/158] speakup: Do not let the line discipline be used several times Date: Mon, 23 Nov 2020 13:22:24 +0100 Message-Id: <20201123121825.536879124@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@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 d4122754442799187d5d537a9c039a49a67e57f1 upstream. Speakup has only one speakup_tty variable to store the tty it is managing. This makes sense since its codebase currently assumes that there is only one user who controls the screen reading. That however means that we have to forbid using the line discipline several times, otherwise the second closure would try to free a NULL ldisc_data, leading to general protection fault: 0000 [#1] SMP KASAN PTI RIP: 0010:spk_ttyio_ldisc_close+0x2c/0x60 Call Trace: tty_ldisc_release+0xa2/0x340 tty_release_struct+0x17/0xd0 tty_release+0x9d9/0xcc0 __fput+0x231/0x740 task_work_run+0x12c/0x1a0 do_exit+0x9b5/0x2230 ? release_task+0x1240/0x1240 ? __do_page_fault+0x562/0xa30 do_group_exit+0xd5/0x2a0 __x64_sys_exit_group+0x35/0x40 do_syscall_64+0x89/0x2b0 ? page_fault+0x8/0x30 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Cc: stable@vger.kernel.org Reported-by: 秦世松 Signed-off-by: Samuel Thibault Tested-by: Shisong Qin Link: https://lore.kernel.org/r/20201110183541.fzgnlwhjpgqzjeth@function Signed-off-by: Greg Kroah-Hartman --- drivers/staging/speakup/spk_ttyio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/drivers/staging/speakup/spk_ttyio.c +++ b/drivers/staging/speakup/spk_ttyio.c @@ -49,15 +49,25 @@ static int spk_ttyio_ldisc_open(struct t if (!tty->ops->write) 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) + if (!ldisc_data) { + speakup_tty = NULL; + mutex_unlock(&speakup_tty_mutex); return -ENOMEM; + } init_completion(&ldisc_data->completion); ldisc_data->buf_free = true; speakup_tty->disc_data = ldisc_data; + mutex_unlock(&speakup_tty_mutex); return 0; }