From patchwork Thu Oct 20 11:40:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arend van Spriel X-Patchwork-Id: 617472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E11C5C4332F for ; Thu, 20 Oct 2022 11:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbiJTLmF (ORCPT ); Thu, 20 Oct 2022 07:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231400AbiJTLmE (ORCPT ); Thu, 20 Oct 2022 07:42:04 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D191C1DD887 for ; Thu, 20 Oct 2022 04:42:01 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id j8so1908756qvo.6 for ; Thu, 20 Oct 2022 04:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=ilfTHDklLr+k1WgHwtlP4qYX3mg+ioPviYqgWNGMoDc=; b=LLzz2Rlw+FCgmJgRD4Asq/B9/tAfgWKkKwrDBgA3kD6wumvwIHSiCUgx7WuB1MkScO pWvpdTSTz2jar+vTP8Oo/Ly0kzuAocJ6ryv8j0R8puYyL6pi9jv65PE1/ZEpwfQL2yRl ktz3Ykia2DfsoC51/XtpIqGA3+InZ4i5y2Gbc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ilfTHDklLr+k1WgHwtlP4qYX3mg+ioPviYqgWNGMoDc=; b=P0WHF5fkzH+yQPaAIYkn3kLLegxJVeOl2BdXkvu866wK1UVNGPFyYa5lxh+NtSBc2L Jiy3/jJUV5E+zvpeKo9iufSmbsl4QQJhBjX79/X5lWNRMaTotTD95XD5dssnTQxrWHbP e7af0mroxB7qndFpYaEPiRP1sC8pm0dXxAuVX3Hr9+xUVMEyrmyJuGApSMEvAzWOjfDI 32up9icxIVyIvOgXSPS66PD8wtgv5bT9Cz2Sy2z/gxRNuk07G7hoVdzcc0ST9PnIJbHa 7ezt+LHBhbkEkDGuSamWyvPBGDVLIcpdMUl1vntqH4DrMUowJdTLhIRRC1QO+M36S9eY HClQ== X-Gm-Message-State: ACrzQf2bF+cTe06rMRfqIg6PgmE1plbLujOEbAqkm+VzV58KOj2zG3X/ f1xaloMtHm71u0enDmczutqrb7BFO0lEHoxk X-Google-Smtp-Source: AMsMyM6WsMqPUumxmmDn+yvyoFbIH2YhaH6FgssWlwB2OZ34Se7HYoxACGwJyJCezlFg56FCe2aR3g== X-Received: by 2002:a0c:b20c:0:b0:4ac:c5b7:e5ca with SMTP id x12-20020a0cb20c000000b004acc5b7e5camr10749206qvd.126.1666266120992; Thu, 20 Oct 2022 04:42:00 -0700 (PDT) Received: from bld-bun-02.bun.broadcom.com ([192.19.148.250]) by smtp.gmail.com with ESMTPSA id oo12-20020a05620a530c00b006eeae49537bsm6915017qkn.98.2022.10.20.04.41.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2022 04:41:59 -0700 (PDT) From: Arend van Spriel To: Kalle Valo Cc: linux-wireless@vger.kernel.org, Arend van Spriel Subject: [PATCH V2] wifi: cfg80211: fix memory leak in query_regdb_file() Date: Thu, 20 Oct 2022 13:40:40 +0200 Message-Id: <20221020114040.169564-1-arend.vanspriel@broadcom.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 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 --- Got a hint from Florian that previous patch had line wrapping hence this update. Also got sending emails using my work email going so changing indentities here. Regards, Arend --- 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)