From patchwork Tue Dec 12 11:17:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavrilov Ilia X-Patchwork-Id: 177266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7651069vqy; Tue, 12 Dec 2023 03:18:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgPhJJqs1ZPQj2cLijfGcwIDnNJu3ElgoIt5ttdQS2Xw0VCFp5c96H8lFqa+az9iAyRm5d X-Received: by 2002:a17:903:2988:b0:1d3:387c:f9b8 with SMTP id lm8-20020a170903298800b001d3387cf9b8mr166687plb.119.1702379880792; Tue, 12 Dec 2023 03:18:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702379880; cv=none; d=google.com; s=arc-20160816; b=dH6N/5ONjec5WSEmQzh2ZKPEyzzZpG6KJnanNxON41lTbbR5DKSTiX8/oThefv1+AM l2ZUpStPZ5V8ODwwsAVNiy/1KpOHZSKGtbaRbUhV0QRRhvEKtPstL2l4bSYiRtFLGSCC V/LGtdYWOhjE1hqAyaxDltz+ouNhgSFwEQ6cZyMDb3eftudDpjv06TjaQYyZxwzTzqD9 BDC/FXRQuuCobKGB6aZVdL66qaJMshDvPlHZRwQTlR9c7QgTr18gM59n/8Dj1WRi+MO6 /H5RisI4tj50u5PlkfMii7MVZ5uJzgr4bXJNpXBFsKJvOADnebTxjNuAELiXDBqUamn3 2Y4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-filter; bh=9bSZRvhCRx5ZJOxhq5dQQZcW3HOYwOVchaVahsGhmC4=; fh=u+G+CD1eYM6Vo3b8xzbHF1u8aVS/uLL7/k29XSHONQc=; b=xJJA1A6ZR4cPYKk7ArioySRfTQon9++I/DAd9H6QI6cOzpxQSnAgWZUJGxBco8Dx1R QaFtkPLoHzxHEcrILgK+4JKto71mGpXCuSTE6OF8rsNJbKiSus5ChfaMzZxCoi50Vl8x xMR06m2cebH00tAtkDcbAVeaspXTFR5fewan/H/KfOkTJmKfn6qKrUOn+oWeox8jGcvq IL0/1tvAbVsdKTO1TYLFO9wdlshJpBJSE/VV5VIeBa18XrCxfvi2PvMek1CNNpviZGpv 2LbdxdqE9xnK0PNsPmhYrheX5En2wzi9CH3RQKl0PTAEYb3t0i2NAy7b7Riyk3hXc74l vWnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=sUS+QwZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id o12-20020a170902bccc00b001cfb4d36d44si7487879pls.64.2023.12.12.03.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 03:18:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@infotecs.ru header.s=mx header.b=sUS+QwZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=infotecs.ru Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 35C9C80215FF; Tue, 12 Dec 2023 03:17:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346339AbjLLLRe (ORCPT + 99 others); Tue, 12 Dec 2023 06:17:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346326AbjLLLRX (ORCPT ); Tue, 12 Dec 2023 06:17:23 -0500 Received: from mx0.infotecs.ru (mx0.infotecs.ru [91.244.183.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C339EA for ; Tue, 12 Dec 2023 03:17:24 -0800 (PST) Received: from mx0.infotecs-nt (localhost [127.0.0.1]) by mx0.infotecs.ru (Postfix) with ESMTP id 29F5912012B4; Tue, 12 Dec 2023 14:17:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx0.infotecs.ru 29F5912012B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infotecs.ru; s=mx; t=1702379842; bh=9bSZRvhCRx5ZJOxhq5dQQZcW3HOYwOVchaVahsGhmC4=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=sUS+QwZS/BUI2i+pNguzOC3QXoOfVo8YH+i56eACSvkMkJzIts/9LltTnfytI91Qc C76Mxo6v1b4HQv07X//uQZVp4CaqDtpX3TOQ5ZLT3LQ9g+EGlFvagHhqb3jYYy6jV8 elrpT/F/ZgO3Cq2yYNtBtHUcmxMz7uCqGYjrv764= Received: from msk-exch-01.infotecs-nt (msk-exch-01.infotecs-nt [10.0.7.191]) by mx0.infotecs-nt (Postfix) with ESMTP id 25F4D316AAFE; Tue, 12 Dec 2023 14:17:22 +0300 (MSK) From: Gavrilov Ilia To: "stable@vger.kernel.org" , Greg Kroah-Hartman CC: Daniel Starke , Jiri Slaby , Russ Gorby , "linux-kernel@vger.kernel.org" , "lvc-project@linuxtesting.org" , "syzbot+e3563f0c94e188366dbb@syzkaller.appspotmail.com" , Mazin Al Haddad Subject: [PATCH 5.10 3/3] tty: n_gsm: add sanity check for gsm->receive in gsm_receive_buf() Thread-Topic: [PATCH 5.10 3/3] tty: n_gsm: add sanity check for gsm->receive in gsm_receive_buf() Thread-Index: AQHaLOzG6jNgFQFcyE2RxcW+B/dJcw== Date: Tue, 12 Dec 2023 11:17:21 +0000 Message-ID: <20231212111431.4064760-4-Ilia.Gavrilov@infotecs.ru> References: <20231212111431.4064760-1-Ilia.Gavrilov@infotecs.ru> In-Reply-To: <20231212111431.4064760-1-Ilia.Gavrilov@infotecs.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.17.0.10] x-exclaimer-md-config: 208ac3cd-1ed4-4982-a353-bdefac89ac0a MIME-Version: 1.0 X-KLMS-Rule-ID: 5 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Status: not scanned, disabled by settings X-KLMS-AntiSpam-Interceptor-Info: not scanned X-KLMS-AntiPhishing: Clean, bases: 2023/12/12 08:32:00 X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, bases: 2023/12/12 02:27:00 #22664189 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 03:17:58 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785074686007922252 X-GMAIL-MSGID: 1785074686007922252 From: Mazin Al Haddad commit f16c6d2e58a4c2b972efcf9eb12390ee0ba3befb upstream A null pointer dereference can happen when attempting to access the "gsm->receive()" function in gsmld_receive_buf(). Currently, the code assumes that gsm->receive is only called after MUX activation. Since the gsmld_receive_buf() function can be accessed without the need to initialize the MUX, the gsm->receive() function will not be set and a NULL pointer dereference will occur. Fix this by avoiding the call to "gsm->receive()" in case the function is not initialized by adding a sanity check. Call Trace: gsmld_receive_buf+0x1c2/0x2f0 drivers/tty/n_gsm.c:2861 tiocsti drivers/tty/tty_io.c:2293 [inline] tty_ioctl+0xa75/0x15d0 drivers/tty/tty_io.c:2692 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:870 [inline] __se_sys_ioctl fs/ioctl.c:856 [inline] __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Link: https://syzkaller.appspot.com/bug?id=bdf035c61447f8c6e0e6920315d577cb5cc35ac5 Fixes: 01aecd917114 ("tty: n_gsm: fix tty registration before control channel open") Reported-and-tested-by: syzbot+e3563f0c94e188366dbb@syzkaller.appspotmail.com Signed-off-by: Mazin Al Haddad Link: https://lore.kernel.org/r/20220814015211.84180-1-mazinalhaddad05@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Gavrilov Ilia --- drivers/tty/n_gsm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 2455f952e0aa..fa49529682ce 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2588,7 +2588,8 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, flags = *fp++; switch (flags) { case TTY_NORMAL: - gsm->receive(gsm, *cp); + if (gsm->receive) + gsm->receive(gsm, *cp); break; case TTY_OVERRUN: case TTY_BREAK: