Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp74100pxb; Mon, 13 Sep 2021 13:18:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVoEPdWIF6XEuwZ0nzVXiwGl3hT5UdJby5At/liCXHWrh2WbaySnqOKoFd2327+lYN+fcg X-Received: by 2002:a17:906:8a41:: with SMTP id gx1mr13363169ejc.507.1631564313231; Mon, 13 Sep 2021 13:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631564313; cv=none; d=google.com; s=arc-20160816; b=YQi6s/z8lLyrrfmGJnaV7+E53V3ArumVDzS1yg0i0sy7UCqQiuIqXilQF7u03u6Of3 fyeOdG1xUWQQKi3dFwCxCSzxoXq8YpBn6w/QI+5NFhqmftTf+d6F1uIm9+lG86CiFxFN Sh7z4NQVDvoijuWFpEliOECZMUftPYdzXnJdgauSaNoaGgvNgw9EqJlctAwAKO32h18f pxW/2JqWto1IuQMVUdF0ifUmYYqJJUweTYJT6L9o1WoYO4sZM9DVqMfVHFqfbud2fPuc BrjL4L3VR3Fi3pkghycnIisIbrdFr1fGf1xP0b/qquRqjEr4ZST6TOsBLukxRoxx+YTq iaTg== 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=pzhXQ2jcHCGn6W3yf8SLA9IR/QWcCxpI3rneXgkwRKx3MELnqy1P+SJ/jE7Unq7jIC LOt1NONcrw5IeJNTodIJfSyHZmMGFcGWMObhsKfgGUGxyEIcagydHzJawHSFdXvki09j A8U3oc/oLFkgc/rOe/n0CRh7yAF1xbsDoN8JTihhp9QEX7/4nrhPbLs+0tZieUBFEaQC 5CPH4oL3cPyWkGIBBER433PmWHJwLlj346ZRAbnXJ+u4yvFm6gYZF9L1eprrlN2PpuX/ 5GoXFtlxz00GbF6lu1oaqr74UShuHOPJ7W67z97HWBGQvxxra8VXyjS5Ax063F22b8mU gSCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IvKgg7Pu; 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 bs18si8506923ejb.674.2021.09.13.13.18.09; Mon, 13 Sep 2021 13:18:33 -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=IvKgg7Pu; 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 S243191AbhIMNv6 (ORCPT + 99 others); Mon, 13 Sep 2021 09:51:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:56744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244077AbhIMNrc (ORCPT ); Mon, 13 Sep 2021 09:47:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 722AD6121E; Mon, 13 Sep 2021 13:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539941; bh=cHZumzlrM6+tZYz5z+PpTZySAuJUyF2i/7mgvc4lVKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvKgg7PuP11F6DDqEuJ1vxrTaazETr2gqWn1FdVsUlU68e4JUZTqG+AoKxs6O/VBw Z0ZbjehSZJQCer3XYEGCeMVw0rbioRYX3cgqCZ4FfvHG1OB5tEP1Lat7jPLzIVcx5I Z+xDNvSN8VGICiO5JdHIwtcbDWfDufIu0HGgR7QA= 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.10 205/236] bcma: Fix memory leak for internally-handled cores Date: Mon, 13 Sep 2021 15:15:10 +0200 Message-Id: <20210913131107.357124858@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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