Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3057198ioo; Tue, 24 May 2022 12:01:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz0H11mKFk9bcPP8THY8XdVU2XveidQyeLIwOEKW8ekI39uiDI2m8wVHmC2mcAKGxMliOO X-Received: by 2002:a05:6402:5c9:b0:420:aac6:257b with SMTP id n9-20020a05640205c900b00420aac6257bmr30095921edx.128.1653418910469; Tue, 24 May 2022 12:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653418910; cv=none; d=google.com; s=arc-20160816; b=fYPPmDvnKIoKl7mkQNr2whu2ezdqvjh3wNoVZhDJfWfqKUCXVx9swN1/4f+GgjU/59 K0UCHm9/dezQisulzqibp3A7ACPg06nEEqhHHyMgtCJyaZLBWTDxMNQJqPknINF7fT69 Xw9Z2N8DraWd6d7DluBhneOxnZOPnEJwq6v/nKCFe8edJcj3X/chURW5NbyiiDNN14va c0/oiDKNQhAsi97E+j5eOXTckIBvzojYHYWSCUTIoPu95EF2ftUDs2y7AgaE90OJsBTU FTfgvlnkov62U6tHI+qp/tmn9pPXMArb3NVwCi7/ZKmGmuYzeF/KHyALnaROllcYTUIU OOgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:feedback-id:message-id:subject :reply-to:from:to:dkim-signature:date; bh=eub/et+mHH8VEHCirBk8CEjJyfwhvFaMCP9BnHpivR4=; b=dUg2T87fWtBy+SSVTaNLb4BQPaRsEMGxK6uvXtnCiP6UUBdud8RLuSJqF+vGTb7XKy Tq1Afd+ZeFpVUH9n5dnip8bPTnQKoT50OAlkAY/u8uy2UPsl++MZMZFY8Mr4rfbnXy1v E/W4QS8Ccew/Y6y9dZ92QjDu4l7eamB5RxAwirdX3XcFJGr/xgkrcL9HKUl8vo6Gd4do eMfXem5gKR7BZodqFgQes27l+mcJ75Jx0TpCmNJNym8j/ftLQ5Rd5u0vXR7p7uxHduR2 B+8Q1AQfdBBOeiEdDMrsdGGQto3C0hUl/mFMwsenbrPlKx3T6iNlv8fKhHH9sjSqbwBC RuFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dannyvanheumen.nl header.s=protonmail2 header.b=f1qHqhS4; 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=NONE dis=NONE) header.from=dannyvanheumen.nl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt19-20020a170907729300b006ff09d27800si1123793ejc.536.2022.05.24.12.01.31; Tue, 24 May 2022 12:01:50 -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=@dannyvanheumen.nl header.s=protonmail2 header.b=f1qHqhS4; 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=NONE dis=NONE) header.from=dannyvanheumen.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238066AbiEXQwD (ORCPT + 67 others); Tue, 24 May 2022 12:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234234AbiEXQv7 (ORCPT ); Tue, 24 May 2022 12:51:59 -0400 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467033B54E for ; Tue, 24 May 2022 09:51:57 -0700 (PDT) Date: Tue, 24 May 2022 16:51:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dannyvanheumen.nl; s=protonmail2; t=1653411112; x=1653670312; bh=eub/et+mHH8VEHCirBk8CEjJyfwhvFaMCP9BnHpivR4=; h=Date:To:From:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc: Date:Subject:Reply-To:Feedback-ID:Message-ID; b=f1qHqhS4rH/7CTLRQqhKUdNnGFDc+FfoylppBrQCBZqGNjN1haXmUtCfkF+0QrMEP rMYxwgUYDLUW+KriohCNPE2MO8ZD+LUJDzKC8bO9RIf0F1upHWKCaLIr67tZTkYGjA KtN/3Aiq1Dy79VmPq7ijTbZmKAFOb70CD2JiIrA5EAHFZH8qhX6drOJ2q7eWfC5gNF uD7GEu8MZb1KMJegSL294XB+Zp9s6/lf9OsnR8adJdIrreALigyWMf6jz8coAOf7wh gUM2nuP4cUpeqn9hapUdebnxY0idA9bkzWgm68tWXKBvujEiI47ygI3DPhpQVozlLa K5LF0r1WYy0MA== To: Arend van Spriel , Franky Lin , Hante Meuleman , "linux-wireless@vger.kernel.org" , "brcm80211-dev-list.pdl@broadcom.com" , "SHA-cyfmac-dev-list@infineon.com" From: Danny van Heumen Reply-To: Danny van Heumen Subject: [PATCH] work-in-progress: double-free after hardware reset due to firmware-crash Message-ID: Feedback-ID: 15073070:user:proton MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="b1_RPhNPD9Bya3UKZFdwHbHQzdDkAkL7WNqxfiTeZTk" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 This is a multi-part message in MIME format. --b1_RPhNPD9Bya3UKZFdwHbHQzdDkAkL7WNqxfiTeZTk Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dear all, I am not a regular C developer nor kernel developer. I don't regularly repo= rt issues, so I will probably do things wrong. I investigated a crash that IIUC occurs with hardened memory allocation ena= bled and a firmware-crash followed by an early failure during hardware rein= itialization/probing. The hardened allocator detects double-free issue. I have created the patch (see attachment) against linux-5.18. Though, pleas= e check carefully, because I have not been able to confirm that it actually= works. I am hoping someone familiar with the code-base can either test thi= s easily, or confirm from review/analysis. The commit message describes it in more detail. In summary: 'brcmf_sdio_bus_reset' cleans up and reinitializes the hardware. It frees m= emory used by (struct brcmf_sdio_dev)->freezer (struct brcmf_sdiod_freezer)= . However, it then goes to probe the hardware, and an early failure to prob= e results in the same freeing, both called through function 'brcmf_sdiod_fr= eezer_detach' called inside 'brcmf_sdiod_remove'. Which results in double f= reeing. As mentioned before, I was not able to test this and I do not regularly dev= elop in C. I am not confident that this is the proper way to fix it, but it= seemed obvious enough. I hope you can support in fixing this bug. Kind regards, Danny PS: Please let me know if I am doing things wrong. I have included both mai= ntainers and mailing lists from https://docs.kernel.org/process/maintainers= .html#broadcom-brcm80211-ieee802-11n-wireless-driver I hope I this is alrig= ht. --b1_RPhNPD9Bya3UKZFdwHbHQzdDkAkL7WNqxfiTeZTk Content-Type: text/x-patch; name=0001-brcmfmac-prevent-double-free-on-hardware-reset.patch Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=0001-brcmfmac-prevent-double-free-on-hardware-reset.patch RnJvbSBkZGIyODFlMmViZjdlNmJkODlmMDkxNDAzNjE2YTlkNzdkNzNiZTYzIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBEYW5ueSB2YW4gSGV1bWVuIDxkYW5ueUBkYW5ueXZhbmhldW1l bi5ubD4KRGF0ZTogVHVlLCAyNCBNYXkgMjAyMiAxODozMDo1MCArMDIwMApTdWJqZWN0OiBbUEFU Q0hdIGJyY21mbWFjOiBwcmV2ZW50IGRvdWJsZS1mcmVlIG9uIGhhcmR3YXJlLXJlc2V0LgoKSW4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