Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6827046rwn; Tue, 13 Sep 2022 09:29:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7oErkc/OsZiG7wNU9o3rljdUktEgmRnppMuo57F8XkPyIxNWS16w49PsU4oEd4p//bl+4m X-Received: by 2002:a17:907:d07:b0:72e:ec79:ad0f with SMTP id gn7-20020a1709070d0700b0072eec79ad0fmr23073667ejc.296.1663086586919; Tue, 13 Sep 2022 09:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086586; cv=none; d=google.com; s=arc-20160816; b=aoNOzNnH3UNTHWvb2n3YdOqwGTcnT1jA1g8ajS+05uu0lqlLu/g9McoH0i3/u361C6 3lVSKNmVotmFj5u9nRx+GWpob0VbcBSDOOXZNggyk1NOIhB7pEruIDGQCUQ/PcIzx4S1 8RKlGLGWHoZ9F3khBIaiiAuK4GFRuWrQ8HyEh2Ha8mvs8t9uWweGl6Qf4+HtgK7S5v4B twy9bkQ0kL30rCetFhnoA+neL66NBxg/dJ8p8Lo+iVDeNQGr+ahepcuy3c8rioao1VA4 537q9SOn6nIZCIwpIXv16HmXTadFgzBB6AGpQkoqvnpkgZQ2x2KeVqOEWzlhPWpDBYu7 5Srw== 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=+cfkopjijcHKfByy0I3G5pg5GYLEX2ddDKHZbUIIDBU=; b=r2zcAwMXFJN15ZG53zVBOZfcBN3RdAx5+C+YEaka6gBgsumZGhuNiP8xkEa+vgklsu r1H9ezWI+GooE1fLXVLF0IdSdiVfJ3SG5Uq51FlgaK/CoiMwCFUjXmkMpYLGpJhX7ycL d7h3ju2pMeOdCKmtWvgvl1SDrVpD1vieGO60dWFp4NHiw7zUpdArJlLuT58ItRn+/0ME AE/CKnFBpEsH7ic7qbsh4eBlpaxihr/XS+1D+XLCx9HzewC8zy3J/C5yJ0Z4LZZwpz2D jJSbARHhDKm0/sEI/yDBgiACw3YzO1Fyh1/w8lc57+ShSaujJuGYNkuocht7bgqQW/7k OuYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WrS9bI6g; 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 s27-20020a170906061b00b0073d7f493935si7908693ejb.755.2022.09.13.09.29.17; Tue, 13 Sep 2022 09:29:46 -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=WrS9bI6g; 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 S230518AbiIMOoo (ORCPT + 99 others); Tue, 13 Sep 2022 10:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233086AbiIMOmb (ORCPT ); Tue, 13 Sep 2022 10:42:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 994A75FF4E; Tue, 13 Sep 2022 07:22:45 -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 ams.source.kernel.org (Postfix) with ESMTPS id 1D5C4B80F01; Tue, 13 Sep 2022 14:22:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E59BC433C1; Tue, 13 Sep 2022 14:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078955; bh=TDPwj3b/S3MexzapRQJ0/V6tRppIAPrvSk1VkTJLtCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WrS9bI6gHqFyqfqR3nQKzz3nz/w1djOYlR+qCzBnXYbzlqVTBj0JwqXmUjurg4Fu6 2o+8/EvZfu+CDbtLNoOl2ov6RBypw1BLZVKp4uX02Qp5hLpIn0h4GY3iC613ccnpBS LoT4NwKS8WlWl3CSGhKq+HzvzbhEgjHibSuMbfck= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , stable , Jiri Slaby , Tetsuo Handa , Fedor Pchelkin Subject: [PATCH 5.10 03/79] tty: n_gsm: initialize more members at gsm_alloc_mux() Date: Tue, 13 Sep 2022 16:04:08 +0200 Message-Id: <20220913140350.450170649@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140350.291927556@linuxfoundation.org> References: <20220913140350.291927556@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 32dd59f ("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: 32dd59f ("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: Fedor Pchelkin Signed-off-by: Greg Kroah-Hartman --- drivers/tty/n_gsm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -2200,11 +2200,6 @@ static int gsm_activate_mux(struct gsm_m { struct gsm_dlci *dlci; - timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); - 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 @@ -2306,6 +2301,10 @@ static struct gsm_mux *gsm_alloc_mux(voi mutex_init(&gsm->mutex); kref_init(&gsm->ref); INIT_LIST_HEAD(&gsm->tx_list); + timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); + init_waitqueue_head(&gsm->event); + spin_lock_init(&gsm->control_lock); + spin_lock_init(&gsm->tx_lock); gsm->t1 = T1; gsm->t2 = T2;