Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6631005rwb; Tue, 9 Aug 2022 20:37:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4pBfW0e8tKLxshsbyqPVyNHvIWSaq9KDKzFej4v2OTl2QN23EW0nzRce5WM9drGkkMWcRf X-Received: by 2002:a17:906:974d:b0:732:e3d8:ec6c with SMTP id o13-20020a170906974d00b00732e3d8ec6cmr4031585ejy.602.1660102630278; Tue, 09 Aug 2022 20:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660102630; cv=none; d=google.com; s=arc-20160816; b=aUxfAYMjRY3IXQFf5UssxyCkuPsIeAkFh+krrE7jDvseH6hS+6rPXAg25cJEBJ+Ngt gDyyeeZsVeC423N2wW/76j7InADYQOB101G9AspcAC06FzqFvvglv50LypZI+UCOKacv 0I7qmf5Fa+mvJxRTr3Z3HjZOg0bsaa9QoYmJoxs+T03jNEOkk3uqgX2Gg06/0SGbAADQ Et9s+HeWcln1oR6YfbcYrZgSFAlTaCX9j3Evl41S0UQPV+VWjoXvKI5HjXdzkAwsW7lY WMq2HZ6AWFEYtjD4QtHKafbCY0fVTlpH5vHc+mTVzYDGpeoghTF59Fh/1SEYy/YZOJZf oFKg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=84NRcLKFfe/6XQq15qNZMiBSNFJ+/AXaHO09WwjXOT0=; b=Ool9W0RD+8HP9K5yWLe5wPgr+sj9zC6gHYbtMsI25p50NfbqPTCk1Hx8B5Zr6wKPDc tY+jaAgtmTOJAHOGlEcAU0sMFjY6M0nVZ6DNGExdcsRmgKjvCVnpqitNHb6s9rmqiDIo EzDAQBB/Yi9Y44hmXtp2HgU38jKosuBL/kz0JkHMTEPWxq8IIeTPoWKX5cbt1rpPO0oC q0IjIRbmGbeTZkFqHXJgoSA/UMfNB+G8LKu42msfKKyWACec+6g/I4vBkakND5fcTzoI AOCKfhsbwz9f1WrNpDmWOAPK8KQwNulFoQW/xwwaBwSclNZCPE40VdPkOVxAJCnSAdL6 4o9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PrqePyJw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id er19-20020a056402449300b0043e64d81518si8274590edb.619.2022.08.09.20.36.45; Tue, 09 Aug 2022 20:37:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PrqePyJw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229490AbiHJDVb (ORCPT + 99 others); Tue, 9 Aug 2022 23:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbiHJDUv (ORCPT ); Tue, 9 Aug 2022 23:20:51 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFC99647CC for ; Tue, 9 Aug 2022 20:16:46 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v3so16356659wrp.0 for ; Tue, 09 Aug 2022 20:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=84NRcLKFfe/6XQq15qNZMiBSNFJ+/AXaHO09WwjXOT0=; b=PrqePyJw637rEQIgXaT5QRPPe8o+bbDEL8SJeUu+NzC/ASKCeew3qy5DdUr5Jrh8iN BDvJIsZtCJa6EyY4lqbG7Lbo/KvV0y2QqHhfDRhCpC/ZMwPQEv/2spQM6FFukn/3Hsyh 0LRW38JmCm3jdEh5uMQREhhdhoc5BqyGEq/mz/6KI44alJ7sffbjToVgrTUYTdkXXy80 qpcqPrtzkOEl4/4KJUQGUk8xwFfKK99En3egrrKrmbjPGlMppD0z/Z4KNDCrr7iranpi P3EZK+5MPIFMJe3A5iID2tNdkiB+tHElTRp/ierU2zSSrle/bckLJVm8BSr+UZL1Zdfd CDsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=84NRcLKFfe/6XQq15qNZMiBSNFJ+/AXaHO09WwjXOT0=; b=RWuR4BP0ZSDtA5m/MMXDYgtqfmFu4venGUpZFarF0ncWwKyQ27KG82kky1unGggVdj mK2MrNp65NZiefSRs7jCHzifX3JfBB1nWign1G/hK2IBqf9sbV+Lq7sf5lo+wqHP0KvU wv5x6aKOI/erecj9Bx4PUzRmgB3JF/CzXM3MAr53ylQDaEUpmoabBa9t/5lqQop6GZV4 E6hRfNGpLhSE42OP1roccdYHNQ+rBTkoExVQe1RAUY52D8GnQCiIumPwRytuZGPi1pX6 SOFqykasYWYI4z4Gy512Eo/q9f2Yb7N4NqpsXMQlRE/tvcraaxdXe/qyWv3s3JDWY2u/ B6iw== X-Gm-Message-State: ACgBeo2PVaE4j4cJgBB2QjfJaxhT8O9SjbcSXYaU2/wCcDE+mJeqtHY4 Dqpl6a+KvKWUpwfknQkFix8= X-Received: by 2002:a5d:64e2:0:b0:220:7dfb:ab6f with SMTP id g2-20020a5d64e2000000b002207dfbab6fmr15514382wri.664.1660101396774; Tue, 09 Aug 2022 20:16:36 -0700 (PDT) Received: from localhost.localdomain ([84.255.184.228]) by smtp.gmail.com with ESMTPSA id g11-20020a5d698b000000b0021eff2ecb31sm15575961wru.95.2022.08.09.20.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 20:16:36 -0700 (PDT) From: Mazin Al Haddad To: gregkh@linuxfoundation.org Cc: jirislaby@kernel.org, daniel.starke@siemens.com, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, skhan@linuxfoundation.org, paskripkin@gmail.com, Mazin Al Haddad , syzbot+e3563f0c94e188366dbb@syzkaller.appspotmail.com Subject: [PATCH] tty: n_gsm: fix missing assignment of gsm->receive() in gsmld_attach_gsm() Date: Wed, 10 Aug 2022 06:12:52 +0300 Message-Id: <20220810031251.91291-1-mazinalhaddad05@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixes a bug reported by syzbot. A null pointer dereference can happen when attempting to access the "gsm->receive()" function in gsmld_receive_buf(). Currently, the "gsm->receive()" function is only set after a call to the GSMIO_SETCONF ioctl. Since the gsmld_receive_buf() function can be accessed without the need to call the line discipline ioctl (GSMIO_SETCONF), the gsm->receive() function will not be set and a NULL pointer dereference will occur. Fix this by setting the gsm->receive() function when the line discipline is being attached to the terminal device, inside gsmld_attach_gsm(). This will guarantee that the function is assigned and a call to TIOCSTI, which calls gsmld_receive_buf(), will not reference a null pointer. 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 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 --- drivers/tty/n_gsm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index caa5c14ed57f..1d74dd9d70d0 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2825,6 +2825,11 @@ static void gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) /* Turn off tty XON/XOFF handling to handle it explicitly. */ gsm->old_c_iflag = tty->termios.c_iflag; tty->termios.c_iflag &= (IXON | IXOFF); + + if (gsm->encoding == 0) + gsm->receive = gsm0_receive; + else + gsm->receive = gsm1_receive; } /** -- 2.37.1