Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1863714rwb; Fri, 19 Aug 2022 10:38:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7CxKNKa3kNkx3vW1tLVKyEATnMnX878rAlTJLwOO9s5D5djji3LbH6hAEVZLg6vhTBGKUU X-Received: by 2002:a63:85c8:0:b0:42a:4354:8867 with SMTP id u191-20020a6385c8000000b0042a43548867mr2678329pgd.359.1660930720969; Fri, 19 Aug 2022 10:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930720; cv=none; d=google.com; s=arc-20160816; b=0qEhE3VE5LKJC2F97zaKcVqflI4dspEl2Sv0EXfGbv70lB0ijw2/pOJ3EkThIW1fjY S3kxaGceuOLQvn68znS2dvMZaQA+k1usT1udCKdkFRxkl5vY4KAxFyubfeQ8RUbCdtuN 4bMW3UibtOZiOlqyGNs/j1adh8sdagO5I9HkoI7VEJBMOmm3jzE+T1i9/hHTDmpQv7jZ mIcWOG2KZ6YmgGF1/3X4FBQinXjtquuv6ea0sjSdnYuoqCi2D3VuIoN9U5uHbXzPPl9r 6y6GeSr+S+Cb1RNRwNESxkvDRu2FyAwE1rgexwDE8qdnA2BGNavXvLqm//cFY546v+HJ T0Vw== 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=Kd1YaEzV6RZaCWhoqcHuEkP0eeGZnk/o0ujyJrCYG2E=; b=KMptGr/K8VDV+/2+naJp1I5dqBAkWv1aXpMI5cYuxEIkWRkqqcazOZirBL5rq5kpGw INzrpqjE4ktVzaYunSOsrs93SfxNhoKIOV4ZP6BwkZ5ukK83hBy3hKLoNsOa1m9MM8dz Civ125cGoceb+k6HpNGQKruiYGOne2nv9JLuDNxm0H7bApglqDj/V3AbOXWlEkKFidGk CcQIs6k+RzkEZ0QGP4J+2onAVmLdmgez3pr5uUf5ijzrTK/XSIahhqMnsVX80F8EhBXQ YqwYxjuvtZN/52J1vz7/3j7YHD9eBVaTkXIkw3SjWWcXmC3Mj7fmh1Z2e5el6r06yMPU VkEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VNYe5B+9; 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 dw24-20020a056a00369800b0053606bf05d0si2646262pfb.0.2022.08.19.10.38.29; Fri, 19 Aug 2022 10:38:40 -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=VNYe5B+9; 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 S1354280AbiHSQy4 (ORCPT + 99 others); Fri, 19 Aug 2022 12:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354421AbiHSQxh (ORCPT ); Fri, 19 Aug 2022 12:53:37 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3E931DED; Fri, 19 Aug 2022 09:15:16 -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 sin.source.kernel.org (Postfix) with ESMTPS id 3DEC4CE26AC; Fri, 19 Aug 2022 16:13:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D11EC433C1; Fri, 19 Aug 2022 16:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925609; bh=3CxRal1Wz7dBYYhtwSv0Lq8UgsO8mOKXA/8E1KJSgzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VNYe5B+99BccbWn/3SSx+uUspZpdoQ9ARa7pYGjyX8RO/SXphcRXWpkP1CwnwM1Gu fD6OAPwDtc2KgVvkAYs69y/PVGEKFD1PyMMBMy2yJAj0CyoBP9HbrP29OkjeWj4dBI JfLARyOKsL/DF+65f+JruKK1RckjpEZOHkkjr02Y= 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.10 537/545] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Fri, 19 Aug 2022 17:45:07 +0200 Message-Id: <20220819153853.617121540@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 @@ -1966,11 +1966,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; @@ -1989,11 +1989,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 */