Skip to content
Snippets Groups Projects
  1. Jan 07, 2022
  2. Jan 06, 2022
    • Chris Packham's avatar
      i2c: mpc: Avoid out of bounds memory access · 72a4a87d
      Chris Packham authored
      
      When performing an I2C transfer where the last message was a write KASAN
      would complain:
      
        BUG: KASAN: slab-out-of-bounds in mpc_i2c_do_action+0x154/0x630
        Read of size 2 at addr c814e310 by task swapper/2/0
      
        CPU: 2 PID: 0 Comm: swapper/2 Tainted: G    B             5.16.0-rc8 #1
        Call Trace:
        [e5ee9d50] [c08418e8] dump_stack_lvl+0x4c/0x6c (unreliable)
        [e5ee9d70] [c02f8a14] print_address_description.constprop.13+0x64/0x3b0
        [e5ee9da0] [c02f9030] kasan_report+0x1f0/0x204
        [e5ee9de0] [c0c76ee4] mpc_i2c_do_action+0x154/0x630
        [e5ee9e30] [c0c782c4] mpc_i2c_isr+0x164/0x240
        [e5ee9e60] [c00f3a04] __handle_irq_event_percpu+0xf4/0x3b0
        [e5ee9ec0] [c00f3d40] handle_irq_event_percpu+0x80/0x110
        [e5ee9f40] [c00f3e48] handle_irq_event+0x78/0xd0
        [e5ee9f60] [c00fcfec] handle_fasteoi_irq+0x19c/0x370
        [e5ee9fa0] [c00f1d84] generic_handle_irq+0x54/0x80
        [e5ee9fc0] [c0006b54] __do_irq+0x64/0x200
        [e5ee9ff0] [c0007958] __do_IRQ+0xe8/0x1c0
        [c812dd50] [e3eaab20] 0xe3eaab20
        [c812dd90] [c0007a4c] do_IRQ+0x1c/0x30
        [c812dda0] [c0000c04] ExternalInput+0x144/0x160
        --- interrupt: 500 at arch_cpu_idle+0x34/0x60
        NIP:  c000b684 LR: c000b684 CTR: c0019688
        REGS: c812ddb0 TRAP: 0500   Tainted: G    B              (5.16.0-rc8)
        MSR:  00029002 <CE,EE,ME>  CR: 22000488  XER: 20000000
      
        GPR00: c10ef7fc c812de90 c80ff200 c2394718 00000001 00000001 c10e3f90 00000003
        GPR08: 00000000 c0019688 c2394718 fc7d625b 22000484 00000000 21e17000 c208228c
        GPR16: e3e99284 00000000 ffffffff c2390000 c001bac0 c2082288 c812df60 c001ba60
        GPR24: c23949c0 00000018 00080000 00000004 c80ff200 00000002 c2348ee4 c2394718
        NIP [c000b684] arch_cpu_idle+0x34/0x60
        LR [c000b684] arch_cpu_idle+0x34/0x60
        --- interrupt: 500
        [c812de90] [c10e3f90] rcu_eqs_enter.isra.60+0xc0/0x110 (unreliable)
        [c812deb0] [c10ef7fc] default_idle_call+0xbc/0x230
        [c812dee0] [c00af0e8] do_idle+0x1c8/0x200
        [c812df10] [c00af3c0] cpu_startup_entry+0x20/0x30
        [c812df20] [c001e010] start_secondary+0x5d0/0xba0
        [c812dff0] [c00028a0] __secondary_start+0x90/0xdc
      
      This happened because we would overrun the i2c->msgs array on the final
      interrupt for the I2C STOP. This didn't happen if the last message was a
      read because there is no interrupt in that case. Ensure that we only
      access the current message if we are not processing a I2C STOP
      condition.
      
      Fixes: 1538d82f ("i2c: mpc: Interrupt driven transfer")
      Reported-by: default avatarMaxime Bizon <mbizon@freebox.fr>
      Signed-off-by: default avatarChris Packham <chris.packham@alliedtelesis.co.nz>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      72a4a87d
  3. Dec 31, 2021
  4. Dec 10, 2021
  5. Dec 09, 2021
    • Vincent Whitchurch's avatar
      i2c: virtio: fix completion handling · b503de23
      Vincent Whitchurch authored
      
      The driver currently assumes that the notify callback is only received
      when the device is done with all the queued buffers.
      
      However, this is not true, since the notify callback could be called
      without any of the queued buffers being completed (for example, with
      virtio-pci and shared interrupts) or with only some of the buffers being
      completed (since the driver makes them available to the device in
      multiple separate virtqueue_add_sgs() calls).
      
      This can lead to incorrect data on the I2C bus or memory corruption in
      the guest if the device operates on buffers which are have been freed by
      the driver.  (The WARN_ON in the driver is also triggered.)
      
       BUG kmalloc-128 (Tainted: G        W        ): Poison overwritten
       First byte 0x0 instead of 0x6b
       Allocated in i2cdev_ioctl_rdwr+0x9d/0x1de age=243 cpu=0 pid=28
       	memdup_user+0x2e/0xbd
       	i2cdev_ioctl_rdwr+0x9d/0x1de
       	i2cdev_ioctl+0x247/0x2ed
       	vfs_ioctl+0x21/0x30
       	sys_ioctl+0xb18/0xb41
       Freed in i2cdev_ioctl_rdwr+0x1bb/0x1de age=68 cpu=0 pid=28
       	kfree+0x1bd/0x1cc
       	i2cdev_ioctl_rdwr+0x1bb/0x1de
       	i2cdev_ioctl+0x247/0x2ed
       	vfs_ioctl+0x21/0x30
       	sys_ioctl+0xb18/0xb41
      
      Fix this by calling virtio_get_buf() from the notify handler like other
      virtio drivers and by actually waiting for all the buffers to be
      completed.
      
      Fixes: 3cfc8838 ("i2c: virtio: add a virtio i2c frontend driver")
      Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: default avatarVincent Whitchurch <vincent.whitchurch@axis.com>
      Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      b503de23
  6. Nov 30, 2021
  7. Nov 29, 2021
  8. Nov 23, 2021
    • Vincent Whitchurch's avatar
      i2c: virtio: disable timeout handling · 84e1d0bf
      Vincent Whitchurch authored
      
      If a timeout is hit, it can result is incorrect data on the I2C bus
      and/or memory corruptions in the guest since the device can still be
      operating on the buffers it was given while the guest has freed them.
      
      Here is, for example, the start of a slub_debug splat which was
      triggered on the next transfer after one transfer was forced to timeout
      by setting a breakpoint in the backend (rust-vmm/vhost-device):
      
       BUG kmalloc-1k (Not tainted): Poison overwritten
       First byte 0x1 instead of 0x6b
       Allocated in virtio_i2c_xfer+0x65/0x35c age=350 cpu=0 pid=29
       	__kmalloc+0xc2/0x1c9
       	virtio_i2c_xfer+0x65/0x35c
       	__i2c_transfer+0x429/0x57d
       	i2c_transfer+0x115/0x134
       	i2cdev_ioctl_rdwr+0x16a/0x1de
       	i2cdev_ioctl+0x247/0x2ed
       	vfs_ioctl+0x21/0x30
       	sys_ioctl+0xb18/0xb41
       Freed in virtio_i2c_xfer+0x32e/0x35c age=244 cpu=0 pid=29
       	kfree+0x1bd/0x1cc
       	virtio_i2c_xfer+0x32e/0x35c
       	__i2c_transfer+0x429/0x57d
       	i2c_transfer+0x115/0x134
       	i2cdev_ioctl_rdwr+0x16a/0x1de
       	i2cdev_ioctl+0x247/0x2ed
       	vfs_ioctl+0x21/0x30
       	sys_ioctl+0xb18/0xb41
      
      There is no simple fix for this (the driver would have to always create
      bounce buffers and hold on to them until the device eventually returns
      the buffers), so just disable the timeout support for now.
      
      Fixes: 3cfc8838 ("i2c: virtio: add a virtio i2c frontend driver")
      Acked-by: default avatarJie Deng <jie.deng@intel.com>
      Signed-off-by: default avatarVincent Whitchurch <vincent.whitchurch@axis.com>
      Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      84e1d0bf
    • Jarkko Nikula's avatar
      i2c: i801: Fix interrupt storm from SMB_ALERT signal · 03a976c9
      Jarkko Nikula authored
      Currently interrupt storm will occur from i2c-i801 after first
      transaction if SMB_ALERT signal is enabled and ever asserted. It is
      enough if the signal is asserted once even before the driver is loaded
      and does not recover because that interrupt is not acknowledged.
      
      This fix aims to fix it by two ways:
      - Add acknowledging for the SMB_ALERT interrupt status
      - Disable the SMB_ALERT interrupt on platforms where possible since the
        driver currently does not make use for it
      
      Acknowledging resets the SMB_ALERT interrupt status on all platforms and
      also should help to avoid interrupt storm on older platforms where the
      SMB_ALERT interrupt disabling is not available.
      
      For simplicity this fix reuses the host notify feature for disabling and
      restoring original register value.
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=177311
      
      
      Reported-by: default avatar <ck+kernelbugzilla@bl4ckb0x.de>
      Reported-by: default avatar <stephane.poignant@protonmail.com>
      Signed-off-by: default avatarJarkko Nikula <jarkko.nikula@linux.intel.com>
      Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
      Tested-by: default avatarJean Delvare <jdelvare@suse.de>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      03a976c9
    • Jean DELVARE's avatar
      i2c: i801: Restore INTREN on unload · 9b5bf587
      Jean DELVARE authored
      
      If driver interrupts are enabled, SMBHSTCNT_INTREN will be 1 after
      the first transaction, and will stay to that value forever. This
      means that interrupts will be generated for both host-initiated
      transactions and also SMBus Alert events even after the driver is
      unloaded. To be on the safe side, we should restore the initial state
      of this bit at suspend and reboot time, as we do for several other
      configuration bits already and for the same reason: the BIOS should
      be handed the device in the same configuration state in which we
      received it. Otherwise interrupts may be generated which nobody
      will process.
      
      Signed-off-by: default avatarJean Delvare <jdelvare@suse.de>
      Tested-by: default avatarJarkko Nikula <jarkko.nikula@linux.intel.com>
      Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
      9b5bf587
  9. Nov 07, 2021
  10. Nov 06, 2021
  11. Nov 03, 2021
  12. Nov 01, 2021
  13. Oct 30, 2021
    • Sudeep Holla's avatar
      mailbox: pcc: Use PCC mailbox channel pointer instead of standard · 7b6da7fe
      Sudeep Holla authored
      
      Now that we have all the shared memory region information populated in
      the pcc_mbox_chan, let us propagate the pointer to the same as the
      return value to pcc_mbox_request channel.
      
      This eliminates the need for the individual users of PCC mailbox to
      parse the PCCT subspace entries and fetch the shmem information. This
      also eliminates the need for PCC mailbox controller to set con_priv to
      PCCT subspace entries. This is required as con_priv is private to the
      controller driver to attach private data associated with the channel and
      not meant to be used by the mailbox client/users.
      
      Let us convert all the users of pcc_mbox_{request,free}_channel to use
      new interface.
      
      Cc: Jean Delvare <jdelvare@suse.com>
      Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
      Acked-by: default avatarWolfram Sang <wsa@kernel.org>
      Acked-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarJassi Brar <jaswinder.singh@linaro.org>
      7b6da7fe
  14. Oct 29, 2021
  15. Oct 20, 2021
  16. Oct 11, 2021
  17. Oct 04, 2021
Loading