android_kernel_oneplus_msm8998/drivers
Sultan Alsawaf 1b37d68f4c ANDROID: Fix massive cpufreq_times memory leaks
Every time _cpu_up() is called for a CPU, idle_thread_get() is called
which then re-initializes a CPU's idle thread that was already
previously created and cached in a global variable in
smpboot.c. idle_thread_get() calls init_idle() which then calls
__sched_fork(). __sched_fork() is where cpufreq_task_times_init() is,
and cpufreq_task_times_init() allocates memory for the task struct's
time_in_state array.

Since idle_thread_get() reuses a task struct instance that was already
previously created, this means that every time it calls init_idle(),
cpufreq_task_times_init() allocates this array again and overwrites
the existing allocation that the idle thread already had.

This causes memory to be leaked every time a CPU is onlined. In order
to fix this, move allocation of time_in_state into _do_fork to avoid
allocating it at all for idle threads. The cpufreq times interface is
intended to be used for tracking userspace tasks, so we can safely
remove it from the kernel's idle threads without killing any
functionality.

But that's not all!

Task structs can be freed outside of release_task(), which creates
another memory leak because a task struct can be freed without having
its cpufreq times allocation freed. To fix this, free the cpufreq
times allocation at the same time that task struct allocations are
freed, in free_task().

Since free_task() can also be called in error paths of copy_process()
after dup_task_struct(), set time_in_state to NULL immediately after
calling dup_task_struct() to avoid possible double free.

Bug description and fix adapted from patch submitted by
Sultan Alsawaf <sultanxda@gmail.com> at
https://android-review.googlesource.com/c/kernel/msm/+/700134

