Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp958278rwi; Wed, 19 Oct 2022 05:12:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rrRFmQeYOa/+08HBxo0yVvlFl7xsM1XiGYeBkrVSxquJ5/k5B/RFkS5pOGrXbEo/DHJdm X-Received: by 2002:a17:906:730d:b0:78e:9ca5:3269 with SMTP id di13-20020a170906730d00b0078e9ca53269mr6445619ejc.366.1666181529305; Wed, 19 Oct 2022 05:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666181529; cv=none; d=google.com; s=arc-20160816; b=DRIIpwrNEVm1Aw0MCKIgeKoJvdRK7lLi2KOprTMnNGgk9eORu2h70ijrN1kCiYO6iV Y+nqs3DnFo+0oI9r5t9enYxvzTb9YCjqbKOCzuEDkCiW4T3zIM+7y7KQeKjrmIWGbeGl wm5CIhVPxYPFunNsWo8I+viV/j394ihh/XTZyzf3PL4Hotyi0jNAw0i328QeZRhBqSq3 diw2poIb9yZHg8Fm4fAFFaUO8LJvgz86QkSEhAjqYKhY3A7frlGUn4N247n94rM7EY0d iF1FsMKjfrdj4n1NT5C+0wJdKrEqGc0dLE7P+0g3x3TfaWz2oB3/iqtBZ5cbhQkf6haC h3ug== 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:mime-version:from :dkim-signature; bh=LWXy3ixXhBh6Q+ZuZgHETSGEk5KoziqbQ5MQxqx+wbs=; b=asyOAWV4zVB1i6wepNhfOFbpBOQBvodsrLujrDP9lZIIirpkL7pUudUeoawVjSDVGt 5auAV336bXurc0daOosOJAbxnauF738+FaSFLwF90zSPUinRSxg93/7UsCMxes/O0yg7 flUdo0VD02vfEb1JSUGZmr+JZ/jjRiSZRyqDLj5bEjUR9kRx13NNmaMs3Wsn5WaUUxU4 1DmNpHe3lMoHX12iGmP3iOFay45Zu08eEcD/kKlQe2p8xfyBwrCoxplmu3ApneAI8EJP sVv9/kfRLnNZH6cJ7x5yzVbQYtV3vrF/yG2vTsGPKhETUD+pTD+fQwW7FDlgScxNXCim vOGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CaPw3qHT; 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 hz5-20020a1709072ce500b007919d2f6517si4257110ejc.737.2022.10.19.05.11.49; Wed, 19 Oct 2022 05:12:09 -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=CaPw3qHT; 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 S232754AbiJSMLC (ORCPT + 64 others); Wed, 19 Oct 2022 08:11:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233104AbiJSMJ1 (ORCPT ); Wed, 19 Oct 2022 08:09:27 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120C2107A85 for ; Wed, 19 Oct 2022 04:45:18 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id b2so39306963eja.6 for ; Wed, 19 Oct 2022 04:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=LWXy3ixXhBh6Q+ZuZgHETSGEk5KoziqbQ5MQxqx+wbs=; b=CaPw3qHT3TySqMmiNuwPFH+mLC2ACNuwLziAPyH7O4nkzf72qzK3ynkIwY6SGfClq9 5QaupJng8/SEmYdiXlpNVSq4kqDNO9rkcztr+gBSWXfxZbuJlSwcBEuEQrBlQtT+49sI E4QPybDNIjiEoLzI8NVa+kdtKP0IZlLax7NAih98SAUV0UUl8Jokv30R8sopdHB0n5DG 45f3iRasdqvDuHYcPKEO7GGpbA2vf9BWIZJq8UNAYFPyc+4gTYNyqsTG61mIB1sChxnq XN9U8MGT5tU/PtbHqgCZc8d0v4YwGdygb7tYGjMxLL8Kf6TUEQ49/PILKIb3rQqjtFtB sXmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LWXy3ixXhBh6Q+ZuZgHETSGEk5KoziqbQ5MQxqx+wbs=; b=cQUWIKNZdKPALGUeYDz6tH/Z208q56GeiJv5jf80aLIEVcJ/G+rHXQl5pOumiXtm49 JOMmE0N6eis7gjx8acSn9EjyfHz2RrOwhDadUjFKGb7jCL/RsmJ7CNbJV49vcvR83siF ENAOeZtEK3Bo0rD8es1XdRW7iXyLEoCGo5YZ3XpTYgLSGln0KUq+JV/kX3tHvZhxrsBv AbmgPT9TF5nry8eN/JPL6cy5rXKzU9rjWNXRcUvoAbwVUNQHRtyroUatuxXv/8C5xWTC 3HClREilgbT4SV2jDLhbNnC2RSDkONbn+2LVetKhU0Pn8pd134ErbvAGXcjNlgqn9Faa 1lag== X-Gm-Message-State: ACrzQf3IrzudawDzpfeafoVW2TMf7a40HMAtcNWWZBHq3kRWRiKMkl0/ ZeHdNxwdWYeGWSQlgVrBed8hkpS5UCGsOMUZqCY= X-Received: by 2002:a17:907:7621:b0:741:6656:bd14 with SMTP id jy1-20020a170907762100b007416656bd14mr6318806ejc.298.1666179859287; Wed, 19 Oct 2022 04:44:19 -0700 (PDT) Received: from 35650733073 named unknown by gmailapi.google.com with HTTPREST; Wed, 19 Oct 2022 04:44:18 -0700 From: Arend van Spriel X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Date: Wed, 19 Oct 2022 04:44:18 -0700 Message-ID: Subject: [PATCH] wifi: cfg80211: fix memory leak in query_regdb_file() To: Johannes Berg , arend.vanspriel@broadcom.com Cc: linux-wireless@vger.kernel.org, Arend van Spriel 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 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 In the function query_regdb_file() the alpha2 parameter is duplicated using kmemdup() and subsequently freed in regdb_fw_cb(). However, request_firmware_nowait() can fail without calling regdb_fw_cb() and thus leak memory. Fixes: 007f6c5e6eb4 ("cfg80211: support loading regulatory database as firmware file") Signed-off-by: Arend van Spriel --- net/wireless/reg.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index ec25924a1c26..f629c2e15fea 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -1080,6 +1080,8 @@ static void regdb_fw_cb(const struct firmware *fw, void *context) static int query_regdb_file(const char *alpha2) { + int err; + ASSERT_RTNL(); if (regdb) @@ -1089,9 +1091,13 @@ static int query_regdb_file(const char *alpha2) if (!alpha2) return -ENOMEM; - return request_firmware_nowait(THIS_MODULE, true, "regulatory.db", - ®_pdev->dev, GFP_KERNEL, - (void *)alpha2, regdb_fw_cb); + err = request_firmware_nowait(THIS_MODULE, true, "regulatory.db", + ®_pdev->dev, GFP_KERNEL, + (void *)alpha2, regdb_fw_cb); + if (err) + kfree(alpha2); + + return err; } int reg_reload_regdb(void) -- 2.35.1