Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2219978imn; Mon, 1 Aug 2022 16:02:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vZGfmADDLfcbtsebY8yNEzcOiEt9mZvzsJcfHiD6LYK4NV30Xp4DQUSX1jR+OiDf+dleyM X-Received: by 2002:a17:907:1623:b0:72b:64e3:878a with SMTP id hb35-20020a170907162300b0072b64e3878amr14578619ejc.185.1659394942618; Mon, 01 Aug 2022 16:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659394942; cv=none; d=google.com; s=arc-20160816; b=BvWF/FPytttrGvUuJfbw+kG31dxkHFAvLp0iTu80GiFJ13Sx/wpDeTkCSgKFLXR5Lc AT6ySnKV1WsFYf5a87yrLAKRCnSnKSPFrsUqizZK7GhYVWxI1XSorI8lP4inu3zuZ5OO vo10jGzvhhvns9x76SucXT8iKHSnZzmm9Qjy8vrQUU43XZi+Wbv1F5RO6mFB9m84P6cE 0riQvfnjAwQ1XjlgiQutKFTpAMLAp67sec1jH6mY9fDYwwRXqW9pjijFWi/kguLoPox7 g/bJacXxmHw+Sg2p/pOXc7iWE7bdoek/uQQldBuqZY8YLBRcbE8mbVXPQSRoAJcAxdkS AYMg== 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 :message-id:date:subject:to:from:dkim-signature; bh=zGTSp5JZjYvfyaVfDTaI1pBiLT+ktc1Kshk6i30iUo0=; b=bjCx6Ayck2jVC0YF9zzn68Qx1jzfwhnPebeh8c7pif6gaTU9gbnYwKBvrgDGdDONQX YI0m3J0ZBdu7+JAwILKN6CTAkKle2MvOJEbJcCsTz8CdnkIfgNdsrJ5Z7B41Kf9mIzu2 LJjdfAHIXmsuWrGZGNyaiQKgZCPWJTVXCcsf/QY2KOCGkUzCqc4KuDjS8S+AKkvFwbIn e7D+TxVWM3kI1IPweQRnTJryXosfoxx6zgnPc2S9tPNSbr6eLBEHDBa+hDWo3amcCplh 8TBY+k309sCp53WYs/8gyn1ADuqXCdCo1YSgonhfzo2vIOxtZYeTtggPFkhAW95i+Udf 4EsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MxsZsdoa; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ec54-20020a0564020d7600b0043b0e7cf010si9476296edb.331.2022.08.01.16.01.42; Mon, 01 Aug 2022 16:02:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@gmail.com header.s=20210112 header.b=MxsZsdoa; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234125AbiHAW5G (ORCPT + 99 others); Mon, 1 Aug 2022 18:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233286AbiHAW5F (ORCPT ); Mon, 1 Aug 2022 18:57:05 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52D6229822 for ; Mon, 1 Aug 2022 15:57:05 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id f11so10890213pgj.7 for ; Mon, 01 Aug 2022 15:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zGTSp5JZjYvfyaVfDTaI1pBiLT+ktc1Kshk6i30iUo0=; b=MxsZsdoaJUBRUzyU7DUaLq1G71fU45S55506k+CJOcw2CDcSlUhzbePifqst6oas2v 2wPSOtJy+lsNkDeN91pHeb3KoFlNRS7Jh/naXJ9HXD4Bd1d4ecrVzKUBhYCW97+byVfw riridxB20SEzQjMrWGvj0XHgTGdTpCn24eWXzJ+NRCkCgbqwp0bt+l2VqEUEo5PWwz5L 8JrLnhyKulyle5c7nzhbkXH/jd0N1FXcjF7EnURVeNBcBnjN6xduGTbwBvhJgqacIliU Wb9IErCzOkxTcPaCzBDwBNusfQq5lz2+E10XHlEeOUHiJTedRYup0hYMSwxbvk1e7yiz X3uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zGTSp5JZjYvfyaVfDTaI1pBiLT+ktc1Kshk6i30iUo0=; b=7pLvo1IFCqnkc47uNlZOmGfr7oLmYkjVo3hQk9gwzgqDtrSv8U75AdnIN+zY6q3dE2 FmQf6mUmOtu99LKscmh5fu+ok9WCZH7PXzoV1BkPQ4rk0tSQTEgnOxP+mhyUKTNCzJIC BLTN7X5zRCoRhZGhQApDE18HIEo+kwl3vMnT4BzmikWbosNCAEs3AqV33+erD5+Uw8aY oeEmUpu7547doUXO72n5ZHS3+y3uvoZSEyU2xNcQTxcd/cO8ukuMRjeByb3qbv2BRvWH mdDX+g8wYCCTDEowKSEIL8Muizvpj/WXIeoz4IFzks9MSMgZPELIJpPRquhmAYs6inXI EQog== X-Gm-Message-State: ACgBeo1r0NXk+boQJUq2VmOEA09UBiMf0J8s/JIwHPRcrx2Nx8VdqvZj uKBskeQk8a79QyHQOTxFVa9PKGv0m34dTw== X-Received: by 2002:a65:6e96:0:b0:41b:d634:ea7d with SMTP id bm22-20020a656e96000000b0041bd634ea7dmr9485507pgb.130.1659394624195; Mon, 01 Aug 2022 15:57:04 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id u18-20020a17090ae01200b001f2fc3828e4sm9513007pjy.24.2022.08.01.15.57.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 15:57:03 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Date: Mon, 1 Aug 2022 15:57:02 -0700 Message-Id: <20220801225702.2278772-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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 --- v2: Fix lkp findings. net/bluetooth/l2cap_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 77c0aac14539..1c39fc40591b 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1970,11 +1970,11 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm, 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; -- 2.37.1