Subject: CVE-2021-47205: clk: sunxi-ng: Unregister clocks/resets when unbinding

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

clk: sunxi-ng: Unregister clocks/resets when unbinding

Currently, unbinding a CCU driver unmaps the device's MMIO region, while
leaving its clocks/resets and their providers registered. This can cause
a page fault later when some clock operation tries to perform MMIO. Fix
this by separating the CCU initialization from the memory allocation,
and then using a devres callback to unregister the clocks and resets.

This also fixes a memory leak of the `struct ccu_reset`, and uses the
correct owner (the specific platform driver) for the clocks and resets.

Early OF clock providers are never unregistered, and limited error
handling is possible, so they are mostly unchanged. The error reporting
is made more consistent by moving the message inside of_sunxi_ccu_probe.

The Linux kernel CVE team has assigned CVE-2021-47205 to this issue.

Affected and fixed versions
===========================

	Fixed in 5.15.5 with commit b5dd513daa70
	Fixed in 5.16 with commit 9bec2b9c6134

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2021-47205
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/clk/sunxi-ng/ccu-sun4i-a10.c
	drivers/clk/sunxi-ng/ccu-sun50i-a100-r.c
	drivers/clk/sunxi-ng/ccu-sun50i-a100.c
	drivers/clk/sunxi-ng/ccu-sun50i-a64.c
	drivers/clk/sunxi-ng/ccu-sun50i-h6-r.c
	drivers/clk/sunxi-ng/ccu-sun50i-h6.c
	drivers/clk/sunxi-ng/ccu-sun50i-h616.c
	drivers/clk/sunxi-ng/ccu-sun5i.c
	drivers/clk/sunxi-ng/ccu-sun6i-a31.c
	drivers/clk/sunxi-ng/ccu-sun8i-a23.c
	drivers/clk/sunxi-ng/ccu-sun8i-a33.c
	drivers/clk/sunxi-ng/ccu-sun8i-a83t.c
	drivers/clk/sunxi-ng/ccu-sun8i-de2.c
	drivers/clk/sunxi-ng/ccu-sun8i-h3.c
	drivers/clk/sunxi-ng/ccu-sun8i-r.c
	drivers/clk/sunxi-ng/ccu-sun8i-r40.c
	drivers/clk/sunxi-ng/ccu-sun8i-v3s.c
	drivers/clk/sunxi-ng/ccu-sun9i-a80-de.c
	drivers/clk/sunxi-ng/ccu-sun9i-a80-usb.c
	drivers/clk/sunxi-ng/ccu-sun9i-a80.c
	drivers/clk/sunxi-ng/ccu-suniv-f1c100s.c
	drivers/clk/sunxi-ng/ccu_common.c
	drivers/clk/sunxi-ng/ccu_common.h

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/b5dd513daa70ee8f6d281a20bd28485ee9bb7db2
	https://git.kernel.org/stable/c/9bec2b9c6134052994115d2d3374e96f2ccb9b9d