Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3262050rwb; Mon, 15 Aug 2022 22:37:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR6G/Vvx7wj/26mksVGWD2ebg8tllbpIidd+hxflR+d+0GlY5/dbxv/Z/xYUbfJnSBFdsoro X-Received: by 2002:a17:902:b114:b0:16e:f1e0:51da with SMTP id q20-20020a170902b11400b0016ef1e051damr10386303plr.0.1660628253930; Mon, 15 Aug 2022 22:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660628253; cv=none; d=google.com; s=arc-20160816; b=pzIxpa4E7SZqeZDVOldvXicGGsBUHUej3pkuWrdv8J6uTgqzInzWCay7atGlWEjfei oewPlYBTLmgosiYEluHpv1SMudDGsN60EEVZlL7FxXGx3Ys3smTpB/BFywPG2jIzZbM2 9OultsLEy3fjR0AIRCNCTOxxD9nTZ6bdOtxTbdXjL1JYuTnlgBoA0cHS5RRGmHCtxC/A zz6dJDnVafqcKPcisMulo0kUoGTf+W4FAEtgpgQeV4jo1c7DhLoYP10SCyqP+K6kbJrm HNiT5B+kfuST9oTHbDxD57HQdBUDibQt08AgddvKbSsXovpadJ48qulws8jVcckBA7sh SC/Q== 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=heayzrl3uCn4rgO4BxhPybvKfQuuDryivmxLIk7K3nI=; b=e0RPK9CT/2lkQIHgKFOgG2REZHQ1oZTxYZg9paHqGMSovYbBUkW1gVky5myuk2gnCo l7YMgZmYAJdpGXBynuMWwsiE6cJoB1tX+HvWYAUWGO1hoRhUyJXsY4Nmn0LS83VmIKSB cI6qQfZdM3hK8uSmEWrkioFNF+2dgybW01uiJCZnJQRCPH7QEBzRBerhkYNv5UeWGoj2 csRCVdMRmfWnUGa+tOwGP5uzWoHBZpJA6PQQLza0tsevKBAKPh/E8SYAl8obkCQCkWTe I1aEFebc9JvZMeA5lhYlPZYaNaoBLj9TujmHXIK60mk5crhfv/EGCNYmA6SUfnTWQm7d YNBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wTwpwuoF; 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 j1-20020a63fc01000000b0041b539aec98si12211077pgi.816.2022.08.15.22.37.22; Mon, 15 Aug 2022 22:37:33 -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=wTwpwuoF; 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 S234066AbiHPE6v (ORCPT + 99 others); Tue, 16 Aug 2022 00:58:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233543AbiHPE5v (ORCPT ); Tue, 16 Aug 2022 00:57:51 -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 ECF55BC132; Mon, 15 Aug 2022 13:51:46 -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 A85EBB811AE; Mon, 15 Aug 2022 20:51:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D929DC433C1; Mon, 15 Aug 2022 20:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596704; bh=tO76lJ66HsVJV3KXENX1SUk8oeNUKoWrD0rDT+0Y+lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wTwpwuoFSsnIkFS3jG/RjglJ151tfLN5KablfVPgwTvPAcrptVCmJ44lmB0aeRY4j lbIiRsI/fC6qMCeG5zbO3id7fuX+MzUgblfgH8v4gRTkkZ9THpWMZKVBX6Kb5Sn+aA uSQnLiNg68E+yn0Af/XBVTyyRrhjNhPcWZxcKoNQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Luiz Augusto von Dentz Subject: [PATCH 5.19 1157/1157] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Mon, 15 Aug 2022 20:08:33 +0200 Message-Id: <20220815180526.836274587@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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: Luiz Augusto von Dentz commit 332f1795ca202489c665a75e62e18ff6284de077 upstream. The patch d0be8347c623: "Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put" from Jul 21, 2022, leads to the following Smatch static checker warning: net/bluetooth/l2cap_core.c:1977 l2cap_global_chan_by_psm() error: we previously assumed 'c' could be null (see line 1996) Fixes: d0be8347c623 ("Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put") Reported-by: Dan Carpenter Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/l2cap_core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1969,11 +1969,11 @@ static struct l2cap_chan *l2cap_global_c bdaddr_t *dst, u8 link_type) { - struct l2cap_chan *c, *c1 = NULL; + struct l2cap_chan *c, *tmp, *c1 = NULL; read_lock(&chan_list_lock); - list_for_each_entry(c, &chan_list, global_l) { + list_for_each_entry_safe(c, tmp, &chan_list, global_l) { if (state && c->state != state) continue; @@ -1992,11 +1992,10 @@ static struct l2cap_chan *l2cap_global_c dst_match = !bacmp(&c->dst, dst); if (src_match && dst_match) { c = l2cap_chan_hold_unless_zero(c); - if (!c) - continue; - - read_unlock(&chan_list_lock); - return c; + if (c) { + read_unlock(&chan_list_lock); + return c; + } } /* Closest match */