Message ID | 20230914051507.3240-1-daniel.starke@siemens.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp295149vqi; Thu, 14 Sep 2023 05:04:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyVTRlhcIqZEtt7IvlOaej5kp3+MNObeS0s8oxt3rTE6yyEw3SDqifqjwY1zpzazqtMDok X-Received: by 2002:a05:6871:68e:b0:1d5:34ea:6b88 with SMTP id l14-20020a056871068e00b001d534ea6b88mr5792116oao.28.1694693058359; Thu, 14 Sep 2023 05:04:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694693058; cv=none; d=google.com; s=arc-20160816; b=HkegMWTP/mr6AjwGPn4Y3UKMuHQVYMhyBB2ehpvEOGWtrTRH1lKOFPLvaRmUN0MQQt mYd8EBBFZtfIK41yq2hvcXrCkyqRsRajRokO1QjyoTIaANcp1npjL2A+xUqDMaup1JNV SodDxvcIPnNdONtzWwbGpHDUzLMKQ6t4Jf708JYvge5Il7nHf0jk/nBRSDDYfSznN0AN dWV8r3zjUOSOr6lpQxY8wxiQ/u2ODXCKhOlzdszttvea0kQO0Ox4TVxP759V3U/eMeys ZQOVmUpPKRvoJ1BAnMtfkd1CQ7c2IzxtJ6+ybx3qipaykRLyMuA32k6GAlk5Y3rdTig7 G35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=gZzddzoCMxHTB8tXxt4nFUsRH1Ri6FrsG2SDJTbPMf8=; fh=ozRB2LB6M5QyCNJfWJmG3paWGJhVvnEfbqIFqTzEumw=; b=e0vgoW7CpvnROdVqP+XVo4U8ka+bUgc0jkbVXyJFCwYIlgs3fye0IMRpyzSJsst1f8 +aIeLvWmabg7cQG/pkOml+YCRCFQxl5c1SZsCZNfS39+1hvX7CAfeF2/J8C8Jy8oNeKd 10qqUCEdcRDmokzkiKdnU8qBey6trgtgBBAO8Hdp15ue5jkl/1EjK46gDKcxOTgCXZwM sS+rjvLuKzuUGgBdQEo8kQ5swxH01fQoG+KlTopUn5hNR6YYlyPBBGR+Lc+OZgf9Tw7e kq4/AxAXyaXlM72Wy++2YwuGRKQKYlLj1g58Avm2xauKTrANg+qk70gH4xjtkw6dMGZO 8U7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b="KYKJ7ov/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f7-20020a655507000000b0055793097dbesi1376014pgr.469.2023.09.14.05.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:04:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@siemens.com header.s=fm1 header.b="KYKJ7ov/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id DF2C381DFD72; Wed, 13 Sep 2023 22:16:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234720AbjINFQk (ORCPT <rfc822;chrisfriedt@gmail.com> + 35 others); Thu, 14 Sep 2023 01:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234197AbjINFQi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 14 Sep 2023 01:16:38 -0400 Received: from mta-64-228.siemens.flowmailer.net (mta-64-228.siemens.flowmailer.net [185.136.64.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF9721BCF for <linux-kernel@vger.kernel.org>; Wed, 13 Sep 2023 22:16:33 -0700 (PDT) Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 202309140516316b578876157cef1ed1 for <linux-kernel@vger.kernel.org>; Thu, 14 Sep 2023 07:16:31 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=daniel.starke@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc; bh=gZzddzoCMxHTB8tXxt4nFUsRH1Ri6FrsG2SDJTbPMf8=; b=KYKJ7ov/T2XaL6vsynXP+1JVPCCad16UuTf2C1IZQxkQeA69EG9YgLEtKlMD/ey9UPJ+PY 68a1TYHo1CcrJxYrDXbJaOfr3WKjv94RJvM/+pbnDNRvhPvEdNi8hMgTMVOeAWoo7qKoSSHW sQOAEqymDHOaLNqWRsxEGSz8mvYIo=; From: "D. Starke" <daniel.starke@siemens.com> To: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com Cc: linux-kernel@vger.kernel.org, hedonistsmith@gmail.com, Daniel Starke <daniel.starke@siemens.com> Subject: [PATCH 1/1] Revert "tty: n_gsm: fix UAF in gsm_cleanup_mux" Date: Thu, 14 Sep 2023 07:15:07 +0200 Message-Id: <20230914051507.3240-1-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-314044:519-21489:flowmailer Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 22:16:47 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777014468533708360 X-GMAIL-MSGID: 1777014468533708360 |
Series |
[1/1] Revert "tty: n_gsm: fix UAF in gsm_cleanup_mux"
|
|
Commit Message
D. Starke
Sept. 14, 2023, 5:15 a.m. UTC
From: Daniel Starke <daniel.starke@siemens.com> This reverts commit 9b9c8195f3f0d74a826077fc1c01b9ee74907239. The commit above is reverted as it did not solve the original issue. gsm_cleanup_mux() tries to free up the virtual ttys by calling gsm_dlci_release() for each available DLCI. There, dlci_put() is called to decrease the reference counter for the DLCI via tty_port_put() which finally calls gsm_dlci_free(). This already clears the pointer which is being checked in gsm_cleanup_mux() before calling gsm_dlci_release(). Therefore, it is not necessary to clear this pointer in gsm_cleanup_mux() as done in the reverted commit. The commit introduces a null pointer dereference: <TASK> ? __die+0x1f/0x70 ? page_fault_oops+0x156/0x420 ? search_exception_tables+0x37/0x50 ? fixup_exception+0x21/0x310 ? exc_page_fault+0x69/0x150 ? asm_exc_page_fault+0x26/0x30 ? tty_port_put+0x19/0xa0 gsmtty_cleanup+0x29/0x80 [n_gsm] release_one_tty+0x37/0xe0 process_one_work+0x1e6/0x3e0 worker_thread+0x4c/0x3d0 ? __pfx_worker_thread+0x10/0x10 kthread+0xe1/0x110 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2f/0x50 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1b/0x30 </TASK> The actual issue is that nothing guards dlci_put() from being called multiple times while the tty driver was triggered but did not yet finished calling gsm_dlci_free(). Signed-off-by: Daniel Starke <daniel.starke@siemens.com> --- drivers/tty/n_gsm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) I plan to create a bug report for this issue around next month as I have no solution for this at hand.
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index b3550ff9c494..1f3aba607cd5 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -3097,10 +3097,8 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) gsm->has_devices = false; } for (i = NUM_DLCI - 1; i >= 0; i--) - if (gsm->dlci[i]) { + if (gsm->dlci[i]) gsm_dlci_release(gsm->dlci[i]); - gsm->dlci[i] = NULL; - } mutex_unlock(&gsm->mutex); /* Now wipe the queues */ tty_ldisc_flush(gsm->tty);