Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3110900rwb; Mon, 15 Aug 2022 18:21:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dvYv+JN/jpZ4N43xCmYrs51FZWLpUUHGguvD0r6JXF6y4E9dSFHPyIYEc29oj8DKCooUp X-Received: by 2002:a17:902:d2c3:b0:16e:ea56:7840 with SMTP id n3-20020a170902d2c300b0016eea567840mr19599532plc.142.1660612895795; Mon, 15 Aug 2022 18:21:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660612895; cv=none; d=google.com; s=arc-20160816; b=0lgatzG70jbwd+3DV3fPUWnEMdNmfteUpwnrakcu+fVLggeU7445XWnPqWxGE7yOo3 bq2EfboOQGnoRJ3j6fz1+Ueucr9IQZ8bFgBTcfGLn0v/6ZYzqEz/6OllMq/+VutbRKkU IV9iAo1D560JDelDkP/o4V56n+NwK4jriTUrWUBXgL4K/jnVMRFdrcMtlgL/eq3VuNX0 LJVUVzEq2N0ynRuo3BjZn4X7erfgi3+Y9g3QPl30P/OTpJk3AUie5BIU+2AkUT9p93tF fjed+RG0hZgrjBHk9zAN007QXi+eUt7AW5oZyqTtBZa6vUci2EY5uNEWq8tou90mku+T qrig== 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=ywQjTb/NXY2zvgZmfwmFpMIlcsDlIGs8RPwYKMcn8o8nssKpC1rPfztqgPBcpTeokU Jzpmmj3Q+GTsIeieXaKiRHukABISR5z1lfGMAvjdZJvvzJaw+s5BHp8BUu422XM5500G uyaojhJSowZhzqbV8l/IePC4mSNzGn3kx5KQwk04BwNFEOMK3iDvPie9WiuBruhjbDea M7d139N6gW5JsBW7bSXv4+59vSnshCw4EPypHIE2XmuXiJHKOgIwF26tc3PxoazMzxed CCwuY2OxNQkG5PVo7u1DI8YXX4/bPJjjnQwc1cw+fO+YdmgjlWaR2f5ZiKyc38o0AxP5 90Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="png/pixY"; 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 x189-20020a6386c6000000b0040c8a3cab3esi2894200pgd.638.2022.08.15.18.21.24; Mon, 15 Aug 2022 18:21:35 -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="png/pixY"; 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 S1355055AbiHOXrB (ORCPT + 99 others); Mon, 15 Aug 2022 19:47:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354318AbiHOXlx (ORCPT ); Mon, 15 Aug 2022 19:41:53 -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 72D312C652; Mon, 15 Aug 2022 13:12:22 -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 10DFD60B6E; Mon, 15 Aug 2022 20:12:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 004B1C433C1; Mon, 15 Aug 2022 20:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594341; bh=tO76lJ66HsVJV3KXENX1SUk8oeNUKoWrD0rDT+0Y+lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=png/pixYqbv4AWNf90gVIJIwv3RHazrRqi66RMiEWiTHUGfb0pHCrocjMF59yFMQE wjhmlGn8FdsVLAnwt+Ut5AtW2wDtdMPI/IqRq2ZcneUzNoSWOOGsCB5B+qcmTcpNSv leg2t+1NAL425nu4WGzEmuJRqoQIz2acLsltX+Yw= 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.18 1095/1095] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Mon, 15 Aug 2022 20:08:14 +0200 Message-Id: <20220815180514.297750540@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 */