Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2887378rwb; Mon, 15 Aug 2022 13:20:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7j6jIdDnh3wdmoin+tYSnj/hNaFnaa9atuMOLqBbPH8gPD3Z/ylt0eT3NjsEtvy3xD7J7v X-Received: by 2002:aa7:d292:0:b0:43d:7923:66cd with SMTP id w18-20020aa7d292000000b0043d792366cdmr15179916edq.403.1660594821276; Mon, 15 Aug 2022 13:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594821; cv=none; d=google.com; s=arc-20160816; b=Qugs6lDCf1okuUsP+tNfG09fSNg1TfZ8SXk4AaFfrUbAjzYmaleQgs7V9cgQsDfTH6 dH5WXEE89zlx+cIio0eeEd8Op7gFDrnSeKz3/qWfDTnS79HZ4m/HCt4fkQ42QKqYJ64q xX3p8yoq9eHB//Na4q7sxIo2f/K9P3DbCQBXAHEbh+FBa7x06xl/LEFTLnWmLZi/xgaR FNDxUycU9eK6/5chRUg4zvykFBeVEKiK6Ir7GFmlY9Z20cKBXbP+qaSI0rUi9ZywyevV z4CZBN21ynIG9nfmof7CPeJUiKkdivf9D5spWTUPnYvPciTQysvL6PBrAmndnVBaSijf sWlQ== 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=TFvqgloakJQygi9hty3GLg83EaFrxvltXH3XedLaza8=; b=034feya9MdS8sJ+buvEv314ixjyaF8RsyxLZoO7bnTKyCS6N+u8R6aE2VkyArTQa/n /jj9QtBPg5enYvCfCDl/0aPObBvHM9TCAob8aXrcThyNTArNkrKJS7n25Ri4kkOOZ7mO oPD87MXLAnxmNpt3JFBJ6Lm1jyYZ2QIv/6mUIItc4hRsC+hyEKOXYVH6rCs/jAPrAbKr wxIpZoEncw2pYIsDY0d6z8ueU0LWn850CiwdcqZ4OIuvhp5zkMlwXoDKEuN0jOR3roV5 vaIf21aGErT4Xa61PR3RDFWnWrZocmEIIzWopDtWiNXQkfaZCMLWibXjN7JZJO6hees+ SW2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Vu4BZZgA; 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 w14-20020a05640234ce00b0043be308c841si9170073edc.251.2022.08.15.13.19.54; Mon, 15 Aug 2022 13:20:21 -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=Vu4BZZgA; 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 S232462AbiHOUCP (ORCPT + 99 others); Mon, 15 Aug 2022 16:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345945AbiHOUBF (ORCPT ); Mon, 15 Aug 2022 16:01:05 -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 D008A7B7BA; Mon, 15 Aug 2022 11:53:42 -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 1A924B810A2; Mon, 15 Aug 2022 18:53:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D49C433C1; Mon, 15 Aug 2022 18:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589616; bh=ypcTEHAAN56lMkwcSW2kJ2Sjqa0FjUipNQmNtZq0vRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vu4BZZgAMZeyDKNUDDpYHvxGRlDoO8AXwvxq4wzjgYuMbmPGxHdLlWphziANjqWMc v0gm4a6FIeJ2RoDtqUZCls6sAV4fPZsbykLyc3l/Cs+6uhW3Ps8qjNWsWpn9mNZDUH RSvKu887ROlAse51yr9XTufGb0i5ANvAG7ZMYds4= 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.15 775/779] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Mon, 15 Aug 2022 20:06:59 +0200 Message-Id: <20220815180410.517422014@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 @@ -1970,11 +1970,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; @@ -1993,11 +1993,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 */