1. 11 6月, 2020 1 次提交
  2. 25 5月, 2020 1 次提交
  3. 16 4月, 2020 1 次提交
  4. 26 3月, 2020 1 次提交
  5. 21 3月, 2020 1 次提交
    • T
      completion: Use simple wait queues · a5c6234e
      Thomas Gleixner 提交于
      completion uses a wait_queue_head_t to enqueue waiters.
      
      wait_queue_head_t contains a spinlock_t to protect the list of waiters
      which excludes it from being used in truly atomic context on a PREEMPT_RT
      enabled kernel.
      
      The spinlock in the wait queue head cannot be replaced by a raw_spinlock
      because:
      
        - wait queues can have custom wakeup callbacks, which acquire other
          spinlock_t locks and have potentially long execution times
      
        - wake_up() walks an unbounded number of list entries during the wake up
          and may wake an unbounded number of waiters.
      
      For simplicity and performance reasons complete() should be usable on
      PREEMPT_RT enabled kernels.
      
      completions do not use custom wakeup callbacks and are usually single
      waiter, except for a few corner cases.
      
      Replace the wait queue in the completion with a simple wait queue (swait),
      which uses a raw_spinlock_t for protecting the waiter list and therefore is
      safe to use inside truly atomic regions on PREEMPT_RT.
      
      There is no semantical or functional change:
      
        - completions use the exclusive wait mode which is what swait provides
      
        - complete() wakes one exclusive waiter
      
        - complete_all() wakes all waiters while holding the lock which protects
          the wait queue against newly incoming waiters. The conversion to swait
          preserves this behaviour.
      
      complete_all() might cause unbound latencies with a large number of waiters
      being woken at once, but most complete_all() usage sites are either in
      testing or initialization code or have only a really small number of
      concurrent waiters which for now does not cause a latency problem. Keep it
      simple for now.
      
      The fixup of the warning check in the USB gadget driver is just a straight
      forward conversion of the lockless waiter check from one waitqueue type to
      the other.
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NDavidlohr Bueso <dbueso@suse.de>
      Reviewed-by: NJoel Fernandes (Google) <joel@joelfernandes.org>
      Acked-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Link: https://lkml.kernel.org/r/20200321113242.317954042@linutronix.de
      a5c6234e
  6. 11 2月, 2020 1 次提交
  7. 08 2月, 2020 2 次提交
  8. 15 1月, 2020 1 次提交
    • P
      usb: gadget: f_fs: set req->num_sgs as 0 for non-sg transfer · d2450c69
      Peter Chen 提交于
      The UDC core uses req->num_sgs to judge if scatter buffer list is used.
      Eg: usb_gadget_map_request_by_dev. For f_fs sync io mode, the request
      is re-used for each request, so if the 1st request->length > PAGE_SIZE,
      and the 2nd request->length is <= PAGE_SIZE, the f_fs uses the 1st
      req->num_sgs for the 2nd request, it causes the UDC core get the wrong
      req->num_sgs value (The 2nd request doesn't use sg). For f_fs async
      io mode, it is not harm to initialize req->num_sgs as 0 either, in case,
      the UDC driver doesn't zeroed request structure.
      
      Cc: Jun Li <jun.li@nxp.com>
      Cc: stable <stable@vger.kernel.org>
      Fixes: 772a7a72 ("usb: gadget: f_fs: Allow scatter-gather buffers")
      Signed-off-by: NPeter Chen <peter.chen@nxp.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d2450c69
  9. 10 12月, 2019 1 次提交
  10. 23 10月, 2019 1 次提交
  11. 19 9月, 2019 1 次提交
  12. 18 6月, 2019 2 次提交
    • A
      usb: gadget: Zero ffs_io_data · 50859551
      Andrzej Pietrasiewicz 提交于
      In some cases the "Allocate & copy" block in ffs_epfile_io() is not
      executed. Consequently, in such a case ffs_alloc_buffer() is never called
      and struct ffs_io_data is not initialized properly. This in turn leads to
      problems when ffs_free_buffer() is called at the end of ffs_epfile_io().
      
      This patch uses kzalloc() instead of kmalloc() in the aio case and memset()
      in non-aio case to properly initialize struct ffs_io_data.
      Signed-off-by: NAndrzej Pietrasiewicz <andrzej.p@collabora.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      50859551
    • F
      usb: gadget: f_fs: data_len used before properly set · 4833a94e
      Fei Yang 提交于
      The following line of code in function ffs_epfile_io is trying to set
      flag io_data->use_sg in case buffer required is larger than one page.
      
          io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE;
      
      However at this point of time the variable data_len has not been set
      to the proper buffer size yet. The consequence is that io_data->use_sg
      is always set regardless what buffer size really is, because the condition
      (data_len > PAGE_SIZE) is effectively an unsigned comparison between
      -EINVAL and PAGE_SIZE which would always result in TRUE.
      
      Fixes: 772a7a72 ("usb: gadget: f_fs: Allow scatter-gather buffers")
      Signed-off-by: NFei Yang <fei.yang@intel.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      4833a94e
  13. 03 5月, 2019 1 次提交
    • F
      usb: gadget: f_fs: don't free buffer prematurely · 73103c7f
      Fei Yang 提交于
      The following kernel panic happens due to the io_data buffer gets deallocated
      before the async io is completed. Add a check for the case where io_data buffer
      should be deallocated by ffs_user_copy_worker.
      
      [   41.663334] BUG: unable to handle kernel NULL pointer dereference at 0000000000000048
      [   41.672099] #PF error: [normal kernel read fault]
      [   41.677356] PGD 20c974067 P4D 20c974067 PUD 20c973067 PMD 0
      [   41.683687] Oops: 0000 [#1] PREEMPT SMP
      [   41.687976] CPU: 1 PID: 7 Comm: kworker/u8:0 Tainted: G     U            5.0.0-quilt-2e5dc0ac-00790-gd8c79f2-dirty #2
      [   41.705309] Workqueue: adb ffs_user_copy_worker
      [   41.705316] RIP: 0010:__vunmap+0x2a/0xc0
      [   41.705318] Code: 0f 1f 44 00 00 48 85 ff 0f 84 87 00 00 00 55 f7 c7 ff 0f 00 00 48 89 e5 41 55 41 89 f5 41 54 53 48 89 fb 75 71 e8 56 d7 ff ff <4c> 8b 60 48 4d 85 e4 74 76 48 89 df e8 25 ff ff ff 45 85 ed 74 46
      [   41.705320] RSP: 0018:ffffbc3a40053df0 EFLAGS: 00010286
      [   41.705322] RAX: 0000000000000000 RBX: ffffbc3a406f1000 RCX: 0000000000000000
      [   41.705323] RDX: 0000000000000001 RSI: 0000000000000001 RDI: 00000000ffffffff
      [   41.705324] RBP: ffffbc3a40053e08 R08: 000000000001fb79 R09: 0000000000000037
      [   41.705325] R10: ffffbc3a40053b68 R11: ffffbc3a40053cad R12: fffffffffffffff2
      [   41.705326] R13: 0000000000000001 R14: 0000000000000000 R15: ffffffffffffffff
      [   41.705328] FS:  0000000000000000(0000) GS:ffff9e2977a80000(0000) knlGS:0000000000000000
      [   41.705329] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   41.705330] CR2: 0000000000000048 CR3: 000000020c994000 CR4: 00000000003406e0
      [   41.705331] Call Trace:
      [   41.705338]  vfree+0x50/0xb0
      [   41.705341]  ffs_user_copy_worker+0xe9/0x1c0
      [   41.705344]  process_one_work+0x19f/0x3e0
      [   41.705348]  worker_thread+0x3f/0x3b0
      [   41.829766]  kthread+0x12b/0x150
      [   41.833371]  ? process_one_work+0x3e0/0x3e0
      [   41.838045]  ? kthread_create_worker_on_cpu+0x70/0x70
      [   41.843695]  ret_from_fork+0x3a/0x50
      [   41.847689] Modules linked in: hci_uart bluetooth ecdh_generic rfkill_gpio dwc3_pci dwc3 snd_usb_audio mei_me tpm_crb snd_usbmidi_lib xhci_pci xhci_hcd mei tpm snd_hwdep cfg80211 snd_soc_skl snd_soc_skl_ipc snd_soc_sst_ipc snd_soc_sst_dsp snd_hda_ext_core snd_hda_core videobuf2_dma_sg crlmodule
      [   41.876880] CR2: 0000000000000048
      [   41.880584] ---[ end trace 2bc4addff0f2e673 ]---
      [   41.891346] RIP: 0010:__vunmap+0x2a/0xc0
      [   41.895734] Code: 0f 1f 44 00 00 48 85 ff 0f 84 87 00 00 00 55 f7 c7 ff 0f 00 00 48 89 e5 41 55 41 89 f5 41 54 53 48 89 fb 75 71 e8 56 d7 ff ff <4c> 8b 60 48 4d 85 e4 74 76 48 89 df e8 25 ff ff ff 45 85 ed 74 46
      [   41.916740] RSP: 0018:ffffbc3a40053df0 EFLAGS: 00010286
      [   41.922583] RAX: 0000000000000000 RBX: ffffbc3a406f1000 RCX: 0000000000000000
      [   41.930563] RDX: 0000000000000001 RSI: 0000000000000001 RDI: 00000000ffffffff
      [   41.938540] RBP: ffffbc3a40053e08 R08: 000000000001fb79 R09: 0000000000000037
      [   41.946520] R10: ffffbc3a40053b68 R11: ffffbc3a40053cad R12: fffffffffffffff2
      [   41.954502] R13: 0000000000000001 R14: 0000000000000000 R15: ffffffffffffffff
      [   41.962482] FS:  0000000000000000(0000) GS:ffff9e2977a80000(0000) knlGS:0000000000000000
      [   41.971536] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   41.977960] CR2: 0000000000000048 CR3: 000000020c994000 CR4: 00000000003406e0
      [   41.985930] Kernel panic - not syncing: Fatal exception
      [   41.991817] Kernel Offset: 0x16000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
      [   42.009525] Rebooting in 10 seconds..
      [   52.014376] ACPI MEMORY or I/O RESET_REG.
      
      Fixes: 772a7a72 ("usb: gadget: f_fs: Allow scatter-gather buffers")
      Signed-off-by: NFei Yang <fei.yang@intel.com>
      Reviewed-by: NManu Gautam <mgautam@codeaurora.org>
      Tested-by: NJohn Stultz <john.stultz@linaro.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      73103c7f
  14. 11 2月, 2019 1 次提交
    • J
      usb: f_fs: Avoid crash due to out-of-scope stack ptr access · 54f64d5c
      John Stultz 提交于
      Since the 5.0 merge window opened, I've been seeing frequent
      crashes on suspend and reboot with the trace:
      
      [   36.911170] Unable to handle kernel paging request at virtual address ffffff801153d660
      [   36.912769] Unable to handle kernel paging request at virtual address ffffff800004b564
      ...
      [   36.950666] Call trace:
      [   36.950670]  queued_spin_lock_slowpath+0x1cc/0x2c8
      [   36.950681]  _raw_spin_lock_irqsave+0x64/0x78
      [   36.950692]  complete+0x28/0x70
      [   36.950703]  ffs_epfile_io_complete+0x3c/0x50
      [   36.950713]  usb_gadget_giveback_request+0x34/0x108
      [   36.950721]  dwc3_gadget_giveback+0x50/0x68
      [   36.950723]  dwc3_thread_interrupt+0x358/0x1488
      [   36.950731]  irq_thread_fn+0x30/0x88
      [   36.950734]  irq_thread+0x114/0x1b0
      [   36.950739]  kthread+0x104/0x130
      [   36.950747]  ret_from_fork+0x10/0x1c
      
      I isolated this down to in ffs_epfile_io():
      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/gadget/function/f_fs.c#n1065
      
      Where the completion done is setup on the stack:
        DECLARE_COMPLETION_ONSTACK(done);
      
      Then later we setup a request and queue it, and wait for it:
        if (unlikely(wait_for_completion_interruptible(&done))) {
          /*
          * To avoid race condition with ffs_epfile_io_complete,
          * dequeue the request first then check
          * status. usb_ep_dequeue API should guarantee no race
          * condition with req->complete callback.
          */
          usb_ep_dequeue(ep->ep, req);
          interrupted = ep->status < 0;
        }
      
      The problem is, that we end up being interrupted, dequeue the
      request, and exit.
      
      But then the irq triggers and we try calling complete() on the
      context pointer which points to now random stack space, which
      results in the panic.
      
      Alan Stern pointed out there is a bug here, in that the snippet
      above "assumes that usb_ep_dequeue() waits until the request has
      been completed." And that:
      
          wait_for_completion(&done);
      
      Is needed right after the usb_ep_dequeue().
      
      Thus this patch implements that change. With it I no longer see
      the crashes on suspend or reboot.
      
      This issue seems to have been uncovered by behavioral changes in
      the dwc3 driver in commit fec9095b ("usb: dwc3: gadget:
      remove wait_end_transfer").
      
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: Zeng Tao <prime.zeng@hisilicon.com>
      Cc: Jack Pham <jackp@codeaurora.org>
      Cc: Thinh Nguyen <thinh.nguyen@synopsys.com>
      Cc: Chen Yu <chenyu56@huawei.com>
      Cc: Jerry Zhang <zhangjerry@google.com>
      Cc: Lars-Peter Clausen <lars@metafoo.de>
      Cc: Vincent Pelletier <plr.vincent@gmail.com>
      Cc: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Linux USB List <linux-usb@vger.kernel.org>
      Suggested-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NJohn Stultz <john.stultz@linaro.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      54f64d5c
  15. 07 2月, 2019 1 次提交
  16. 26 11月, 2018 2 次提交
  17. 14 11月, 2018 1 次提交
  18. 26 7月, 2018 1 次提交
    • J
      usb: gadget: f_fs: Only return delayed status when len is 0 · e610257e
      Jerry Zhang 提交于
      Commit 1b9ba000 ("Allow function drivers to pause control
      transfers") states that USB_GADGET_DELAYED_STATUS is only
      supported if data phase is 0 bytes.
      
      It seems that when the length is not 0 bytes, there is no
      need to explicitly delay the data stage since the transfer
      is not completed until the user responds. However, when the
      length is 0, there is no data stage and the transfer is
      finished once setup() returns, hence there is a need to
      explicitly delay completion.
      
      This manifests as the following bugs:
      
      Prior to 946ef68a ('Let setup() return
      USB_GADGET_DELAYED_STATUS'), when setup is 0 bytes, ffs
      would require user to queue a 0 byte request in order to
      clear setup state. However, that 0 byte request was actually
      not needed and would hang and cause errors in other setup
      requests.
      
      After the above commit, 0 byte setups work since the gadget
      now accepts empty queues to ep0 to clear the delay, but all
      other setups hang.
      
      Fixes: 946ef68a ("Let setup() return USB_GADGET_DELAYED_STATUS")
      Signed-off-by: NJerry Zhang <zhangjerry@google.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      e610257e
  19. 20 7月, 2018 1 次提交
    • J
      usb: gadget: f_fs: Only return delayed status when len is 0 · 4d644abf
      Jerry Zhang 提交于
      Commit 1b9ba000 ("Allow function drivers to pause control
      transfers") states that USB_GADGET_DELAYED_STATUS is only
      supported if data phase is 0 bytes.
      
      It seems that when the length is not 0 bytes, there is no
      need to explicitly delay the data stage since the transfer
      is not completed until the user responds. However, when the
      length is 0, there is no data stage and the transfer is
      finished once setup() returns, hence there is a need to
      explicitly delay completion.
      
      This manifests as the following bugs:
      
      Prior to 946ef68a ('Let setup() return
      USB_GADGET_DELAYED_STATUS'), when setup is 0 bytes, ffs
      would require user to queue a 0 byte request in order to
      clear setup state. However, that 0 byte request was actually
      not needed and would hang and cause errors in other setup
      requests.
      
      After the above commit, 0 byte setups work since the gadget
      now accepts empty queues to ep0 to clear the delay, but all
      other setups hang.
      
      Fixes: 946ef68a ("Let setup() return USB_GADGET_DELAYED_STATUS")
      Signed-off-by: NJerry Zhang <zhangjerry@google.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4d644abf
  20. 18 6月, 2018 1 次提交
    • V
      usb: gadget: ffs: Fix BUG when userland exits with submitted AIO transfers · d52e4d0c
      Vincent Pelletier 提交于
      This bug happens only when the UDC needs to sleep during usb_ep_dequeue,
      as is the case for (at least) dwc3.
      
      [  382.200896] BUG: scheduling while atomic: screen/1808/0x00000100
      [  382.207124] 4 locks held by screen/1808:
      [  382.211266]  #0:  (rcu_callback){....}, at: [<c10b4ff0>] rcu_process_callbacks+0x260/0x440
      [  382.219949]  #1:  (rcu_read_lock_sched){....}, at: [<c1358ba0>] percpu_ref_switch_to_atomic_rcu+0xb0/0x130
      [  382.230034]  #2:  (&(&ctx->ctx_lock)->rlock){....}, at: [<c11f0c73>] free_ioctx_users+0x23/0xd0
      [  382.230096]  #3:  (&(&ffs->eps_lock)->rlock){....}, at: [<f81e7710>] ffs_aio_cancel+0x20/0x60 [usb_f_fs]
      [  382.230160] Modules linked in: usb_f_fs libcomposite configfs bnep btsdio bluetooth ecdh_generic brcmfmac brcmutil intel_powerclamp coretemp dwc3 kvm_intel ulpi udc_core kvm irqbypass crc32_pclmul crc32c_intel pcbc dwc3_pci aesni_intel aes_i586 crypto_simd cryptd ehci_pci ehci_hcd gpio_keys usbcore basincove_gpadc industrialio usb_common
      [  382.230407] CPU: 1 PID: 1808 Comm: screen Not tainted 4.14.0-edison+ #117
      [  382.230416] Hardware name: Intel Corporation Merrifield/BODEGA BAY, BIOS 542 2015.01.21:18.19.48
      [  382.230425] Call Trace:
      [  382.230438]  <SOFTIRQ>
      [  382.230466]  dump_stack+0x47/0x62
      [  382.230498]  __schedule_bug+0x61/0x80
      [  382.230522]  __schedule+0x43/0x7a0
      [  382.230587]  schedule+0x5f/0x70
      [  382.230625]  dwc3_gadget_ep_dequeue+0x14c/0x270 [dwc3]
      [  382.230669]  ? do_wait_intr_irq+0x70/0x70
      [  382.230724]  usb_ep_dequeue+0x19/0x90 [udc_core]
      [  382.230770]  ffs_aio_cancel+0x37/0x60 [usb_f_fs]
      [  382.230798]  kiocb_cancel+0x31/0x40
      [  382.230822]  free_ioctx_users+0x4d/0xd0
      [  382.230858]  percpu_ref_switch_to_atomic_rcu+0x10a/0x130
      [  382.230881]  ? percpu_ref_exit+0x40/0x40
      [  382.230904]  rcu_process_callbacks+0x2b3/0x440
      [  382.230965]  __do_softirq+0xf8/0x26b
      [  382.231011]  ? __softirqentry_text_start+0x8/0x8
      [  382.231033]  do_softirq_own_stack+0x22/0x30
      [  382.231042]  </SOFTIRQ>
      [  382.231071]  irq_exit+0x45/0xc0
      [  382.231089]  smp_apic_timer_interrupt+0x13c/0x150
      [  382.231118]  apic_timer_interrupt+0x35/0x3c
      [  382.231132] EIP: __copy_user_ll+0xe2/0xf0
      [  382.231142] EFLAGS: 00210293 CPU: 1
      [  382.231154] EAX: bfd4508c EBX: 00000004 ECX: 00000003 EDX: f3d8fe50
      [  382.231165] ESI: f3d8fe51 EDI: bfd4508d EBP: f3d8fe14 ESP: f3d8fe08
      [  382.231176]  DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
      [  382.231265]  core_sys_select+0x25f/0x320
      [  382.231346]  ? __wake_up_common_lock+0x62/0x80
      [  382.231399]  ? tty_ldisc_deref+0x13/0x20
      [  382.231438]  ? ldsem_up_read+0x1b/0x40
      [  382.231459]  ? tty_ldisc_deref+0x13/0x20
      [  382.231479]  ? tty_write+0x29f/0x2e0
      [  382.231514]  ? n_tty_ioctl+0xe0/0xe0
      [  382.231541]  ? tty_write_unlock+0x30/0x30
      [  382.231566]  ? __vfs_write+0x22/0x110
      [  382.231604]  ? security_file_permission+0x2f/0xd0
      [  382.231635]  ? rw_verify_area+0xac/0x120
      [  382.231677]  ? vfs_write+0x103/0x180
      [  382.231711]  SyS_select+0x87/0xc0
      [  382.231739]  ? SyS_write+0x42/0x90
      [  382.231781]  do_fast_syscall_32+0xd6/0x1a0
      [  382.231836]  entry_SYSENTER_32+0x47/0x71
      [  382.231848] EIP: 0xb7f75b05
      [  382.231857] EFLAGS: 00000246 CPU: 1
      [  382.231868] EAX: ffffffda EBX: 00000400 ECX: bfd4508c EDX: bfd4510c
      [  382.231878] ESI: 00000000 EDI: 00000000 EBP: 00000000 ESP: bfd45020
      [  382.231889]  DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 007b
      [  382.232281] softirq: huh, entered softirq 9 RCU c10b4d90 with preempt_count 00000100, exited with 00000000?
      Tested-by: NSam Protsenko <semen.protsenko@linaro.org>
      Signed-off-by: NVincent Pelletier <plr.vincent@gmail.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      d52e4d0c
  21. 06 6月, 2018 1 次提交
    • D
      vfs: change inode times to use struct timespec64 · 95582b00
      Deepa Dinamani 提交于
      struct timespec is not y2038 safe. Transition vfs to use
      y2038 safe struct timespec64 instead.
      
      The change was made with the help of the following cocinelle
      script. This catches about 80% of the changes.
      All the header file and logic changes are included in the
      first 5 rules. The rest are trivial substitutions.
      I avoid changing any of the function signatures or any other
      filesystem specific data structures to keep the patch simple
      for review.
      
      The script can be a little shorter by combining different cases.
      But, this version was sufficient for my usecase.
      
      virtual patch
      
      @ depends on patch @
      identifier now;
      @@
      - struct timespec
      + struct timespec64
        current_time ( ... )
        {
      - struct timespec now = current_kernel_time();
      + struct timespec64 now = current_kernel_time64();
        ...
      - return timespec_trunc(
      + return timespec64_trunc(
        ... );
        }
      
      @ depends on patch @
      identifier xtime;
      @@
       struct \( iattr \| inode \| kstat \) {
       ...
      -       struct timespec xtime;
      +       struct timespec64 xtime;
       ...
       }
      
      @ depends on patch @
      identifier t;
      @@
       struct inode_operations {
       ...
      int (*update_time) (...,
      -       struct timespec t,
      +       struct timespec64 t,
      ...);
       ...
       }
      
      @ depends on patch @
      identifier t;
      identifier fn_update_time =~ "update_time$";
      @@
       fn_update_time (...,
      - struct timespec *t,
      + struct timespec64 *t,
       ...) { ... }
      
      @ depends on patch @
      identifier t;
      @@
      lease_get_mtime( ... ,
      - struct timespec *t
      + struct timespec64 *t
        ) { ... }
      
      @te depends on patch forall@
      identifier ts;
      local idexpression struct inode *inode_node;
      identifier i_xtime =~ "^i_[acm]time$";
      identifier ia_xtime =~ "^ia_[acm]time$";
      identifier fn_update_time =~ "update_time$";
      identifier fn;
      expression e, E3;
      local idexpression struct inode *node1;
      local idexpression struct inode *node2;
      local idexpression struct iattr *attr1;
      local idexpression struct iattr *attr2;
      local idexpression struct iattr attr;
      identifier i_xtime1 =~ "^i_[acm]time$";
      identifier i_xtime2 =~ "^i_[acm]time$";
      identifier ia_xtime1 =~ "^ia_[acm]time$";
      identifier ia_xtime2 =~ "^ia_[acm]time$";
      @@
      (
      (
      - struct timespec ts;
      + struct timespec64 ts;
      |
      - struct timespec ts = current_time(inode_node);
      + struct timespec64 ts = current_time(inode_node);
      )
      
      <+... when != ts
      (
      - timespec_equal(&inode_node->i_xtime, &ts)
      + timespec64_equal(&inode_node->i_xtime, &ts)
      |
      - timespec_equal(&ts, &inode_node->i_xtime)
      + timespec64_equal(&ts, &inode_node->i_xtime)
      |
      - timespec_compare(&inode_node->i_xtime, &ts)
      + timespec64_compare(&inode_node->i_xtime, &ts)
      |
      - timespec_compare(&ts, &inode_node->i_xtime)
      + timespec64_compare(&ts, &inode_node->i_xtime)
      |
      ts = current_time(e)
      |
      fn_update_time(..., &ts,...)
      |
      inode_node->i_xtime = ts
      |
      node1->i_xtime = ts
      |
      ts = inode_node->i_xtime
      |
      <+... attr1->ia_xtime ...+> = ts
      |
      ts = attr1->ia_xtime
      |
      ts.tv_sec
      |
      ts.tv_nsec
      |
      btrfs_set_stack_timespec_sec(..., ts.tv_sec)
      |
      btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
      |
      - ts = timespec64_to_timespec(
      + ts =
      ...
      -)
      |
      - ts = ktime_to_timespec(
      + ts = ktime_to_timespec64(
      ...)
      |
      - ts = E3
      + ts = timespec_to_timespec64(E3)
      |
      - ktime_get_real_ts(&ts)
      + ktime_get_real_ts64(&ts)
      |
      fn(...,
      - ts
      + timespec64_to_timespec(ts)
      ,...)
      )
      ...+>
      (
      <... when != ts
      - return ts;
      + return timespec64_to_timespec(ts);
      ...>
      )
      |
      - timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
      + timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
      |
      - timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
      + timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
      |
      - timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
      + timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
      |
      node1->i_xtime1 =
      - timespec_trunc(attr1->ia_xtime1,
      + timespec64_trunc(attr1->ia_xtime1,
      ...)
      |
      - attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
      + attr1->ia_xtime1 =  timespec64_trunc(attr2->ia_xtime2,
      ...)
      |
      - ktime_get_real_ts(&attr1->ia_xtime1)
      + ktime_get_real_ts64(&attr1->ia_xtime1)
      |
      - ktime_get_real_ts(&attr.ia_xtime1)
      + ktime_get_real_ts64(&attr.ia_xtime1)
      )
      
      @ depends on patch @
      struct inode *node;
      struct iattr *attr;
      identifier fn;
      identifier i_xtime =~ "^i_[acm]time$";
      identifier ia_xtime =~ "^ia_[acm]time$";
      expression e;
      @@
      (
      - fn(node->i_xtime);
      + fn(timespec64_to_timespec(node->i_xtime));
      |
       fn(...,
      - node->i_xtime);
      + timespec64_to_timespec(node->i_xtime));
      |
      - e = fn(attr->ia_xtime);
      + e = fn(timespec64_to_timespec(attr->ia_xtime));
      )
      
      @ depends on patch forall @
      struct inode *node;
      struct iattr *attr;
      identifier i_xtime =~ "^i_[acm]time$";
      identifier ia_xtime =~ "^ia_[acm]time$";
      identifier fn;
      @@
      {
      + struct timespec ts;
      <+...
      (
      + ts = timespec64_to_timespec(node->i_xtime);
      fn (...,
      - &node->i_xtime,
      + &ts,
      ...);
      |
      + ts = timespec64_to_timespec(attr->ia_xtime);
      fn (...,
      - &attr->ia_xtime,
      + &ts,
      ...);
      )
      ...+>
      }
      
      @ depends on patch forall @
      struct inode *node;
      struct iattr *attr;
      struct kstat *stat;
      identifier ia_xtime =~ "^ia_[acm]time$";
      identifier i_xtime =~ "^i_[acm]time$";
      identifier xtime =~ "^[acm]time$";
      identifier fn, ret;
      @@
      {
      + struct timespec ts;
      <+...
      (
      + ts = timespec64_to_timespec(node->i_xtime);
      ret = fn (...,
      - &node->i_xtime,
      + &ts,
      ...);
      |
      + ts = timespec64_to_timespec(node->i_xtime);
      ret = fn (...,
      - &node->i_xtime);
      + &ts);
      |
      + ts = timespec64_to_timespec(attr->ia_xtime);
      ret = fn (...,
      - &attr->ia_xtime,
      + &ts,
      ...);
      |
      + ts = timespec64_to_timespec(attr->ia_xtime);
      ret = fn (...,
      - &attr->ia_xtime);
      + &ts);
      |
      + ts = timespec64_to_timespec(stat->xtime);
      ret = fn (...,
      - &stat->xtime);
      + &ts);
      )
      ...+>
      }
      
      @ depends on patch @
      struct inode *node;
      struct inode *node2;
      identifier i_xtime1 =~ "^i_[acm]time$";
      identifier i_xtime2 =~ "^i_[acm]time$";
      identifier i_xtime3 =~ "^i_[acm]time$";
      struct iattr *attrp;
      struct iattr *attrp2;
      struct iattr attr ;
      identifier ia_xtime1 =~ "^ia_[acm]time$";
      identifier ia_xtime2 =~ "^ia_[acm]time$";
      struct kstat *stat;
      struct kstat stat1;
      struct timespec64 ts;
      identifier xtime =~ "^[acmb]time$";
      expression e;
      @@
      (
      ( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1  ;
      |
       node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
      |
       node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
      |
       node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
      |
       stat->xtime = node2->i_xtime1;
      |
       stat1.xtime = node2->i_xtime1;
      |
      ( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1  ;
      |
      ( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
      |
      - e = node->i_xtime1;
      + e = timespec64_to_timespec( node->i_xtime1 );
      |
      - e = attrp->ia_xtime1;
      + e = timespec64_to_timespec( attrp->ia_xtime1 );
      |
      node->i_xtime1 = current_time(...);
      |
       node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
      - e;
      + timespec_to_timespec64(e);
      |
       node->i_xtime1 = node->i_xtime3 =
      - e;
      + timespec_to_timespec64(e);
      |
      - node->i_xtime1 = e;
      + node->i_xtime1 = timespec_to_timespec64(e);
      )
      Signed-off-by: NDeepa Dinamani <deepa.kernel@gmail.com>
      Cc: <anton@tuxera.com>
      Cc: <balbi@kernel.org>
      Cc: <bfields@fieldses.org>
      Cc: <darrick.wong@oracle.com>
      Cc: <dhowells@redhat.com>
      Cc: <dsterba@suse.com>
      Cc: <dwmw2@infradead.org>
      Cc: <hch@lst.de>
      Cc: <hirofumi@mail.parknet.co.jp>
      Cc: <hubcap@omnibond.com>
      Cc: <jack@suse.com>
      Cc: <jaegeuk@kernel.org>
      Cc: <jaharkes@cs.cmu.edu>
      Cc: <jslaby@suse.com>
      Cc: <keescook@chromium.org>
      Cc: <mark@fasheh.com>
      Cc: <miklos@szeredi.hu>
      Cc: <nico@linaro.org>
      Cc: <reiserfs-devel@vger.kernel.org>
      Cc: <richard@nod.at>
      Cc: <sage@redhat.com>
      Cc: <sfrench@samba.org>
      Cc: <swhiteho@redhat.com>
      Cc: <tj@kernel.org>
      Cc: <trond.myklebust@primarydata.com>
      Cc: <tytso@mit.edu>
      Cc: <viro@zeniv.linux.org.uk>
      95582b00
  22. 15 5月, 2018 1 次提交
  23. 13 3月, 2018 2 次提交
    • L
      usb: gadget: ffs: Let setup() return USB_GADGET_DELAYED_STATUS · 946ef68a
      Lars-Peter Clausen 提交于
      Some UDC drivers (like the DWC3) expect that the response to a setup()
      request is queued from within the setup function itself so that it is
      available as soon as setup() has completed.
      
      Upon receiving a setup request the function fs driver creates an event that
      is made available to userspace. And only once userspace has acknowledged
      that event the response to the setup request is queued.
      
      So it violates the requirement of those UDC drivers and random failures can
      be observed. This is basically a race condition and if userspace is able to
      read the event and queue the response fast enough all is good. But if it is
      not, for example because other processes are currently scheduled to run,
      the USB host that sent the setup request will observe an error.
      
      To avoid this the gadget framework provides the USB_GADGET_DELAYED_STATUS
      return code. If a setup() callback returns this value the UDC driver is
      aware that response is not yet available and can uses the appropriate
      methods to handle this case.
      
      Since in the case of function fs the response will never be available when
      the setup() function returns make sure that this status code is used.
      
      This fixed random occasional failures that were previously observed on a
      DWC3 based system under high system load.
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      946ef68a
    • L
      usb: gadget: ffs: Execute copy_to_user() with USER_DS set · 4058ebf3
      Lars-Peter Clausen 提交于
      When using a AIO read() operation on the function FS gadget driver a URB is
      submitted asynchronously and on URB completion the received data is copied
      to the userspace buffer associated with the read operation.
      
      This is done from a kernel worker thread invoking copy_to_user() (through
      copy_to_iter()). And while the user space process memory is made available
      to the kernel thread using use_mm(), some architecture require in addition
      to this that the operation runs with USER_DS set. Otherwise the userspace
      memory access will fail.
      
      For example on ARM64 with Privileged Access Never (PAN) and User Access
      Override (UAO) enabled the following crash occurs.
      
      	Internal error: Accessing user space memory with fs=KERNEL_DS: 9600004f [#1] SMP
      	Modules linked in:
      	CPU: 2 PID: 1636 Comm: kworker/2:1 Not tainted 4.9.0-04081-g8ab2dfb-dirty #487
      	Hardware name: ZynqMP ZCU102 Rev1.0 (DT)
      	Workqueue: events ffs_user_copy_worker
      	task: ffffffc87afc8080 task.stack: ffffffc87a00c000
      	PC is at __arch_copy_to_user+0x190/0x220
      	LR is at copy_to_iter+0x78/0x3c8
      	[...]
      	[<ffffff800847b790>] __arch_copy_to_user+0x190/0x220
      	[<ffffff80086f25d8>] ffs_user_copy_worker+0x70/0x130
      	[<ffffff80080b8c64>] process_one_work+0x1dc/0x460
      	[<ffffff80080b8f38>] worker_thread+0x50/0x4b0
      	[<ffffff80080bf5a0>] kthread+0xd8/0xf0
      	[<ffffff8008083680>] ret_from_fork+0x10/0x50
      
      Address this by placing a set_fs(USER_DS) before of the copy operation
      and revert it again once the copy operation has finished.
      
      This patch is analogous to commit d7ffde35 ("vhost: use USER_DS in
      vhost_worker thread") which addresses the same underlying issue.
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      4058ebf3
  24. 05 3月, 2018 1 次提交
    • X
      usb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb() · 1a087f03
      Xinyong 提交于
      When I debug a kernel crash issue in funcitonfs, found ffs_data.ref
      overflowed, While functionfs is unmounting, ffs_data is put twice.
      
      Commit 43938613 ("drivers, usb: convert ffs_data.ref from atomic_t to
      refcount_t") can avoid refcount overflow, but that is risk some situations.
      So no need put ffs data in ffs_fs_kill_sb, already put in ffs_data_closed.
      
      The issue can be reproduced in Mediatek mt6763 SoC, ffs for ADB device.
      KASAN enabled configuration reports use-after-free errro.
      
      BUG: KASAN: use-after-free in refcount_dec_and_test+0x14/0xe0 at addr ffffffc0579386a0
      Read of size 4 by task umount/4650
      ====================================================
      BUG kmalloc-512 (Tainted: P        W  O   ): kasan: bad access detected
      -----------------------------------------------------------------------------
      
      INFO: Allocated in ffs_fs_mount+0x194/0x844 age=22856 cpu=2 pid=566
          alloc_debug_processing+0x1ac/0x1e8
          ___slab_alloc.constprop.63+0x640/0x648
          __slab_alloc.isra.57.constprop.62+0x24/0x34
          kmem_cache_alloc_trace+0x1a8/0x2bc
          ffs_fs_mount+0x194/0x844
          mount_fs+0x6c/0x1d0
          vfs_kern_mount+0x50/0x1b4
          do_mount+0x258/0x1034
      INFO: Freed in ffs_data_put+0x25c/0x320 age=0 cpu=3 pid=4650
          free_debug_processing+0x22c/0x434
          __slab_free+0x2d8/0x3a0
          kfree+0x254/0x264
          ffs_data_put+0x25c/0x320
          ffs_data_closed+0x124/0x15c
          ffs_fs_kill_sb+0xb8/0x110
          deactivate_locked_super+0x6c/0x98
          deactivate_super+0xb0/0xbc
      INFO: Object 0xffffffc057938600 @offset=1536 fp=0x          (null)
      ......
      Call trace:
      [<ffffff900808cf5c>] dump_backtrace+0x0/0x250
      [<ffffff900808d3a0>] show_stack+0x14/0x1c
      [<ffffff90084a8c04>] dump_stack+0xa0/0xc8
      [<ffffff900826c2b4>] print_trailer+0x158/0x260
      [<ffffff900826d9d8>] object_err+0x3c/0x40
      [<ffffff90082745f0>] kasan_report_error+0x2a8/0x754
      [<ffffff9008274f84>] kasan_report+0x5c/0x60
      [<ffffff9008273208>] __asan_load4+0x70/0x88
      [<ffffff90084cd81c>] refcount_dec_and_test+0x14/0xe0
      [<ffffff9008d98f9c>] ffs_data_put+0x80/0x320
      [<ffffff9008d9d904>] ffs_fs_kill_sb+0xc8/0x110
      [<ffffff90082852a0>] deactivate_locked_super+0x6c/0x98
      [<ffffff900828537c>] deactivate_super+0xb0/0xbc
      [<ffffff90082af0c0>] cleanup_mnt+0x64/0xec
      [<ffffff90082af1b0>] __cleanup_mnt+0x10/0x18
      [<ffffff90080d9e68>] task_work_run+0xcc/0x124
      [<ffffff900808c8c0>] do_notify_resume+0x60/0x70
      [<ffffff90080866e4>] work_pending+0x10/0x14
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NXinyong <xinyong.fang@linux.alibaba.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      1a087f03
  25. 12 2月, 2018 3 次提交
    • J
      usb: gadget: f_fs: Use config_ep_by_speed() · 675272d0
      Jack Pham 提交于
      In commit 2bfa0719 ("usb: gadget: function: f_fs: pass
      companion descriptor along") there is a pointer arithmetic
      bug where the comp_desc is obtained as follows:
      
       comp_desc = (struct usb_ss_ep_comp_descriptor *)(ds +
      	       USB_DT_ENDPOINT_SIZE);
      
      Since ds is a pointer to usb_endpoint_descriptor, adding
      7 to it ends up going out of bounds (7 * sizeof(struct
      usb_endpoint_descriptor), which is actually 7*9 bytes) past
      the SS descriptor. As a result the maxburst value will be
      read incorrectly, and the UDC driver will also get a garbage
      comp_desc (assuming it uses it).
      
      Since Felipe wrote, "Eventually, f_fs.c should be converted
      to use config_ep_by_speed() like all other functions, though",
      let's finally do it. This allows the other usb_ep fields to
      be properly populated, such as maxpacket and mult. It also
      eliminates the awkward speed-based descriptor lookup since
      config_ep_by_speed() does that already using the ones found
      in struct usb_function.
      
      Fixes: 2bfa0719 ("usb: gadget: function: f_fs: pass companion descriptor along")
      Cc: stable@vger.kernel.org
      Signed-off-by: NJack Pham <jackp@codeaurora.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      675272d0
    • J
      usb: gadget: f_fs: Process all descriptors during bind · 6cf439e0
      Jack Pham 提交于
      During _ffs_func_bind(), the received descriptors are evaluated
      to prepare for binding with the gadget in order to allocate
      endpoints and optionally set up OS descriptors. However, the
      high- and super-speed descriptors are only parsed based on
      whether the gadget_is_dualspeed() and gadget_is_superspeed()
      calls are true, respectively.
      
      This is a problem in case a userspace program always provides
      all of the {full,high,super,OS} descriptors when configuring a
      function. Then, for example if a gadget device is not capable
      of SuperSpeed, the call to ffs_do_descs() for the SS descriptors
      is skipped, resulting in an incorrect offset calculation for
      the vla_ptr when moving on to the OS descriptors that follow.
      This causes ffs_do_os_descs() to fail as it is now looking at
      the SS descriptors' offset within the raw_descs buffer instead.
      
      _ffs_func_bind() should evaluate the descriptors unconditionally,
      so remove the checks for gadget speed.
      
      Fixes: f0175ab5 ("usb: gadget: f_fs: OS descriptors support")
      Cc: stable@vger.kernel.org
      Co-Developed-by: NMayank Rana <mrana@codeaurora.org>
      Signed-off-by: NMayank Rana <mrana@codeaurora.org>
      Signed-off-by: NJack Pham <jackp@codeaurora.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      6cf439e0
    • L
      vfs: do bulk POLL* -> EPOLL* replacement · a9a08845
      Linus Torvalds 提交于
      This is the mindless scripted replacement of kernel use of POLL*
      variables as described by Al, done by this script:
      
          for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
              L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
              for f in $L; do sed -i "-es/^\([^\"]*\)\(\<POLL$V\>\)/\\1E\\2/" $f; done
          done
      
      with de-mangling cleanups yet to come.
      
      NOTE! On almost all architectures, the EPOLL* constants have the same
      values as the POLL* constants do.  But they keyword here is "almost".
      For various bad reasons they aren't the same, and epoll() doesn't
      actually work quite correctly in some cases due to this on Sparc et al.
      
      The next patch from Al will sort out the final differences, and we
      should be all done.
      Scripted-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a9a08845
  26. 09 1月, 2018 1 次提交
    • H
      usb: f_fs: Prevent gadget unbind if it is already unbound · ce5bf9a5
      Hemant Kumar 提交于
      Upon usb composition switch there is possibility of ep0 file
      release happening after gadget driver bind. In case of composition
      switch from adb to a non-adb composition gadget will never gets
      bound again resulting into failure of usb device enumeration. Fix
      this issue by checking FFS_FL_BOUND flag and avoid extra
      gadget driver unbind if it is already done as part of composition
      switch.
      
      This fixes adb reconnection error reported on Android running
      v4.4 and above kernel versions. Verified on Hikey running vanilla
      v4.15-rc7 + few out of tree Mali patches.
      
      Reviewed-at: https://android-review.googlesource.com/#/c/582632/
      
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: Greg KH <gregkh@linux-foundation.org>
      Cc: Michal Nazarewicz <mina86@mina86.com>
      Cc: John Stultz <john.stultz@linaro.org>
      Cc: Dmitry Shmidt <dimitrysh@google.com>
      Cc: Badhri <badhri@google.com>
      Cc: Android Kernel Team <kernel-team@android.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NHemant Kumar <hemantk@codeaurora.org>
      [AmitP: Cherry-picked it from android-4.14 and updated the commit log]
      Signed-off-by: NAmit Pundir <amit.pundir@linaro.org>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce5bf9a5
  27. 11 12月, 2017 1 次提交
    • V
      usb: gadget: ffs: Make sparse happier · c40619bb
      Vincent Pelletier 提交于
      Silences the following warnings:
      drivers/usb/gadget/function/f_fs.c:1253:37: warning: incorrect type in argument 1 (different address spaces)
      drivers/usb/gadget/function/f_fs.c:1253:37:    expected void [noderef] <asn:1>*to
      drivers/usb/gadget/function/f_fs.c:1253:37:    got void *<noident>
      drivers/usb/gadget/function/f_fs.c:2322:23: warning: cast to restricted __le32
      drivers/usb/gadget/function/f_fs.c:2876:38: warning: cast to restricted __le32
      drivers/usb/gadget/function/f_fs.c:272:12: warning: context imbalance in '__ffs_ep0_queue_wait' - unexpected unlock
      drivers/usb/gadget/function/f_fs.c:450:17: warning: context imbalance in 'ffs_ep0_write' - different lock contexts for basic block
      drivers/usb/gadget/function/f_fs.c:490:24: warning: context imbalance in '__ffs_ep0_read_events' - unexpected unlock
      drivers/usb/gadget/function/f_fs.c:496:16: warning: context imbalance in 'ffs_ep0_read' - different lock contexts for basic block
      
      Also, add an "unlocks spinlock" comment for consistency with existing ones.
      No behaviour change is intended.
      Signed-off-by: NVincent Pelletier <plr.vincent@gmail.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      c40619bb
  28. 29 11月, 2017 1 次提交
  29. 28 11月, 2017 1 次提交
    • J
      usb: f_fs: Force Reserved1=1 in OS_DESC_EXT_COMPAT · a3acc696
      John Keeping 提交于
      The specification says that the Reserved1 field in OS_DESC_EXT_COMPAT
      must have the value "1", but when this feature was first implemented we
      rejected any non-zero values.
      
      This was adjusted to accept all non-zero values (while now rejecting
      zero) in commit 53642399 ("usb: gadget: f_fs: Fix wrong check on
      reserved1 of OS_DESC_EXT_COMPAT"), but that breaks any userspace
      programs that worked previously by returning EINVAL when Reserved1 == 0
      which was previously the only value that succeeded!
      
      If we just set the field to "1" ourselves, both old and new userspace
      programs continue to work correctly and, as a bonus, old programs are
      now compliant with the specification without having to fix anything
      themselves.
      
      Fixes: 53642399 ("usb: gadget: f_fs: Fix wrong check on reserved1 of OS_DESC_EXT_COMPAT")
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NJohn Keeping <john@metanate.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      a3acc696
  30. 27 11月, 2017 1 次提交
    • V
      usb: gadget: ffs: Forbid usb_ep_alloc_request from sleeping · 30bf90cc
      Vincent Pelletier 提交于
      Found using DEBUG_ATOMIC_SLEEP while submitting an AIO read operation:
      
      [  100.853642] BUG: sleeping function called from invalid context at mm/slab.h:421
      [  100.861148] in_atomic(): 1, irqs_disabled(): 1, pid: 1880, name: python
      [  100.867954] 2 locks held by python/1880:
      [  100.867961]  #0:  (&epfile->mutex){....}, at: [<f8188627>] ffs_mutex_lock+0x27/0x30 [usb_f_fs]
      [  100.868020]  #1:  (&(&ffs->eps_lock)->rlock){....}, at: [<f818ad4b>] ffs_epfile_io.isra.17+0x24b/0x590 [usb_f_fs]
      [  100.868076] CPU: 1 PID: 1880 Comm: python Not tainted 4.14.0-edison+ #118
      [  100.868085] Hardware name: Intel Corporation Merrifield/BODEGA BAY, BIOS 542 2015.01.21:18.19.48
      [  100.868093] Call Trace:
      [  100.868122]  dump_stack+0x47/0x62
      [  100.868156]  ___might_sleep+0xfd/0x110
      [  100.868182]  __might_sleep+0x68/0x70
      [  100.868217]  kmem_cache_alloc_trace+0x4b/0x200
      [  100.868248]  ? dwc3_gadget_ep_alloc_request+0x24/0xe0 [dwc3]
      [  100.868302]  dwc3_gadget_ep_alloc_request+0x24/0xe0 [dwc3]
      [  100.868343]  usb_ep_alloc_request+0x16/0xc0 [udc_core]
      [  100.868386]  ffs_epfile_io.isra.17+0x444/0x590 [usb_f_fs]
      [  100.868424]  ? _raw_spin_unlock_irqrestore+0x27/0x40
      [  100.868457]  ? kiocb_set_cancel_fn+0x57/0x60
      [  100.868477]  ? ffs_ep0_poll+0xc0/0xc0 [usb_f_fs]
      [  100.868512]  ffs_epfile_read_iter+0xfe/0x157 [usb_f_fs]
      [  100.868551]  ? security_file_permission+0x9c/0xd0
      [  100.868587]  ? rw_verify_area+0xac/0x120
      [  100.868633]  aio_read+0x9d/0x100
      [  100.868692]  ? __fget+0xa2/0xd0
      [  100.868727]  ? __might_sleep+0x68/0x70
      [  100.868763]  SyS_io_submit+0x471/0x680
      [  100.868878]  do_int80_syscall_32+0x4e/0xd0
      [  100.868921]  entry_INT80_32+0x2a/0x2a
      [  100.868932] EIP: 0xb7fbb676
      [  100.868941] EFLAGS: 00000292 CPU: 1
      [  100.868951] EAX: ffffffda EBX: b7aa2000 ECX: 00000002 EDX: b7af8368
      [  100.868961] ESI: b7fbb660 EDI: b7aab000 EBP: bfb6c658 ESP: bfb6c638
      [  100.868973]  DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 007b
      Signed-off-by: NVincent Pelletier <plr.vincent@gmail.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      30bf90cc
  31. 09 11月, 2017 1 次提交
    • A
      usb: gadget: f_fs: Fix use-after-free in ffs_free_inst · cdafb6d8
      Andrew Gabbasov 提交于
      KASAN enabled configuration reports an error
      
      BUG: KASAN: use-after-free in ffs_free_inst+... [usb_f_fs] at addr ...
      Write of size 8 by task ...
      
      This is observed after "ffs-test" is run and interrupted. If after that
      functionfs is unmounted and g_ffs module is unloaded, that use-after-free
      occurs during g_ffs module removal.
      
      Although the report indicates ffs_free_inst() function, the actual
      use-after-free condition occurs in _ffs_free_dev() function, which
      is probably inlined into ffs_free_inst().
      
      This happens due to keeping the ffs_data reference in device structure
      during functionfs unmounting, while ffs_data itself is freed as no longer
      needed. The fix is to clear that reference in ffs_closed() function,
      which is a counterpart of ffs_ready(), where the reference is stored.
      
      Fixes: 3262ad82 ("usb: gadget: f_fs: Stop ffs_closed NULL pointer dereference")
      Cc: stable@vger.kernel.org
      Signed-off-by: NAndrew Gabbasov <andrew_gabbasov@mentor.com>
      Acked-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cdafb6d8
  32. 07 11月, 2017 1 次提交
  33. 04 11月, 2017 1 次提交
  34. 19 10月, 2017 1 次提交