Bug: 110044919
Test: Hikey960 builds, boots & reports /proc/<pid>/time_in_state
correctly
Change-Id: I12fe7611fc88eb7f6c39f8f7629ad27b6ec4722c
Signed-off-by: Connor O'Brien <connoro@google.com>
2018-07-18 13:21:38 +00:00
..
accessibility printk: move braille console support into separate braille.[ch] files 2013-07-31 14:41:03 -07:00
acpi ACPICA: acpi: acpica: fix acpi operand cache leak in nseval.c 2018-05-30 07:49:11 +02:00
amba ARM: amba: Don't read past the end of sysfs "driver_override" buffer 2018-05-02 07:53:42 -07:00
android UPSTREAM: binder: replace "%p" with "%pK" 2018-07-17 12:48:06 +02:00
ata ahci: Disable LPM on Lenovo 50 series laptops with a too old BIOS 2018-07-17 11:31:43 +02:00
atm atm: zatm: fix memcmp casting 2018-07-03 11:21:24 +02:00
auxdisplay auxdisplay: ks0108: initialize local parport variable 2015-08-14 17:27:17 -07:00
base This is the 4.4.139 stable release 2018-07-03 18:23:34 +02:00
bcma bcma: use (get|put)_device when probing/removing device driver 2017-03-12 06:37:30 +01:00
block loop: remember whether sysfs_create_group() was done 2018-07-17 11:31:46 +02:00
bluetooth Bluetooth: hci_qca: Avoid missing rampatch failure with userspace fw loader 2018-07-03 11:21:28 +02:00
bus bus: brcmstb_gisb: correct support for 64-bit address output 2018-04-13 19:50:05 +02:00
cdrom cdrom: do not call check_disk_change() inside cdrom_open() 2018-05-30 07:49:13 +02:00
char ipmi:bt: Set the timeout before doing a capabilities check 2018-07-03 11:21:28 +02:00
clk clk: samsung: exynos3250: Fix PLL rates 2018-05-30 07:49:16 +02:00
clocksource This is the 4.4.134 stable release 2018-05-30 13:25:24 +02:00
connector connector: bump skb->users before callback invocation 2016-01-04 21:46:45 -05:00
cpufreq ANDROID: Fix massive cpufreq_times memory leaks 2018-07-18 13:21:38 +00:00
cpuidle This is the 4.4.139 stable release 2018-07-03 18:23:34 +02:00
crypto crypto: vmx - Remove overly verbose printk from AES init routines 2018-06-16 09:54:27 +02:00
dca dca: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
devfreq PM / devfreq: Propagate error from devfreq_add_device() 2018-02-22 15:44:58 +01:00
dio m68k: don't export static inline functions 2009-12-06 11:18:28 +01:00
dma dmaengine: usb-dmac: fix endless loop in usb_dmac_chan_terminate_all() 2018-06-06 16:46:22 +02:00
dma-buf CHROMIUM: android: fix warning when releasing active sync point 2016-02-16 13:53:25 -08:00
edac EDAC, mv64x60: Fix an error handling path 2018-04-13 19:50:23 +02:00
eisa Revert "EISA: Initialize device before its resources" 2014-01-17 14:57:29 -07:00
extcon extcon: palmas: Check the parent instance to prevent the NULL 2017-11-21 09:21:18 +01:00
firewire firewire-ohci: work around oversized DMA reads on JMicron controllers 2018-05-30 07:48:52 +02:00
firmware This is the 4.4.134 stable release 2018-05-30 13:25:24 +02:00
fmc Merge 3.14-rc5 into char-misc-next 2014-03-02 19:53:09 -08:00
fpga fpga manager: Fix firmware resource leak on error 2015-11-24 15:25:46 -08:00
gpio gpio: No NULL owner 2018-06-16 09:54:26 +02:00
gpu This is the 4.4.137 stable release 2018-06-13 16:36:26 +02:00
hid This is the 4.4.141 stable release 2018-07-17 12:15:52 +02:00
hsi HSI: ssi_protocol: double free in ssip_pn_xmit() 2018-03-24 10:58:42 +01:00
hv Drivers: hv: vmbus: fix build warning 2018-02-25 11:03:46 +01:00
hwmon hwmon: (pmbus/adm1275) Accept negative page register values 2018-05-30 07:49:13 +02:00
hwspinlock drivers/hwspinlock: fix race between radix tree insertion and lookup 2016-02-25 12:01:23 -08:00
hwtracing hwtracing: stm: fix build error on some arches 2018-06-06 16:46:23 +02:00
i2c i2c: rcar: fix resume by always initializing registers before transfer 2018-07-11 16:03:47 +02:00
ide cdrom: do not call check_disk_change() inside cdrom_open() 2018-05-30 07:49:13 +02:00
idle idle: i7300: add PCI dependency 2018-02-25 11:03:51 +01:00
iio iio:buffer: make length types match kfifo types 2018-07-03 11:21:30 +02:00
infiniband RDMA/ucm: Mark UCM interface as BROKEN 2018-07-17 11:31:46 +02:00
input This is the 4.4.139 stable release 2018-07-03 18:23:34 +02:00
iommu x86/cpufeature: Remove unused and seldomly used cpu_has_xx macros 2018-06-16 09:54:24 +02:00
ipack ipoctal: clear break interrupt as soon as it occurs 2014-09-23 23:26:42 -07:00
irqchip This is the 4.4.134 stable release 2018-05-30 13:25:24 +02:00
isdn isdn: eicon: fix a missing-check bug 2018-06-13 16:15:28 +02:00
leds leds: pca955x: Correct I2C Functionality 2018-04-13 19:50:09 +02:00
lguest Merge branch 'x86-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2015-06-22 17:59:09 -07:00
lightnvm lightnvm: put bio before return 2016-09-24 10:07:35 +02:00
macintosh drivers/macintosh: adb: fix misleading Kconfig help text 2015-10-15 20:31:59 +11:00
mailbox mailbox: handle empty message in tx_tick 2017-08-06 19:19:41 -07:00
mcb mcb: Fixed bar number assignment for the gdd 2016-06-01 12:15:53 -07:00
md This is the 4.4.140 stable release 2018-07-11 16:24:21 +02:00
media media: cx25840: Use subdev host data for PLL override 2018-07-11 16:03:51 +02:00
memory ARM: OMAP2+: gpmc-onenand: propagate error on initialization failure 2017-12-16 10:33:51 +01:00
memstick memstick: rtsx_usb_ms: Manage runtime PM when accessing the device 2016-10-28 03:01:35 -04:00
message scsi: mptfusion: Add bounds check in mptctl_hp_targetinfo() 2018-05-30 07:48:58 +02:00
mfd mfd: intel-lpss: Program REMAP register in PIO mode 2018-07-03 11:21:32 +02:00
misc This is the 4.4.141 stable release 2018-07-17 12:15:52 +02:00
mmc This is the 4.4.134 stable release 2018-05-30 13:25:24 +02:00
mtd This is the 4.4.140 stable release 2018-07-11 16:24:21 +02:00
net This is the 4.4.140 stable release 2018-07-11 16:24:21 +02:00
nfc This is the 4.4.123 stable release 2018-03-22 09:57:28 +01:00
ntb ntb_transport: Fix bug with max_mw_size parameter 2018-05-30 07:48:55 +02:00
nubus nubus: Remove superfluous interrupt disable/restore 2014-10-27 11:03:19 +01:00
nvdimm linvdimm, pmem: Preserve read-only setting for pmem devices 2018-07-03 11:21:31 +02:00
nvme nvme-pci: initialize queue memory before interrupts 2018-07-11 16:03:47 +02:00
nvmem nvmem: imx-ocotp: Fix wrong register size 2017-08-06 19:19:46 -07:00
of This is the 4.4.139 stable release 2018-07-03 18:23:34 +02:00
oprofile Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2015-04-26 17:22:07 -07:00
parisc parisc/pci: Switch LBA PCI bus from Hard Fail to Soft Fail mode 2018-05-30 07:49:10 +02:00
parport parport_pc: Add support for WCH CH382L PCI-E single parallel port card. 2018-04-08 11:52:00 +02:00
pci PCI: pciehp: Clear Presence Detect and Data Link Layer Status Changed on resume 2018-07-03 11:21:30 +02:00
pcmcia pcmcia: db1xxx_ss: fix last irq_to_gpio user 2016-04-20 15:42:09 +09:00
perf This is the 4.4.123 stable release 2018-03-22 09:57:28 +01:00
phy phy: work around 'phys' references to usb-nop-xceiv devices 2018-01-23 19:50:16 +01:00
pinctrl pinctrl: Really force states during suspend/resume 2018-03-24 10:58:48 +01:00
platform goldfish: pipe: ANDROID: address must be written as __pa(x), not x 2018-06-05 09:42:36 -07:00
pnp PNP: Add Broadwell to Intel MCH size workaround 2016-08-16 09:30:48 +02:00
power This is the 4.4.124 stable release 2018-03-25 10:51:55 +02:00
powercap PowerCap: Fix an error code in powercap_register_zone() 2018-04-13 19:50:05 +02:00
pps pps: do not crash when failed to register 2016-08-10 11:49:25 +02:00
ps3 drivers/ps3: Fix ps3-vuart null dereference 2015-09-29 23:00:58 +10:00
ptp time: Change posix clocks ops interfaces to use timespec64 2018-03-24 10:58:40 +01:00
pwm pwm: tegra: Increase precision in PWM rate calculation 2018-03-22 09:23:27 +01:00
rapidio Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2015-06-23 14:08:54 -07:00
ras x86/ras: Move AMD MCE injector to arch/x86/ras/ 2015-08-13 10:12:54 +02:00
regulator regulator: of: Add a missing 'of_node_put()' in an error handling path of 'of_regulator_match()' 2018-05-30 07:49:17 +02:00
remoteproc remoteproc: Fix potential race condition in rproc_add 2016-08-20 18:09:20 +02:00
reset reset: ath79: Fix missing spin_lock_init 2015-09-01 14:48:40 +02:00
rpmsg virtio_rpmsg: set DRIVER_OK before using device 2015-03-13 15:55:42 +10:30
rtc This is the 4.4.134 stable release 2018-05-30 13:25:24 +02:00
s390 scsi: zfcp: fix missing REC trigger trace on enqueue without ERP thread 2018-07-03 11:21:31 +02:00
sbus drivers/sbus/char/envctrl.c: ignore orderly_poweroff return value 2015-04-15 16:35:23 -07:00
scsi This is the 4.4.140 stable release 2018-07-11 16:24:21 +02:00
sfi SFI: fix compiler warnings 2014-12-03 18:49:20 -05:00
sh drivers: sh: Restore legacy clock domain on SuperH platforms 2016-03-09 15:34:49 -08:00
sn Drivers: misc: remove __dev* attributes. 2013-01-03 15:57:16 -08:00
soc soc: qcom/spm: shut up uninitialized variable warning 2016-09-24 10:07:42 +02:00
spi spi: Fix scatterlist elements size in spi_map_buf 2018-07-03 11:21:35 +02:00
spmi spmi: Include OF based modalias in device uevent 2017-07-27 15:06:10 -07:00
ssb ssb: mark ssb_bus_register as __maybe_unused 2018-02-25 11:03:44 +01:00
staging This is the 4.4.140 stable release 2018-07-11 16:24:21 +02:00
target tcm_fileio: Prevent information leak for short reads 2018-03-24 10:58:45 +01:00
tc TC: Error handling clean-ups 2014-11-24 07:45:25 +01:00
tee BACKPORT: tee: shm: Potential NULL dereference calling tee_shm_register() 2018-02-21 15:40:49 +00:00
thermal thermal: imx: Fix race condition in imx_thermal_probe() 2018-04-24 09:32:08 +02:00
thunderbolt thunderbolt: Resume control channel after hibernation image is created 2018-04-24 09:32:07 +02:00
tty This is the 4.4.140 stable release 2018-07-11 16:24:21 +02:00
uio uio: fix dmem_region_start computation 2016-10-31 04:13:59 -06:00
usb This is the 4.4.141 stable release 2018-07-17 12:15:52 +02:00
uwb uwb: ensure that endpoint is interrupt 2017-10-12 11:27:35 +02:00
vfio vfio/pci: Virtualize Maximum Read Request Size 2018-04-24 09:32:09 +02:00
vhost vhost: correctly remove wait queue during poll failure 2018-04-13 19:50:25 +02:00
video This is the 4.4.139 stable release 2018-07-03 18:23:34 +02:00
virt drivers: clean-up prom.h implicit includes 2013-10-09 20:04:04 -05:00
virtio virtio_balloon: prevent uninitialized variable use 2018-02-25 11:03:42 +01:00
vlynq drivers/vlynq/vlynq.c: fix another resource size off by 1 error 2014-01-23 16:36:55 -08:00
vme vme: Fix wrong pointer utilization in ca91cx42_slave_get 2017-01-19 20:17:21 +01:00
w1 This is the 4.4.139 stable release 2018-07-03 18:23:34 +02:00
watchdog watchdog: f71808e_wdt: Fix magic close handling 2018-05-30 07:49:03 +02:00
xen xen: Remove unnecessary BUG_ON from __unbind_from_irq() 2018-07-03 11:21:34 +02:00
zorro zorro: Set up z->dev.dma_mask for the DMA API 2018-05-30 07:49:11 +02:00
Kconfig tee: generic TEE subsystem 2017-12-02 06:53:27 +00:00
Makefile This is the 4.4.118 stable release 2018-02-26 09:24:57 +01:00