1. 26 Sep, 2019 7 commits
    • Suzuki K Poulose's avatar
      usb: yurex: Fix use-after-free in yurex_delete · 1557a4bb
      Suzuki K Poulose authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit fc05481b upstream.
      
      syzbot reported the following crash [0]:
      
      BUG: KASAN: use-after-free in usb_free_coherent+0x79/0x80
      drivers/usb/core/usb.c:928
      Read of size 8 at addr ffff8881b18599c8 by task syz-executor.4/16007
      
      CPU: 0 PID: 16007 Comm: syz-executor.4 Not tainted 5.3.0-rc2+ #23
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      Call Trace:
        __dump_stack lib/dump_stack.c:77 [inline]
        dump_stack+0xca/0x13e lib/dump_stack.c:113
        print_address_description+0x6a/0x32c mm/kasan/report.c:351
        __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:482
        kasan_report+0xe/0x12 mm/kasan/common.c:612
        usb_free_coherent+0x79/0x80 drivers/usb/core/usb.c:928
        yurex_delete+0x138/0x330 drivers/usb/misc/yurex.c:100
        kref_put include/linux/kref.h:65 [inline]
        yurex_release+0x66/0x90 drivers/usb/misc/yurex.c:392
        __fput+0x2d7/0x840 fs/file_table.c:280
        task_work_run+0x13f/0x1c0 kernel/task_work.c:113
        tracehook_notify_resume include/linux/tracehook.h:188 [inline]
        exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
        prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
        syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
        do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
        entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x413511
      Code: 75 14 b8 03 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 04 1b 00 00 c3 48
      83 ec 08 e8 0a fc ff ff 48 89 04 24 b8 03 00 00 00 0f 05 <48> 8b 3c 24 48
      89 c2 e8 53 fc ff ff 48 89 d0 48 83 c4 08 48 3d 01
      RSP: 002b:00007ffc424ea2e0 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
      RAX: 0000000000000000 RBX: 0000000000000007 RCX: 0000000000413511
      RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000006
      RBP: 0000000000000001 R08: 0000000029a2fc22 R09: 0000000029a2fc26
      R10: 00007ffc424ea3c0 R11: 0000000000000293 R12: 000000000075c9a0
      R13: 000000000075c9a0 R14: 0000000000761938 R15: ffffffffffffffff
      
      Allocated by task 2776:
        save_stack+0x1b/0x80 mm/kasan/common.c:69
        set_track mm/kasan/common.c:77 [inline]
        __kasan_kmalloc mm/kasan/common.c:487 [inline]
        __kasan_kmalloc.constprop.0+0xbf/0xd0 mm/kasan/common.c:460
        kmalloc include/linux/slab.h:552 [inline]
        kzalloc include/linux/slab.h:748 [inline]
        usb_alloc_dev+0x51/0xf95 drivers/usb/core/usb.c:583
        hub_port_connect drivers/usb/core/hub.c:5004 [inline]
        hub_port_connect_change drivers/usb/core/hub.c:5213 [inline]
        port_event drivers/usb/core/hub.c:5359 [inline]
        hub_event+0x15c0/0x3640 drivers/usb/core/hub.c:5441
        process_one_work+0x92b/0x1530 kernel/workqueue.c:2269
        worker_thread+0x96/0xe20 kernel/workqueue.c:2415
        kthread+0x318/0x420 kernel/kthread.c:255
        ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352
      
      Freed by task 16007:
        save_stack+0x1b/0x80 mm/kasan/common.c:69
        set_track mm/kasan/common.c:77 [inline]
        __kasan_slab_free+0x130/0x180 mm/kasan/common.c:449
        slab_free_hook mm/slub.c:1423 [inline]
        slab_free_freelist_hook mm/slub.c:1470 [inline]
        slab_free mm/slub.c:3012 [inline]
        kfree+0xe4/0x2f0 mm/slub.c:3953
        device_release+0x71/0x200 drivers/base/core.c:1064
        kobject_cleanup lib/kobject.c:693 [inline]
        kobject_release lib/kobject.c:722 [inline]
        kref_put include/linux/kref.h:65 [inline]
        kobject_put+0x171/0x280 lib/kobject.c:739
        put_device+0x1b/0x30 drivers/base/core.c:2213
        usb_put_dev+0x1f/0x30 drivers/usb/core/usb.c:725
        yurex_delete+0x40/0x330 drivers/usb/misc/yurex.c:95
        kref_put include/linux/kref.h:65 [inline]
        yurex_release+0x66/0x90 drivers/usb/misc/yurex.c:392
        __fput+0x2d7/0x840 fs/file_table.c:280
        task_work_run+0x13f/0x1c0 kernel/task_work.c:113
        tracehook_notify_resume include/linux/tracehook.h:188 [inline]
        exit_to_usermode_loop+0x1d2/0x200 arch/x86/entry/common.c:163
        prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
        syscall_return_slowpath arch/x86/entry/common.c:274 [inline]
        do_syscall_64+0x45f/0x580 arch/x86/entry/common.c:299
        entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      The buggy address belongs to the object at ffff8881b1859980
        which belongs to the cache kmalloc-2k of size 2048
      The buggy address is located 72 bytes inside of
        2048-byte region [ffff8881b1859980, ffff8881b185a180)
      The buggy address belongs to the page:
      page:ffffea0006c61600 refcount:1 mapcount:0 mapping:ffff8881da00c000
      index:0x0 compound_mapcount: 0
      flags: 0x200000000010200(slab|head)
      raw: 0200000000010200 0000000000000000 0000000100000001 ffff8881da00c000
      raw: 0000000000000000 00000000000f000f 00000001ffffffff 0000000000000000
      page dumped because: kasan: bad access detected
      
      Memory state around the buggy address:
        ffff8881b1859880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
        ffff8881b1859900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      > ffff8881b1859980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                     ^
        ffff8881b1859a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
        ffff8881b1859a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
      ==================================================================
      
      A quick look at the yurex_delete() shows that we drop the reference
      to the usb_device before releasing any buffers associated with the
      device. Delay the reference drop until we have finished the cleanup.
      
      [0] https://lore.kernel.org/lkml/0000000000003f86d8058f0bd671@google.com/
      
      Fixes: 6bc235a2 ("USB: add driver for Meywa-Denki & Kayac YUREX")
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Tomoki Sekiyama <tomoki.sekiyama@gmail.com>
      Cc: Oliver Neukum <oneukum@suse.com>
      Cc: andreyknvl@google.com
      Cc: gregkh@linuxfoundation.org
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: syzkaller-bugs@googlegroups.com
      Cc: dtor@chromium.org
      Reported-by: syzbot+d1fedb1c1fdb07fca507@syzkaller.appspotmail.com
      Signed-off-by: default avatarSuzuki K Poulose <suzuki.poulose@arm.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20190805111528.6758-1-suzuki.poulose@arm.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      1557a4bb
    • Adrian Hunter's avatar
      perf db-export: Fix thread__exec_comm() · 6c4bd820
      Adrian Hunter authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit 3de7ae0b upstream.
      
      Threads synthesized from /proc have comms with a start time of zero, and
      not marked as "exec". Currently, there can be 2 such comms. The first is
      created by processing a synthesized fork event and is set to the
      parent's comm string, and the second by processing a synthesized comm
      event set to the thread's current comm string.
      
      In the absence of an "exec" comm, thread__exec_comm() picks the last
      (oldest) comm, which, in the case above, is the parent's comm string.
      For a main thread, that is very probably wrong. Use the second-to-last
      in that case.
      
      This affects only db-export because it is the only user of
      thread__exec_comm().
      
      Example:
      
        $ sudo perf record -a -o pt-a-sleep-1 -e intel_pt//u -- sleep 1
        $ sudo chown ahunter pt-a-sleep-1
      
      Before:
      
        $ perf script -i pt-a-sleep-1 --itrace=bep -s tools/perf/scripts/python/export-to-sqlite.py pt-a-sleep-1.db branches calls
        $ sqlite3 -header -column pt-a-sleep-1.db 'select * from comm_threads_view'
        comm_id     command     thread_id   pid         tid
        ----------  ----------  ----------  ----------  ----------
        1           swapper     1           0           0
        2           rcu_sched   2           10          10
        3           kthreadd    3           78          78
        5           sudo        4           15180       15180
        5           sudo        5           15180       15182
        7           kworker/4:  6           10335       10335
        8           kthreadd    7           55          55
        10          systemd     8           865         865
        10          systemd     9           865         875
        13          perf        10          15181       15181
        15          sleep       10          15181       15181
        16          kworker/3:  11          14179       14179
        17          kthreadd    12          29376       29376
        19          systemd     13          746         746
        21          systemd     14          401         401
        23          systemd     15          879         879
        23          systemd     16          879         945
        25          kthreadd    17          556         556
        27          kworker/u1  18          14136       14136
        28          kworker/u1  19          15021       15021
        29          kthreadd    20          509         509
        31          systemd     21          836         836
        31          systemd     22          836         967
        33          systemd     23          1148        1148
        33          systemd     24          1148        1163
        35          kworker/2:  25          17988       17988
        36          kworker/0:  26          13478       13478
      
      After:
      
        $ perf script -i pt-a-sleep-1 --itrace=bep -s tools/perf/scripts/python/export-to-sqlite.py pt-a-sleep-1b.db branches calls
        $ sqlite3 -header -column pt-a-sleep-1b.db 'select * from comm_threads_view'
        comm_id     command     thread_id   pid         tid
        ----------  ----------  ----------  ----------  ----------
        1           swapper     1           0           0
        2           rcu_sched   2           10          10
        3           kswapd0     3           78          78
        4           perf        4           15180       15180
        4           perf        5           15180       15182
        6           kworker/4:  6           10335       10335
        7           kcompactd0  7           55          55
        8           accounts-d  8           865         865
        8           accounts-d  9           865         875
        10          perf        10          15181       15181
        12          sleep       10          15181       15181
        13          kworker/3:  11          14179       14179
        14          kworker/1:  12          29376       29376
        15          haveged     13          746         746
        16          systemd-jo  14          401         401
        17          NetworkMan  15          879         879
        17          NetworkMan  16          879         945
        19          irq/131-iw  17          556         556
        20          kworker/u1  18          14136       14136
        21          kworker/u1  19          15021       15021
        22          kworker/u1  20          509         509
        23          thermald    21          836         836
        23          thermald    22          836         967
        25          unity-sett  23          1148        1148
        25          unity-sett  24          1148        1163
        27          kworker/2:  25          17988       17988
        28          kworker/0:  26          13478       13478
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: stable@vger.kernel.org
      Fixes: 65de51f9 ("perf tools: Identify which comms are from exec")
      Link: http://lkml.kernel.org/r/20190808064823.14846-1-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      6c4bd820
    • Joerg Roedel's avatar
      mm/vmalloc: Sync unmappings in __purge_vmap_area_lazy() · 153bbd9a
      Joerg Roedel authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit 3f8fd02b upstream.
      
      On x86-32 with PTI enabled, parts of the kernel page-tables are not shared
      between processes. This can cause mappings in the vmalloc/ioremap area to
      persist in some page-tables after the region is unmapped and released.
      
      When the region is re-used the processes with the old mappings do not fault
      in the new mappings but still access the old ones.
      
      This causes undefined behavior, in reality often data corruption, kernel
      oopses and panics and even spontaneous reboots.
      
      Fix this problem by activly syncing unmaps in the vmalloc/ioremap area to
      all page-tables in the system before the regions can be re-used.
      
      References: https://bugzilla.suse.com/show_bug.cgi?id=1118689
      Fixes: 5d72b4fb ('x86, mm: support huge I/O mapping capability I/F')
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Link: https://lkml.kernel.org/r/20190719184652.11391-4-joro@8bytes.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      153bbd9a
    • Joerg Roedel's avatar
      x86/mm: Sync also unmappings in vmalloc_sync_all() · 2956153c
      Joerg Roedel authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit 8e998fc2 upstream.
      
      With huge-page ioremap areas the unmappings also need to be synced between
      all page-tables. Otherwise it can cause data corruption when a region is
      unmapped and later re-used.
      
      Make the vmalloc_sync_one() function ready to sync unmappings and make sure
      vmalloc_sync_all() iterates over all page-tables even when an unmapped PMD
      is found.
      
      Fixes: 5d72b4fb ('x86, mm: support huge I/O mapping capability I/F')
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Link: https://lkml.kernel.org/r/20190719184652.11391-3-joro@8bytes.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      2956153c
    • Joerg Roedel's avatar
      x86/mm: Check for pfn instead of page in vmalloc_sync_one() · f4c115a7
      Joerg Roedel authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit 51b75b5b upstream.
      
      Do not require a struct page for the mapped memory location because it
      might not exist. This can happen when an ioremapped region is mapped with
      2MB pages.
      
      Fixes: 5d72b4fb ('x86, mm: support huge I/O mapping capability I/F')
      Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
      Link: https://lkml.kernel.org/r/20190719184652.11391-2-joro@8bytes.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      f4c115a7
    • Wenwen Wang's avatar
      sound: fix a memory leak bug · 4d8b5026
      Wenwen Wang authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit c7cd7c74 upstream.
      
      In sound_insert_unit(), the controlling structure 's' is allocated through
      kmalloc(). Then it is added to the sound driver list by invoking
      __sound_insert_unit(). Later on, if __register_chrdev() fails, 's' is
      removed from the list through __sound_remove_unit(). If 'index' is not less
      than 0, -EBUSY is returned to indicate the error. However, 's' is not
      deallocated on this execution path, leading to a memory leak bug.
      
      To fix the above issue, free 's' before -EBUSY is returned.
      Signed-off-by: default avatarWenwen Wang <wenwen@cs.uga.edu>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      4d8b5026
    • Oliver Neukum's avatar
      usb: iowarrior: fix deadlock on disconnect · bd9ba5d3
      Oliver Neukum authored
      BugLink: https://bugs.launchpad.net/bugs/1845038
      
      commit c468a8aa upstream.
      
      We have to drop the mutex before we close() upon disconnect()
      as close() needs the lock. This is safe to do by dropping the
      mutex as intfdata is already set to NULL, so open() will fail.
      
      Fixes: 03f36e88 ("USB: open disconnect race in iowarrior")
      Reported-by: syzbot+a64a382964bf6c71a9c0@syzkaller.appspotmail.com
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: default avatarOliver Neukum <oneukum@suse.com>
      Link: https://lore.kernel.org/r/20190808092728.23417-1-oneukum@suse.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
      Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
      bd9ba5d3
  2. 17 Sep, 2019 33 commits