Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4450474rwb; Tue, 6 Sep 2022 07:43:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR5gXUZIf97AqUtaS3dj0WgRo1BToqnqHu6o0YoL1aQ6l4I9kk7uLIkevBQCsAb1iFsBT+c2 X-Received: by 2002:a17:907:2e19:b0:730:acf0:4924 with SMTP id ig25-20020a1709072e1900b00730acf04924mr38842777ejc.629.1662475395867; Tue, 06 Sep 2022 07:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662475395; cv=none; d=google.com; s=arc-20160816; b=Enh2hgtnNmrlr9tOB/XgXuQ/CQifks7dQnKzR2F7zY/kCDw5xaNKqs+zZn8WlH6BBC NfjsJFdpGB4i+A0vJzqPet+12VDsjAlUSCTRZ6J5bBkm0e2FbBzQh78YMaEmAM81gseH BJCd7pE+TqJkKqBQcIwk7oRHEhdy8iCQVKpP+Tn+xTeOG0AmyBSKGfq6BdmhKxIPf5b3 NJEx20TPCQ2F4KSu61raFASTWDzpbpK5iJR/j0Rjfv4dcTrggYq+J+9G/PkI5uVtFkEm 7LtqZq89ZNNKpR8EPNBeQKbAQ3NS2+4ugS8NJJ44AR4cSTb+MdU4plZyHO1lp5oPhyDl jqfQ== 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=3JPDEYLcREj1iA8ZY1B7AJ2F2ukbTvO5fs8K719z6ok=; b=i6FypaatTudBjffM9vZ/HDShli+3T+seDoTZe3leKj0A1QVBM9gooydw78d62f5h+e fhcbk58RMG9KSqLSkQKPKv9jeQ98QUdd6xVYuqCUuYuCgW2QVJ4E7cV41F02mR460Fya ziayYPyiZ/SrB7ePccoLnB14wfA54DwJLiYzeIOSv13ImMXjtxQwzNL4/29dGfNX5VUC iX9exXnqdnLxU1uyb9OlQLCH/6P0UBXjP+sEYUGYefUbcl436gZw50SuHmdTVlOYO5SI ZHxdOzrq3lwNKWeV+xYtLqs/jHnHOW2LDby4sOMDpPsWc9Uw38gZb95Ql6KFB7POkam2 thnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2TDqRWQN; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g10-20020a1709065d0a00b0076f00beeffasi2227429ejt.282.2022.09.06.07.42.50; Tue, 06 Sep 2022 07:43:15 -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=@linuxfoundation.org header.s=korg header.b=2TDqRWQN; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241884AbiIFORF (ORCPT + 99 others); Tue, 6 Sep 2022 10:17:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241731AbiIFON6 (ORCPT ); Tue, 6 Sep 2022 10:13:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3B69895D9; Tue, 6 Sep 2022 06:48:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A07DA61520; Tue, 6 Sep 2022 13:48:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC05BC433C1; Tue, 6 Sep 2022 13:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662472116; bh=2x4gxUdQIJg67nB1mfwUsfFq+F++aq5xL1H4TQZC3Sw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2TDqRWQN7wYBEx1VaTXysMEVnc2hu9PHph65Fh1G7/fi1CvjvebAp79J8nvXyw3BF 6rhI/liKh51Tl1q1H7149uSm3fQ+qc8VwTiWY0TsE2U7/zq3rBUJSeft7nsOIcqKcp UdA/g4HZXX3KJVmDo4IbklgucQboF0yRzoxQZNO0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , stable , Jiri Slaby , Tetsuo Handa Subject: [PATCH 5.19 153/155] tty: n_gsm: initialize more members at gsm_alloc_mux() Date: Tue, 6 Sep 2022 15:31:41 +0200 Message-Id: <20220906132835.860724113@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Tetsuo Handa commit 4bb1a53be85fcb1e24c14860e326a00cdd362c28 upstream. syzbot is reporting use of uninitialized spinlock at gsmld_write() [1], for commit 32dd59f96924f45e ("tty: n_gsm: fix race condition in gsmld_write()") allows accessing gsm->tx_lock before gsm_activate_mux() initializes it. Since object initialization should be done right after allocation in order to avoid accessing uninitialized memory, move initialization of timer/work/waitqueue/spinlock from gsmld_open()/gsm_activate_mux() to gsm_alloc_mux(). Link: https://syzkaller.appspot.com/bug?extid=cf155def4e717db68a12 [1] Fixes: 32dd59f96924f45e ("tty: n_gsm: fix race condition in gsmld_write()") Reported-by: syzbot Tested-by: syzbot Cc: stable Acked-by: Jiri Slaby Signed-off-by: Tetsuo Handa Link: https://lore.kernel.org/r/2110618e-57f0-c1ce-b2ad-b6cacef3f60e@I-love.SAKURA.ne.jp Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2501,13 +2501,6 @@ static int gsm_activate_mux(struct gsm_m if (dlci == NULL) return -ENOMEM; - timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); - timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); - INIT_WORK(&gsm->tx_work, gsmld_write_task); - init_waitqueue_head(&gsm->event); - spin_lock_init(&gsm->control_lock); - spin_lock_init(&gsm->tx_lock); - if (gsm->encoding == 0) gsm->receive = gsm0_receive; else @@ -2612,6 +2605,12 @@ static struct gsm_mux *gsm_alloc_mux(voi kref_init(&gsm->ref); INIT_LIST_HEAD(&gsm->tx_ctrl_list); INIT_LIST_HEAD(&gsm->tx_data_list); + timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); + timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); + INIT_WORK(&gsm->tx_work, gsmld_write_task); + init_waitqueue_head(&gsm->event); + spin_lock_init(&gsm->control_lock); + spin_lock_init(&gsm->tx_lock); gsm->t1 = T1; gsm->t2 = T2; @@ -2947,10 +2946,6 @@ static int gsmld_open(struct tty_struct gsmld_attach_gsm(tty, gsm); - timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); - timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); - INIT_WORK(&gsm->tx_work, gsmld_write_task); - return 0; }