Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3398756rwa; Tue, 23 Aug 2022 04:14:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6fShQjYiozw+6knyEEUpg0Y0kGuyOr3k7ETDgKOv+hToQ6B+4iS6zssMtVqXPym6rTBTv6 X-Received: by 2002:a17:90a:e58a:b0:1fa:c67c:6107 with SMTP id g10-20020a17090ae58a00b001fac67c6107mr2905736pjz.50.1661253290667; Tue, 23 Aug 2022 04:14:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253290; cv=none; d=google.com; s=arc-20160816; b=K8Ner15YanfNRZtAGf1CN0o9y5SQcdaRUew2VZXbcwcPrEJHPm+jeZdsXmpr37IbJF 29x12XRS+IdyIJA6XrroU8ntoH1az8b7jirKVU5gAInYZsepx9MXeFmbYtqzE3YNeKlj zguGq6EdxRS6H1gl17T1lR7Plz8uc3LBC6VLYWcGAkCBUgo8XwL5ztdU5dNACOszfzGR mJvBzOi9k0f8q85OZYcVxdGPqmaBf7njiONzW6idcla/SYngAvUPbfAAyngNs/nIW0ts DG2fyiCFoDupb4p1yhEN8w1ajiJ4MQ2GXokrUAIEbPTIwtVWWbvD50RC8m/pfx0Vp27p 8yjg== 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=U3lP7M+J7QMTTdC++pZDp4dr1FwUGdnvlSoDvpI7Ymg=; b=RcRD05iQ6D9mAVdvNeG1ma1+V/H8r08gToWVTH/f8BhuFEd4qtJ+CKHLFyPO/Sl4Cl 47Zi1bykci8SMF7AK9GxCD3Olx1PnewhWiVc7vA9353bfWI5nNp/M8fXkEh3otKP+Hn7 Fodw7xjHE0coqQIZByeLZ01fCJhb2hcgOfPe1gV+B3J7682V0yh/KjWgFf1rIpkeBM85 Onbodn+/sQmd+DL0riC04OXlA60Fpq0wGv4pZvBWclkZuOPYJz93RYU2rDd8IG8uTgmQ Gyu6SciH5qViGSAEPA/CsCSPwqMoaQRWvI1ve52OyIrWVuxvEdw08DZhmmW3x4x0yH/m nt0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Xg6FmpnZ; 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 nd10-20020a17090b4cca00b001fb395f4814si5249896pjb.180.2022.08.23.04.14.39; Tue, 23 Aug 2022 04:14:50 -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=Xg6FmpnZ; 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 S1356863AbiHWKzu (ORCPT + 99 others); Tue, 23 Aug 2022 06:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356089AbiHWKtC (ORCPT ); Tue, 23 Aug 2022 06:49:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54C24AB077; Tue, 23 Aug 2022 02:12:29 -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 7ED6B60F4B; Tue, 23 Aug 2022 09:12:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D9EDC433C1; Tue, 23 Aug 2022 09:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245947; bh=t9EAyhTB6WaOrs6vp1R5UqNAeAWhZro/XkIxBgAHZao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xg6FmpnZvrQJ2MFLt2C+cIXJJPXS5yMbL2v5u/OsrR6gZ/Nr3xeLE81LucYD7yCaC jhogKzJOYStbhkrYa6c3tMTuRLpRShTfFJ95ME141/8JOIlwH4oI8kZa3sbA1CkehV 7i3XHQu4zsVLpwegH7khkmRk3k8pPTFSTldrRdAE= 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 4.19 209/287] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Tue, 23 Aug 2022 10:26:18 +0200 Message-Id: <20220823080107.964795748@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 @@ -1804,11 +1804,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; @@ -1827,11 +1827,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 */