# git rev-parse -q --verify e3a36eb6dfaeea8175c05d5915dcf0b939be6dab^{commit} e3a36eb6dfaeea8175c05d5915dcf0b939be6dab already have revision, skipping fetch # git checkout -q -f -B kisskb e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # git clean -qxdf # < git log -1 # commit e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # Author: Christoph Hellwig # Date: Wed Mar 11 17:07:10 2020 +0100 # # driver code: clarify and fix platform device DMA mask allocation # # This does three inter-related things to clarify the usage of the # platform device dma_mask field. In the process, fix the bug introduced # by cdfee5623290 ("driver core: initialize a default DMA mask for # platform device") that caused Artem Tashkinov's laptop to not boot with # newer Fedora kernels. # # This does: # # - First off, rename the field to "platform_dma_mask" to make it # greppable. # # We have way too many different random fields called "dma_mask" in # various data structures, where some of them are actual masks, and # some of them are just pointers to the mask. And the structures all # have pointers to each other, or embed each other inside themselves, # and "pdev" sometimes means "platform device" and sometimes it means # "PCI device". # # So to make it clear in the code when you actually use this new field, # give it a unique name (it really should be something even more unique # like "platform_device_dma_mask", since it's per platform device, not # per platform, but that gets old really fast, and this is unique # enough in context). # # To further clarify when the field gets used, initialize it when we # actually start using it with the default value. # # - Then, use this field instead of the random one-off allocation in # platform_device_register_full() that is now unnecessary since we now # already have a perfectly fine allocation for it in the platform # device structure. # # - The above then allows us to fix the actual bug, where the error path # of platform_device_register_full() would unconditionally free the # platform device DMA allocation with 'kfree()'. # # That kfree() was dont regardless of whether the allocation had been # done earlier with the (now removed) kmalloc, or whether # setup_pdev_dma_masks() had already been used and the dma_mask pointer # pointed to the mask that was part of the platform device. # # It seems most people never triggered the error path, or only triggered # it from a call chain that set an explicit pdevinfo->dma_mask value (and # thus caused the unnecessary allocation that was "cleaned up" in the # error path) before calling platform_device_register_full(). # # Robin Murphy points out that in Artem's case the wdat_wdt driver failed # in platform_device_add(), and that was the one that had called # platform_device_register_full() with pdevinfo.dma_mask = 0, and would # have caused that kfree() of pdev.dma_mask corrupting the heap. # # A later unrelated kmalloc() then oopsed due to the heap corruption. # # Fixes: cdfee5623290 ("driver core: initialize a default DMA mask for platform device") # Reported-bisected-and-tested-by: Artem S. Tashkinov # Reviewed-by: Robin Murphy # Cc: Greg Kroah-Hartman # Signed-off-by: Christoph Hellwig # Signed-off-by: Linus Torvalds # < /opt/cross/kisskb/gcc-4.6.3-nolibc/powerpc-linux/bin/powerpc-linux-gcc --version # < /opt/cross/kisskb/gcc-4.6.3-nolibc/powerpc-linux/bin/powerpc-linux-ld --version # < git log --format=%s --max-count=1 e3a36eb6dfaeea8175c05d5915dcf0b939be6dab # < make -s -j 80 ARCH=powerpc O=/kisskb/build/linus_corenet64_smp_defconfig_powerpc-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/powerpc-linux/bin/powerpc-linux- corenet64_smp_defconfig # < make -s -j 80 ARCH=powerpc O=/kisskb/build/linus_corenet64_smp_defconfig_powerpc-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/powerpc-linux/bin/powerpc-linux- help # make -s -j 80 ARCH=powerpc O=/kisskb/build/linus_corenet64_smp_defconfig_powerpc-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/powerpc-linux/bin/powerpc-linux- olddefconfig # make -s -j 80 ARCH=powerpc O=/kisskb/build/linus_corenet64_smp_defconfig_powerpc-gcc4.6 CROSS_COMPILE=/opt/cross/kisskb/gcc-4.6.3-nolibc/powerpc-linux/bin/powerpc-linux- /kisskb/src/kernel/printk/printk.c: In function 'devkmsg_sysctl_set_loglvl': /kisskb/src/kernel/printk/printk.c:204:16: warning: 'old' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/proc/inode.c: In function 'proc_reg_open': /kisskb/src/include/linux/list.h:72:12: warning: 'pdeo' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/proc/inode.c:338:21: note: 'pdeo' was declared here /kisskb/src/fs/ext4/extents.c: In function 'ext4_convert_unwritten_io_end_vec': /kisskb/src/fs/ext4/extents.c:5009:23: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/kernel/trace/trace_events.c: In function 'event_create_dir': /kisskb/src/kernel/trace/trace_events.c:2040:6: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/mm/hugetlb.c: In function 'alloc_pool_huge_page': /kisskb/src/mm/hugetlb.c:1426:5: warning: 'page' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/tty/serial/8250/8250_core.c: In function 'univ8250_release_irq': /kisskb/src/drivers/tty/serial/8250/8250_core.c:247:18: warning: 'i' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/tty/serial/8250/8250_core.c:227:19: note: 'i' was declared here /kisskb/src/drivers/base/regmap/regmap.c: In function 'regmap_raw_read': /kisskb/src/drivers/base/regmap/regmap.c:2598:6: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/base/regmap/regmap.c: In function '_regmap_raw_write': /kisskb/src/drivers/base/regmap/regmap.c:1859:6: warning: 'ret' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/drivers/usb/core/devio.c: In function 'async_completed': /kisskb/src/drivers/usb/core/devio.c:625:23: warning: 'errno' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/udf/unicode.c: In function 'udf_name_conv_char': /kisskb/src/fs/udf/unicode.c:132:8: warning: 'c' may be used uninitialized in this function [-Wuninitialized] /kisskb/src/fs/io_uring.c: In function '__io_sqe_files_update': /kisskb/src/fs/io_uring.c:5845:13: warning: 'err' may be used uninitialized in this function [-Wuninitialized] WARNING: vmlinux.o (.PPC.EMB.apuinfo): unexpected non-allocatable section. Did you forget to use "ax"/"aw" in a .S file? Note that for example contains section definitions for use in .S files. INFO: Uncompressed kernel (size 0x10c2988) overlaps the address of the wrapper(0x400000) INFO: Fixing the link_address of wrapper to (0x1100000) Image Name: Linux-5.6.0-rc5-ge3a36eb6dfae Created: Thu Mar 12 04:28:10 2020 Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size: 7010323 Bytes = 6846.02 KiB = 6.69 MiB Load Address: 00000000 Entry Point: 00000000 Completed OK # rm -rf /kisskb/build/linus_corenet64_smp_defconfig_powerpc-gcc4.6 # Build took: 0:02:12.517001