Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4855980pxb; Mon, 28 Mar 2022 04:39:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtS7Lu83g8jrMbhqM/8rQ8kHWfc97ennU/MKjny/QEcZBWEQ6CogWqNvaNpQY1v2zgZTyj X-Received: by 2002:a05:6402:26c3:b0:419:2e13:27fd with SMTP id x3-20020a05640226c300b004192e1327fdmr15725520edd.210.1648467579780; Mon, 28 Mar 2022 04:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648467579; cv=none; d=google.com; s=arc-20160816; b=N5xGq46IZbI+Ue8fVRESqlOK/aVe0LrwoLblxQ1Lc/Y6gechW4ZGMvbOY8IQvzgZOT 29NPt1gf8vk6EyUA53w4plACiDorzUJno4iwjZnFH7QrwbcxPsIAopYgyu/8x+YvDEgn +OUh8OUuyQBJ0B4Qdtn4rcE59/Pz4AMUohRxBuJ8MBTVcxdrV0bpTdkYcdZuYHO3obwe rGv2EDrFELv1Ph+RK102f/WFtoxWQM+xcu4priIUbPbPwLoRDmGhUjsyrpCfIyE2jAkN 9saNIH3GfmLJpeIu7nfIBAedVHouZkTvfzHB8epczST0iJHd38dWQEf0yMChdechROLv +mxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YKrk7yyVSBJyq5gcy9y0VCTef/2oQsNrO3DCzTW9su0=; b=HhyNaYT12gM5srb2HFRst0oDWYZEZgQOENo1YS/4CffjkF/Gt9W4r97WQ1EmsxGhei bozEQpOhZn5ukp0kVTZyuqLLOoHRP9/qfMBwTCRqHkm6K1ThGnmNqnDzAX3dvqIjb8nJ fkSbSk0e0Fr6Bqwe5dxdX04h25c7DGoorzAv0KCH3UUcrd033TXXeGzM7rqouLfZY76a iOOS6+/jo3Ca9D0YmqAVoHrI90XzBULkB+qAITKwjiogItWLLPVk457ZUYqf79EPO9B5 ljPH/9rR2OBHQdrC6TTTf71/LH8+PMjdlMlJK/6igOnSAvozkZV3ZIkNtWbAHF99Qqgp Bsng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=flLawCsC; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 gl22-20020a170906e0d600b006e0af1565c3si11272499ejb.316.2022.03.28.04.39.22; Mon, 28 Mar 2022 04:39:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=flLawCsC; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 S236788AbiC0Vml (ORCPT + 68 others); Sun, 27 Mar 2022 17:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiC0Vmk (ORCPT ); Sun, 27 Mar 2022 17:42:40 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E55F33A13; Sun, 27 Mar 2022 14:41:01 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id y10so14897041edv.7; Sun, 27 Mar 2022 14:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YKrk7yyVSBJyq5gcy9y0VCTef/2oQsNrO3DCzTW9su0=; b=flLawCsCu7mGwfCSJ/9OK4RPnqnjPyBA1j/kUx6d9OzQsP6SwZdIzQpJ/8oBm/N7ZA F/+9afnveATUPMKLk7o2V4kj4RAyAg7dKhWF5YxF80pzgpbozT0+vg4FO57qOq70LYmv dgUkaB3NNIUQXYkibvxlnsGH3WXqWugpIHhWEwd/zMLnnA0+Ue1b6c6dMf0cpVcPlNyC MT1BVGUNPbzC13tlyE433L6yxImX4gC9NVk+r7sBOoZgM6tlb3HTOyqkesgEnGjFiP5H X7qoWtBx2I4Do+9lFQls3TsGWA53L9wbGx2P+iztcv0xnq6lZPrrZ3zkfIYyi8P/aYtB grLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YKrk7yyVSBJyq5gcy9y0VCTef/2oQsNrO3DCzTW9su0=; b=eVJ0sWaWqd61ZAScC9rKAQlhx83BcjiayvKp9YO68L71/Z1+3fzifAzSlqGAvbZPdf Wn6VFBVhTN3DrIFWeo+Ulq4rmUmrO9DVzElu+ccm9bFRkGTbYNekcYfo6pXf1etgW8Xh aP7sbA9ahdEOw0+Cl6HQz3mc51xgYsBwP0OsSUkBCXBEQw3yh1RgBWutLeu3uVdin6Kz Vftn9VYopVJL3S7zAd66WpLZ15Q8t6nkLP63eY04UqHDIduySXMW8uj3Lzt62sIwi+FX kv05pbuAj4OApy9Ry9ZbbVTY1hv5JOkvkhTr5IlbFte40UixLlGaSgtgu8716TlIo3Fa /iAg== X-Gm-Message-State: AOAM533/M/xjTeWtuwXHC+qWouSErkvhKHckjSmfvyoaz3E4y/PuFk+R 8PMjJHVuekvfcY8DC7CKWULl6T9TRR5RHUlmtP8= X-Received: by 2002:a05:6402:1e90:b0:419:4cdc:8b05 with SMTP id f16-20020a0564021e9000b004194cdc8b05mr12494544edf.211.1648417259540; Sun, 27 Mar 2022 14:40:59 -0700 (PDT) MIME-Version: 1.0 References: <20220327072947.10744-1-xiam0nd.tong@gmail.com> In-Reply-To: <20220327072947.10744-1-xiam0nd.tong@gmail.com> From: Christian Lamparter Date: Sun, 27 Mar 2022 23:40:46 +0200 Message-ID: Subject: Re: [PATCH] carl9170: tx: fix an incorrect use of list iterator To: Xiaomeng Tong Cc: Kalle Valo , David Miller , Jakub Kicinski , pabeni@redhat.com, "John W. Linville" , linux-wireless , Netdev , linux-kernel , Stable Content-Type: text/plain; charset="UTF-8" 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,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-wireless@vger.kernel.org Hi, On Sun, Mar 27, 2022 at 8:10 PM Xiaomeng Tong wrote: > > If the previous list_for_each_entry_continue_rcu() don't exit early > (no goto hit inside the loop), the iterator 'cvif' after the loop > will be a bogus pointer to an invalid structure object containing > the HEAD (&ar->vif_list). As a result, the use of 'cvif' after that > will lead to a invalid memory access (i.e., 'cvif->id': the invalid > pointer dereference when return back to/after the callsite in the > carl9170_update_beacon()). > > The original intention should have been to return the valid 'cvif' > when found in list, NULL otherwise. So just make 'cvif' NULL when > no entry found, to fix this bug. > > Cc: stable@vger.kernel.org > Fixes: 1f1d9654e183c ("carl9170: refactor carl9170_update_beacon") > Signed-off-by: Xiaomeng Tong > --- > drivers/net/wireless/ath/carl9170/tx.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/net/wireless/ath/carl9170/tx.c b/drivers/net/wireless/ath/carl9170/tx.c > index 1b76f4434c06..2b8084121001 100644 > --- a/drivers/net/wireless/ath/carl9170/tx.c > +++ b/drivers/net/wireless/ath/carl9170/tx.c > @@ -1558,6 +1558,9 @@ static struct carl9170_vif_info *carl9170_pick_beaconing_vif(struct ar9170 *ar) > goto out; > } > } while (ar->beacon_enabled && i--); > + > + /* no entry found in list */ > + cvif = NULL; > } > > out: hmm, It's really not easy test this. There are multiple locks, device states and flags to consider. the state of the protecting ar->vifs > 0 (I guess this could be > 1. There's no point in being choosy about "picky choices", if there's only one), the main virtual interface as well as cvif->enable_beacon and ar->beacon_enable don't change on a whim. But it it is true that this function gets called by the firmware as a callback to the TBTT, so it would warrant any protection that is possible. Whenever a bug can happen or be forced in this case: I don't know, I can't do experiments until much later (easter :( ). But it's better and easy to err on the side of caution. Note: That "cvif = NULL;" will certainly break the beaconing for good (for the remaining lifetime of the main interface). The driver would need to be stopped and restarted before beaconing would work again. A safer choice would be to return NULL; That said, if the bug can happen, the driver/firmware would be in a bad state at that point anyway. So a call to carl9170_restart(ar, ...there's no code for a driver/firmware mismatch yet) will be necessary in the hope that this was just a temporary glitch. Cheers, Christian