Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp36100pxb; Mon, 13 Sep 2021 12:14:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIpnHjxXigfYKYois+Pxt92e8Wo3JET7bZci7NM9mibSzg8rLJIEytt4mFIVk+Kta0xDP5 X-Received: by 2002:a02:2b01:: with SMTP id h1mr11363666jaa.133.1631560467456; Mon, 13 Sep 2021 12:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631560467; cv=none; d=google.com; s=arc-20160816; b=UyBuBT1TBt7j60sQ7M6a1DlM8HK1qAtntDsimfmAmHFRJyndyS64n5gWNpJjb1aT9G U/ePb7F2mgbY5QYABkvA3DYvYJgckiqpJ9q/VcYVzys3/3uaooGaBlNFVP1c9JR3x4Ae MQoMOIHbVeTpJJR8dBDJZ16yaaX+CjHoz5lgW7VdmDGPi8+Pv6VFIHhArQiTJyOxCHfw j3oH6Bz4HFZnUEp4Z3S9uRPMaUKVck5Hy605eaI2HLeFC+DzB5XZKqfQgUvOt+P8bGS1 YHd0CWwLIR/s0J0jncBjDLk4TrJGJSlku+TDdMuhJx13sEcbsPsEC9eXGgr+TWmnYdKn 95Jg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pjSVpAuKLubHIajPsrQwBEzqROdzWkLBGS3yoCttANY=; b=zSMJG1AmHYRBEpFU52PQHaZ2FlxULagybM5dz75bdB4YCi8tBA2XacjGaOCNbd7ksu 4DE+82YmwOUip7E7PMmqaEUqgjyo9kGkg5NXEmoKvi0F8Bx+cwnM0z5fFVgltMVuc6Fw psmZ/onCKZ8J3td01HqdOIpQ7SX0DT0sO1HYjPcZ0HHh4FVBAGmyHmOdsJCJwpkKCu6b 4EDBygGvwaRT+8NZZ2pKmh+sRF+razFKXZmQD1hJQysCVNYFQA6pyN75NyUXBdMeQU4p 7zMLl/OR0yPybwBmzAGlmcUGcGaVAeCtDlbu2xqTP8KOx3IFKxa3LWp1OQ+9Sb42zEdi +ShQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Yf0ntNjX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si7065834ios.58.2021.09.13.12.14.15; Mon, 13 Sep 2021 12:14:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Yf0ntNjX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241623AbhIMNdH (ORCPT + 99 others); Mon, 13 Sep 2021 09:33:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:34844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241365AbhIMNYA (ORCPT ); Mon, 13 Sep 2021 09:24:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F057360724; Mon, 13 Sep 2021 13:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539306; bh=cHZumzlrM6+tZYz5z+PpTZySAuJUyF2i/7mgvc4lVKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yf0ntNjXZjBcx00BTH2SRRSL2+hLPNirSqy1dpN/GgSKFgwByMtWz32ttChMFiif3 sFzVQmurETmR9VAll9bVM5Oh1DJoMlIQ2AHYgWpjFqWDmigyxqGGk72cuVdA4eY6qZ 4IGzqnPgGjnhdFGPaFneLz6hR6ND0Mod/kfn1j00= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zenghui Yu , Kalle Valo , Sasha Levin Subject: [PATCH 5.4 119/144] bcma: Fix memory leak for internally-handled cores Date: Mon, 13 Sep 2021 15:15:00 +0200 Message-Id: <20210913131051.906335372@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zenghui Yu [ Upstream commit b63aed3ff195130fef12e0af590f4838cf0201d8 ] kmemleak reported that dev_name() of internally-handled cores were leaked on driver unbinding. Let's use device_initialize() to take refcounts for them and put_device() to properly free the related stuff. While looking at it, there's another potential issue for those which should be *registered* into driver core. If device_register() failed, we put device once and freed bcma_device structures. In bcma_unregister_cores(), they're treated as unregistered and we hit both UAF and double-free. That smells not good and has also been fixed now. Fixes: ab54bc8460b5 ("bcma: fill core details for every device") Signed-off-by: Zenghui Yu Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20210727025232.663-2-yuzenghui@huawei.com Signed-off-by: Sasha Levin --- drivers/bcma/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c index 6535614a7dc1..1df2b5801c3b 100644 --- a/drivers/bcma/main.c +++ b/drivers/bcma/main.c @@ -236,6 +236,7 @@ EXPORT_SYMBOL(bcma_core_irq); void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core) { + device_initialize(&core->dev); core->dev.release = bcma_release_core_dev; core->dev.bus = &bcma_bus_type; dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index); @@ -277,11 +278,10 @@ static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core) { int err; - err = device_register(&core->dev); + err = device_add(&core->dev); if (err) { bcma_err(bus, "Could not register dev for core 0x%03X\n", core->id.id); - put_device(&core->dev); return; } core->dev_registered = true; @@ -372,7 +372,7 @@ void bcma_unregister_cores(struct bcma_bus *bus) /* Now noone uses internally-handled cores, we can free them */ list_for_each_entry_safe(core, tmp, &bus->cores, list) { list_del(&core->list); - kfree(core); + put_device(&core->dev); } } -- 2.30.2