Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3490319rwa; Tue, 23 Aug 2022 05:44:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR5hfWIcgr4qih9smpj7Lfop/fC8w4Y9vduGFwQbKAompFrekQYrT9u3DNPotTiq0F1h489u X-Received: by 2002:a05:6402:268d:b0:43d:b9d0:9efc with SMTP id w13-20020a056402268d00b0043db9d09efcmr3685701edd.92.1661258698419; Tue, 23 Aug 2022 05:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661258698; cv=none; d=google.com; s=arc-20160816; b=WL0JjTqFPr2UfiF95/ZmeBWHpuCANA69hcaSlShyxnYZpfBgwfg8OzFlhfqv0OLjFo GMqJZrkyP488DAPReQBuUOPnI7raebqaM0Z5cju+9g6i3DDkQzaNEtwSPmYR1NtLy4m5 KTD0WRUU9Pp9EuX8Ddi5Y/d1VlcdcEbanMLdWZEuYAqRR6BSIGHXtOJuzGcks6hikMVO 4af/H5jMHAFR9xH2veWdGdFSuIqFmAeo12Iwyv2cTLxwiCAxpObJKbQqh85ilTtsFl/L mHskzE++VgHDXDw+aH/El4UhFdic4m9c/3PwXrCAUWWhAqQohgjzLZTPUGLUZ3/tNlQG iHeQ== 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=cudJbo0Xr0ms2GcvsmpWiW5D3r12E6/auXdEC8zXB7Y=; b=w1pFpv7/nZVXuQoBBIDGoA8GIXJlV+5sxeissnvb7QgQcpHAaH5IVhSMLBaZWY2N4S E3apL8oHw2YhJJQetG6WQQNbYsT1C8nHPs17pMNXegEOP4w9LyDL4resKd7pxeqDg5om BWzcQL2g7iuRnDhs3LMycgip4DtU/9rNluwHjJRFHIgvpKZ8b/USkDNVn5WHUqwvR7if fiB0tSIKN74vX8abxvh5eEkBCerjnlmGD8Yf5qVKFhOthbRW1+HLpQoaPAP4adl6Ki0O 3BXpJyQ1Qgverqvb06GSXUcRQyxDJ1CcT235ru62Zki1fAFnm675qgzPjDdSKTcy56dW pjIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bvLi00Fi; 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 ht18-20020a170907609200b0073094ce02casi11722658ejc.791.2022.08.23.05.44.32; Tue, 23 Aug 2022 05:44:58 -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=bvLi00Fi; 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 S1358419AbiHWLsa (ORCPT + 99 others); Tue, 23 Aug 2022 07:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358169AbiHWLoE (ORCPT ); Tue, 23 Aug 2022 07:44:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D678FD074F; Tue, 23 Aug 2022 02:29:54 -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 7775AB81C66; Tue, 23 Aug 2022 09:29:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E27B1C433C1; Tue, 23 Aug 2022 09:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246991; bh=hAFBu0imeopBah68UDNV2iX2Igkn6Hr9V1s5wp2Yw9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bvLi00Fi6FPWeMUz7ry4tyuBd3VWTMSV6SwOYedKWhO5YNptBnn5KczoQ/QAWfZiQ HsnFLwBkKO2p4drbrPWbbz6aiXKyOgT5xujIKKj9ZuTZRflKIzGhLnGIfus8q2MiAh AexnViYxcIVJ3rnlxS0kKUtSvzGHfsHzytc3mAiM= 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.4 283/389] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Tue, 23 Aug 2022 10:26:01 +0200 Message-Id: <20220823080127.376029742@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@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 @@ -1813,11 +1813,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; @@ -1836,11 +1836,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 */