Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2318997pxb; Mon, 20 Sep 2021 18:41:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTpEavtIfh0bqtt9e2/l9ZJxOyiGMTKcIKYJxTI2nk0UXDfjr96SPasivXpWlOaRrFZTL+ X-Received: by 2002:a6b:dd0c:: with SMTP id f12mr4915094ioc.117.1632188500688; Mon, 20 Sep 2021 18:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188500; cv=none; d=google.com; s=arc-20160816; b=JEsjXTLaaf6GKBSPmU+E0mT5LEyuhFODvhenJXTz8J62W3JcedyKmAt5fL1PeZ5F4a D7GMEXnbsun2qrT4aqzLjWorDydvid2e22w5NqoAJZA6MNopC/Z9WiSWc5wmnG3dnP/6 PgQF4NGh0AY9m7EOhXU1JncyBrgBCX/eUDblvVf4OZDUJFzKxe7qAeAkqQfL0iV+VgJW RqPcqOcNp9+/QvMvQeUl+Yc2O5WoHWSykA3VNKeXeZaXDmMRLUxpZ9Sp7qQoSIt9N9z1 kha4KSZ5K0/V7f8mWm9yyRqCT2zrzBhO+FsQj4+a7K0Q8D/Sva41VYnZVgZSFe8lWAVa QPvQ== 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=KnN8anG5Dak6DTaDF+AU7uPKIEF4wpTm9kYIMs6fGS0=; b=HAE+dKR9sycVCl4Uv5OWR2Wie6oFyaLB/mgynOC+s0hMcgbYl3JS6peu+5znNNwvRk lzmdc5E5TCyvYhiMBXpZAi1UOlK56BSfxGd9k96n0dlFF3fu+3ndHj8Ij0PqMRMP6rvD LMsBEomdn3qfhzREu/1a/pbh0ejHHsgfDTh+m78vmlneCffbHPTT7XbXtYKeYqIAbOz4 ymABkHHCSfNw+YQFbEHBnKLsIEJh5nSeqnGvtxA7Mns5j3TuiHg4KAUS4pNPLSWZJoWH FP3MKSvx8Gb87wmdbjOnnBP49JfoCssWb0/czaRkYngcrmaGs8Ah754ox4k76tZ/T+45 /3aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yRO1d5yS; 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 d6si15245269ios.63.2021.09.20.18.41.29; Mon, 20 Sep 2021 18:41:40 -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=yRO1d5yS; 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 S244412AbhITQuO (ORCPT + 99 others); Mon, 20 Sep 2021 12:50:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:35746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236735AbhITQtG (ORCPT ); Mon, 20 Sep 2021 12:49:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C269F6124A; Mon, 20 Sep 2021 16:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156452; bh=EilGhHmjxJ4GkuYk2HAGE4cchxQ1H6wSlnwmazFEnDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yRO1d5ySnKvrnjZQ6kADyahSEijWDZwK+7/VLbOMi1sgQFe3fr4XVT6r1QTLSsJXL ldxkNJibDDvEDlghp9JP/Q0oGI3IqIKz2QYSUgeOD3FF57ZCa5UFUhwefzFnw9/5+H b5g/iw2KKWkctDS7Rp3AxviqNzjq4W6WAxZ2k1kg= 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 4.4 066/133] bcma: Fix memory leak for internally-handled cores Date: Mon, 20 Sep 2021 18:42:24 +0200 Message-Id: <20210920163914.807839243@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 327f9e374b44..30827ab3bb07 100644 --- a/drivers/bcma/main.c +++ b/drivers/bcma/main.c @@ -246,6 +246,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); @@ -309,11 +310,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; @@ -404,7 +404,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