Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3457246rwa; Tue, 23 Aug 2022 05:12:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR609qEMSoAK3e26wudKpEyaVAfyeGxebl7BntpMIzaWfEUFZd30dRXNvAIDQlafsME4KL5r X-Received: by 2002:a05:6402:3506:b0:43e:954b:bc8a with SMTP id b6-20020a056402350600b0043e954bbc8amr3509469edd.266.1661256765087; Tue, 23 Aug 2022 05:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661256765; cv=none; d=google.com; s=arc-20160816; b=xiDqAPuruquBF3KHcCnFmLC6X0p+oEI8m4qYiQPptBCveM/PleMjTSJg3GVWg2axMv nXn4HPiiJc6a0VJxikji7CXGyxel4lvuIcDntL57Y1gS8Q+M2DjMHB+rX5ZXFwqyWUDK 8tlfjFKNMOQfQ20HnYo+aISL2E0/zh+aY//8oMNj0PSRjQb237xWNiHNK02RVsAdqv5O lb2sUoJxiEnW1bx5MvdaQeAvs9by/5XfbNiWCTSASZnpEN4HMcEbuOMjbbnkFA3tDxxN eB0t7396xGm8MEzckOiy07d+AlrDLZxy4covT5CXUG8WSLhIwVC1mBhRbyBqpC0hUzKv wMtA== 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=b+SlClhGQwspBpL1/r+GP1vkKOMzxz6KdpENg+ezLXJvaQtpaXvL5QZRG1493jqztW rjCR3Y+wZZs/vbbqdgo0OOg6XGm4EDw4AaTOz9FmyYPrn4LThrSPz5cmetQ3RXhvAwxM mi52n1u+W7r/gHw3j1vMIx4jxmGYp9jRMsNidtgxLlK0omTBJiOjg/mxeqsVQ2uYw/fR bIhO1dfDmHe3VMFWf2OwMzY4G8cjpFQ2mFLnSDVoSwEd0ZMENhQ3wxbyzwq1D+1DZF0R S3vPqftqZWkKYJXWvATUMQYBO+iuPBZHqWXlOL1fdZDY3S454Tv49gCgqX9Co8dtAIRb tcnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cfANHe7a; 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 e5-20020a17090658c500b0073c1e339952si14006405ejs.339.2022.08.23.05.12.19; Tue, 23 Aug 2022 05:12:45 -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=cfANHe7a; 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 S1353219AbiHWKLF (ORCPT + 99 others); Tue, 23 Aug 2022 06:11:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352320AbiHWKCh (ORCPT ); Tue, 23 Aug 2022 06:02:37 -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 EC7CFA2630; Tue, 23 Aug 2022 01:51:07 -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 C5D256150F; Tue, 23 Aug 2022 08:51:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2674C433C1; Tue, 23 Aug 2022 08:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244666; bh=t9EAyhTB6WaOrs6vp1R5UqNAeAWhZro/XkIxBgAHZao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cfANHe7ae8ki5YsgBBeVvRiXmM/xOgZ/CR4W1WYJUAUEl/Yv1qaKjauTYFU42m9VP FAjzgsbXqwLKh+EiQsR2R/1Uq8zStnG8dEWt5OUv0qyEG8SXMkFYb267XwRKyRXqDL hT3N/Uakmq8Xbi9Zyl1aCg6CUfN3o+jS+B+ogI0s= 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.14 172/229] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Tue, 23 Aug 2022 10:25:33 +0200 Message-Id: <20220823080059.774255146@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 */