From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>,
Felipe Balbi <felipe.balbi@linux.intel.com>
Subject: [PATCH 4.11 59/78] USB: gadget: fix GPF in gadgetfs
Date: Mon, 19 Jun 2017 23:15:59 +0800 [thread overview]
Message-ID: <20170619151031.639306389@linuxfoundation.org> (raw)
In-Reply-To: <20170619151029.408399976@linuxfoundation.org>
4.11-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <stern@rowland.harvard.edu>
commit f50b878fed33e360d01dcdc31a8eeb1815d033d5 upstream.
A NULL-pointer dereference bug in gadgetfs was uncovered by syzkaller:
> kasan: GPF could be caused by NULL-ptr deref or user memory access
> general protection fault: 0000 [#1] SMP KASAN
> Dumping ftrace buffer:
> (ftrace buffer empty)
> Modules linked in:
> CPU: 2 PID: 4820 Comm: syz-executor0 Not tainted 4.12.0-rc4+ #5
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> task: ffff880039542dc0 task.stack: ffff88003bdd0000
> RIP: 0010:__list_del_entry_valid+0x7e/0x170 lib/list_debug.c:51
> RSP: 0018:ffff88003bdd6e50 EFLAGS: 00010246
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000010000
> RDX: 0000000000000000 RSI: ffffffff86504948 RDI: ffffffff86504950
> RBP: ffff88003bdd6e68 R08: ffff880039542dc0 R09: ffffffff8778ce00
> R10: ffff88003bdd6e68 R11: dffffc0000000000 R12: 0000000000000000
> R13: dffffc0000000000 R14: 1ffff100077badd2 R15: ffffffff864d2e40
> FS: 0000000000000000(0000) GS:ffff88006dc00000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 000000002014aff9 CR3: 0000000006022000 CR4: 00000000000006e0
> Call Trace:
> __list_del_entry include/linux/list.h:116 [inline]
> list_del include/linux/list.h:124 [inline]
> usb_gadget_unregister_driver+0x166/0x4c0 drivers/usb/gadget/udc/core.c:1387
> dev_release+0x80/0x160 drivers/usb/gadget/legacy/inode.c:1187
> __fput+0x332/0x7f0 fs/file_table.c:209
> ____fput+0x15/0x20 fs/file_table.c:245
> task_work_run+0x19b/0x270 kernel/task_work.c:116
> exit_task_work include/linux/task_work.h:21 [inline]
> do_exit+0x18a3/0x2820 kernel/exit.c:878
> do_group_exit+0x149/0x420 kernel/exit.c:982
> get_signal+0x77f/0x1780 kernel/signal.c:2318
> do_signal+0xd2/0x2130 arch/x86/kernel/signal.c:808
> exit_to_usermode_loop+0x1a7/0x240 arch/x86/entry/common.c:157
> prepare_exit_to_usermode arch/x86/entry/common.c:194 [inline]
> syscall_return_slowpath+0x3ba/0x410 arch/x86/entry/common.c:263
> entry_SYSCALL_64_fastpath+0xbc/0xbe
> RIP: 0033:0x4461f9
> RSP: 002b:00007fdac2b1ecf8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
> RAX: fffffffffffffe00 RBX: 00000000007080c8 RCX: 00000000004461f9
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000007080c8
> RBP: 00000000007080a8 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
> R13: 0000000000000000 R14: 00007fdac2b1f9c0 R15: 00007fdac2b1f700
> Code: 00 00 00 00 ad de 49 39 c4 74 6a 48 b8 00 02 00 00 00 00 ad de
> 48 89 da 48 39 c3 74 74 48 c1 ea 03 48 b8 00 00 00 00 00 fc ff df <80>
> 3c 02 00 0f 85 92 00 00 00 48 8b 13 48 39 f2 75 66 49 8d 7c
> RIP: __list_del_entry_valid+0x7e/0x170 lib/list_debug.c:51 RSP: ffff88003bdd6e50
> ---[ end trace 30e94b1eec4831c8 ]---
> Kernel panic - not syncing: Fatal exception
The bug was caused by dev_release() failing to turn off its
gadget_registered flag after unregistering the gadget driver. As a
result, when a later user closed the device file before writing a
valid set of descriptors, dev_release() thought the gadget had been
registered and tried to unregister it, even though it had not been.
This led to the NULL pointer dereference.
The fix is simple: turn off the flag when the gadget is unregistered.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/usb/gadget/legacy/inode.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1182,8 +1182,10 @@ dev_release (struct inode *inode, struct
/* closing ep0 === shutdown all */
- if (dev->gadget_registered)
+ if (dev->gadget_registered) {
usb_gadget_unregister_driver (&gadgetfs_driver);
+ dev->gadget_registered = false;
+ }
/* at this point "good" hardware has disconnected the
* device from USB; the host won't see it any more.
next prev parent reply other threads:[~2017-06-19 15:21 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-19 15:15 [PATCH 4.11 00/78] 4.11.7-stable review Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 01/78] fs: pass on flags in compat_writev Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 02/78] configfs: Fix race between create_link and configfs_rmdir Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 03/78] can: gs_usb: fix memory leak in gs_cmd_reset() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 04/78] ila_xlat: add missing hash secret initialization Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 06/78] [media] vb2: Fix an off by one error in vb2_plane_vaddr Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 07/78] [media] cec: race fix: dont return -ENONET in cec_receive() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 08/78] selinux: fix double free in selinux_parse_opts_str() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 09/78] mac80211: dont look at the PM bit of BAR frames Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 10/78] mac80211/wpa: use constant time memory comparison for MACs Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 11/78] drm: mxsfb_crtc: Reset the eLCDIF controller Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 12/78] drm/amdgpu: Fix overflow of watermark calcs at > 4k resolutions Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 13/78] drm/i915: Fix GVT-g PVINFO version compatibility check Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 15/78] drm/i915: Do not sync RCU during shrinking Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 16/78] mac80211: fix IBSS presp allocation size Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 17/78] mac80211: strictly check mesh address extension mode Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 18/78] mac80211: fix dropped counter in multiqueue RX Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 19/78] mac80211: dont send SMPS action frame in AP mode when not needed Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 20/78] drm/mediatek: fix mtk_hdmi_setup_vendor_specific_infoframe mistake Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 21/78] drm/vc4: Fix OOPSes from trying to cache a partially constructed BO Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 23/78] serial: 8250_lpss: Unconditionally set PCI master for Quark Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 24/78] serial: sh-sci: Fix (AUTO)RTS in sci_init_pins() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 25/78] serial: sh-sci: Fix late enablement of AUTORTS Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 26/78] x86/mm/32: Set the __vmalloc_start_set flag in initmem_init() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 27/78] mfd: omap-usb-tll: Fix inverted bit use for USB TLL mode Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 28/78] mfd: axp20x: Add support for dts property "xpowers,master-mode" Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 29/78] dt-bindings: mfd: axp20x: Add "xpowers,master-mode" property for AXP806 PMICs Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 30/78] mfd: cpcap: Fix interrupt to use level interrupt Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 31/78] mfd: cpcap: Use ack_invert interrupts Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 32/78] mfd: cpcap: Fix bad use of IRQ sense register Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 33/78] phy: rcar-gen3-usb2: fix implementation for runtime PM Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 34/78] mtd: physmap_of: really fix the physmap add-ons Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 35/78] powerpc/mm: Add physical address to Linux page table dump Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 36/78] staging: rtl8188eu: prevent an underflow in rtw_check_beacon_data() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 37/78] staging: bcm2835-camera: fix error handling in init Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 38/78] staging: iio: tsl2x7x_core: Fix standard deviation calculation Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 39/78] iio: imu: st_lsm6dsx: do not apply ODR configuration in write_raw handler Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 40/78] iio: proximity: as3935: recalibrate RCO after resume Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 41/78] iio: adc: ti_am335x_adc: allocating too much in probe Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 42/78] ALSA: hda: Add Geminilake id to SKL_PLUS Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 43/78] ALSA: usb-audio: fix Amanero Combo384 quirk on big-endian hosts Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 44/78] usb: gadget: udc: renesas_usb3: fix pm_runtime functions calling Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 45/78] usb: gadget: udc: renesas_usb3: fix deadlock by spinlock Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 46/78] usb: gadget: udc: renesas_usb3: lock for PN_ registers access Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 47/78] USB: hub: fix SS max number of ports Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 48/78] usb: core: fix potential memory leak in error path during hcd creation Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 49/78] USB: usbip: fix nonconforming hub descriptor Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 50/78] usb: dwc3: gadget: Fix ISO transfer performance Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 51/78] [media] pvrusb2: reduce stack usage pvr2_eeprom_analyze() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 52/78] USB: gadget: dummy_hcd: fix hub-descriptor removable fields Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 53/78] usb: r8a66597-hcd: select a different endpoint on timeout Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 54/78] usb: r8a66597-hcd: decrease timeout Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 55/78] [media] coda: restore original firmware locations Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 56/78] drivers/misc/c2port/c2port-duramar2150.c: checking for NULL instead of IS_ERR() Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 57/78] usb: xhci: Fix USB 3.1 supported protocol parsing Greg Kroah-Hartman
2017-06-19 15:15 ` [PATCH 4.11 58/78] usb: xhci: ASMedia ASM1042A chipset need shorts TX quirk Greg Kroah-Hartman
2017-06-19 15:15 ` Greg Kroah-Hartman [this message]
2017-06-19 15:16 ` [PATCH 4.11 60/78] USB: gadgetfs, dummy-hcd, net2280: fix locking for callbacks Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 61/78] mm/memory-failure.c: use compound_head() flags for huge pages Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 62/78] swap: cond_resched in swap_cgroup_prepare() Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 63/78] mm: numa: avoid waiting on freed migrated pages Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 64/78] userfaultfd: shmem: handle coredumping in handle_userfault() Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 65/78] iio: imu: inv_mpu6050: add accel lpf setting for chip >= MPU6500 Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 66/78] staging: iio: ad7152: Fix deadlock in ad7152_write_raw_samp_freq() Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 67/78] iio: adc: meson-saradc: fix potential crash in meson_sar_adc_clear_fifo Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 68/78] sched/core: Idle_task_exit() shouldnt use switch_mm_irqs_off() Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 69/78] genirq: Release resources in __setup_irq() error path Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 70/78] alarmtimer: Prevent overflow of relative timers Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 71/78] alarmtimer: Rate limit periodic intervals Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 72/78] virtio_balloon: disable VIOMMU support Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 73/78] MIPS: Fix bnezc/jialc return address calculation Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 74/78] MIPS: .its targets depend on vmlinux Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 75/78] crypto: Work around deallocated stack frame reference gcc bug on sparc Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 76/78] ARM: dts: am335x-sl50: Fix card detect pin for mmc1 Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 77/78] ARM: dts: am335x-sl50: Fix cannot claim requested pins for spi0 Greg Kroah-Hartman
2017-06-19 15:16 ` [PATCH 4.11 78/78] mm: larger stack guard gap, between vmas Greg Kroah-Hartman
2017-06-19 22:48 ` [PATCH 4.11 00/78] 4.11.7-stable review Guenter Roeck
2017-06-20 0:54 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170619151031.639306389@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=felipe.balbi@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).