Skip to content
Snippets Groups Projects
  1. Sep 28, 2022
    • Xingui Yang's avatar
      scsi: hisi_sas: Modify v3 HW ATA completion process when SATA disk is in error status · 63c0c05a
      Xingui Yang authored
      driver inclusion
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I5Q63H
      
      
      CVE: NA
      
      -------------------------------------
      
      When an NCQ error occurs, SAS controller will abnormally complete the I/Os
      that newly delivered to disk, and bit8 in CQ dw3 will be set to 1 to
      indicate current SATA disk is in error status. The current processing flow
      is set ts->stat to SAS_OPEN_REJECT and then sas_ata_task_done() will set
      fis stat to ATA_ERR. After analyzed by ata_eh_analyze_tf(), err_mask will
      set to AC_ERR_HSM. If media error occurs for four times within 10 minutes
      and the chip rejects new I/Os for four times, NCQ will be disabled due to
      excessive errors.
      
      However, if media error occurs multiple times, the NCQ mode shouldn't be
      disabled. Therefore, use sas_task_abort() to handle abnormally completed
      I/Os when SATA disk is in error status.
      
      [10253.397429] hisi_sas_v3_hw 0000:b4:02.0: erroneous completion disk err dev id=2 sas_addr=0x5000000000000605 CQ hdr: 0x400903 0x2007f 0x0 0x80470000
      [10253.397430] hisi_sas_v3_hw 0000:b4:02.0: erroneous completion iptt=135 task= pK-error dev id=2 sas_addr=0x5000000000000605 CQ hdr: 0x203 0x20087 0x0 0x100 Error info: 0x0 0x0 0x0 0x0
      [10253.397432] hisi_sas_v3_hw 0000:b4:02.0: erroneous completion iptt=136 task= pK-error dev id=2 sas_addr=0x5000000000000605 CQ hdr: 0x203 0x20088 0x0 0x100 Error info: 0x0 0x0 0x0 0x0
      
      Signed-off-by: default avatarXingui Yang <yangxingui@huawei.com>
      Reviewed-by: default avatarkang fenglong <kangfenglong@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      63c0c05a
  2. Aug 25, 2022
  3. Aug 15, 2022
  4. Aug 04, 2022
    • Damien Le Moal's avatar
      scsi: mpt3sas: Fix unlock imbalance · 7888ad2c
      Damien Le Moal authored
      mainline inclusion
      from mainline-v5.8-rc5
      commit cb551b8d
      category: bugfix
      bugzilla: 187287, https://gitee.com/openeuler/kernel/issues/I5JQML
      CVE: NA
      
      --------------------------------
      
      In BRM_status_show(), if the condition "!ioc->is_warpdrive" tested on entry
      to the function is true, a "goto out" is called. This results in unlocking
      ioc->pci_access_mutex without this mutex lock being taken.  This generates
      the following splat:
      
      [ 1148.539883] mpt3sas_cm2: BRM_status_show: BRM attribute is only for warpdrive
      [ 1148.547184]
      [ 1148.548708] =====================================
      [ 1148.553501] WARNING: bad unlock balance detected!
      [ 1148.558277] 5.8.0-rc3+ #827 Not tainted
      [ 1148.562183] -------------------------------------
      [ 1148.566959] cat/5008 is trying to release lock (&ioc->pci_access_mutex) at:
      [ 1148.574035] [<ffffffffc070b7a3>] BRM_status_show+0xd3/0x100 [mpt3sas]
      [ 1148.580574] but there are no more locks to release!
      [ 1148.585524]
      [ 1148.585524] other info that might help us debug this:
      [ 1148.599624] 3 locks held by cat/5008:
      [ 1148.607085]  #0: ffff92aea3e392c0 (&p->lock){+.+.}-{3:3}, at: seq_read+0x34/0x480
      [ 1148.618509]  #1: ffff922ef14c4888 (&of->mutex){+.+.}-{3:3}, at: kernfs_seq_start+0x2a/0xb0
      [ 1148.630729]  #2: ffff92aedb5d7310 (kn->active#224){.+.+}-{0:0}, at: kernfs_seq_start+0x32/0xb0
      [ 1148.643347]
      [ 1148.643347] stack backtrace:
      [ 1148.655259] CPU: 73 PID: 5008 Comm: cat Not tainted 5.8.0-rc3+ #827
      [ 1148.665309] Hardware name: HGST H4060-S/S2600STB, BIOS SE5C620.86B.02.01.0008.031920191559 03/19/2019
      [ 1148.678394] Call Trace:
      [ 1148.684750]  dump_stack+0x78/0xa0
      [ 1148.691802]  lock_release.cold+0x45/0x4a
      [ 1148.699451]  __mutex_unlock_slowpath+0x35/0x270
      [ 1148.707675]  BRM_status_show+0xd3/0x100 [mpt3sas]
      [ 1148.716092]  dev_attr_show+0x19/0x40
      [ 1148.723664]  sysfs_kf_seq_show+0x87/0x100
      [ 1148.731193]  seq_read+0xbc/0x480
      [ 1148.737882]  vfs_read+0xa0/0x160
      [ 1148.744514]  ksys_read+0x58/0xd0
      [ 1148.751129]  do_syscall_64+0x4c/0xa0
      [ 1148.757941]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [ 1148.766240] RIP: 0033:0x7f1230566542
      [ 1148.772957] Code: Bad RIP value.
      [ 1148.779206] RSP: 002b:00007ffeac1bcac8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
      [ 1148.790063] RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007f1230566542
      [ 1148.800284] RDX: 0000000000020000 RSI: 00007f1223460000 RDI: 0000000000000003
      [ 1148.810474] RBP: 00007f1223460000 R08: 00007f122345f010 R09: 0000000000000000
      [ 1148.820641] R10: 0000000000000022 R11: 0000000000000246 R12: 0000000000000000
      [ 1148.830728] R13: 0000000000000003 R14: 0000000000020000 R15: 0000000000020000
      
      Fix this by returning immediately instead of jumping to the out label.
      
      Link: https://lore.kernel.org/r/20200701085254.51740-1-damien.lemoal@wdc.com
      
      
      Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
      Acked-by: default avatarSreekanth Reddy <sreekanth.reddy@broadcom.com>
      Signed-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Conflict:
      	drivers/scsi/mpt3sas/mpt3sas_ctl.c
      Signed-off-by: default avatarZhang Wensheng <zhangwensheng5@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      7888ad2c
  5. Jul 30, 2022
  6. Jul 20, 2022
    • Zhang Wensheng's avatar
      scsi: ses: fix slab-out-of-bounds in ses_enclosure_data_process · b101167f
      Zhang Wensheng authored
      hulk inclusion
      category: bugfix
      bugzilla: 187025, https://gitee.com/src-openeuler/kernel/issues/I5HPS5
      
      
      CVE: NA
      
      --------------------------------
      
      Kasan report a bug like below:
      [  494.865170] ==================================================================
      [  494.901335] BUG: KASAN: slab-out-of-bounds in ses_enclosure_data_process+0x234/0x6f0 [ses]
      [  494.901347] Write of size 1 at addr ffff8882f3181a70 by task systemd-udevd/1704
      [  494.931929] i801_smbus 0000:00:1f.4: SPD Write Disable is set
      
      [  494.944092] CPU: 12 PID: 1704 Comm: systemd-udevd Tainted: G
      [  494.944101] Hardware name: Huawei 2288H V5/BC11SPSCB0, BIOS 7.01 11/13/2019
      [  494.964003] i801_smbus 0000:00:1f.4: SMBus using PCI interrupt
      [  494.978532] Call Trace:
      [  494.978544]  dump_stack+0xbe/0xf9
      [  494.978558]  print_address_description.constprop.0+0x19/0x130
      [  495.092838]  ? ses_enclosure_data_process+0x234/0x6f0 [ses]
      [  495.092846]  __kasan_report.cold+0x68/0x80
      [  495.092855]  ? __kasan_kmalloc.constprop.0+0x71/0xd0
      [  495.092862]  ? ses_enclosure_data_process+0x234/0x6f0 [ses]
      [  495.092868]  kasan_report+0x3a/0x50
      [  495.092875]  ses_enclosure_data_process+0x234/0x6f0 [ses]
      [  495.092882]  ? mutex_unlock+0x1d/0x40
      [  495.092889]  ses_intf_add+0x57f/0x910 [ses]
      [  495.092900]  class_interface_register+0x26d/0x290
      [  495.092906]  ? class_destroy+0xd0/0xd0
      [  495.092912]  ? 0xffffffffc0bf8000
      [  495.092919]  ses_init+0x18/0x1000 [ses]
      [  495.092927]  do_one_initcall+0xcb/0x370
      [  495.092934]  ? initcall_blacklisted+0x1b0/0x1b0
      [  495.092942]  ? create_object.isra.0+0x330/0x3a0
      [  495.092950]  ? kasan_unpoison_shadow+0x33/0x40
      [  495.092957]  ? kasan_unpoison_shadow+0x33/0x40
      [  495.092966]  do_init_module+0xe4/0x3a0
      [  495.092972]  load_module+0xd0a/0xdd0
      [  495.092980]  ? layout_and_allocate+0x300/0x300
      [  495.092989]  ? seccomp_run_filters+0x1d6/0x2c0
      [  495.092999]  ? kernel_read_file_from_fd+0xb3/0xe0
      [  495.093006]  __se_sys_finit_module+0x11b/0x1b0
      [  495.093012]  ? __ia32_sys_init_module+0x40/0x40
      [  495.093023]  ? __audit_syscall_entry+0x226/0x290
      [  495.093032]  do_syscall_64+0x33/0x40
      [  495.093041]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [  495.093046] RIP: 0033:0x7f39c3376089
      [  495.093054] Code: 00 48 81 c4 80 00 00 00 89 f0 c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d e7 dd 0b 00 f7 d8 64 89 01 48
      [  495.093058] RSP: 002b:00007ffdc6009e18 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
      [  495.093068] RAX: ffffffffffffffda RBX: 000055d4192801c0 RCX: 00007f39c3376089
      [  495.093072] RDX: 0000000000000000 RSI: 00007f39c2fae99d RDI: 000000000000000f
      [  495.093076] RBP: 00007f39c2fae99d R08: 0000000000000000 R09: 0000000000000001
      [  495.093080] R10: 000000000000000f R11: 0000000000000246 R12: 0000000000000000
      [  495.093084] R13: 000055d419282e00 R14: 0000000000020000 R15: 000055d41927f1f0
      
      [  495.093091] Allocated by task 1704:
      [  495.093098]  kasan_save_stack+0x1b/0x40
      [  495.093105]  __kasan_kmalloc.constprop.0+0xc2/0xd0
      [  495.093111]  ses_enclosure_data_process+0x65d/0x6f0 [ses]
      [  495.093117]  ses_intf_add+0x57f/0x910 [ses]
      [  495.093123]  class_interface_register+0x26d/0x290
      [  495.093129]  ses_init+0x18/0x1000 [ses]
      [  495.093134]  do_one_initcall+0xcb/0x370
      [  495.093139]  do_init_module+0xe4/0x3a0
      [  495.093144]  load_module+0xd0a/0xdd0
      [  495.093150]  __se_sys_finit_module+0x11b/0x1b0
      [  495.093155]  do_syscall_64+0x33/0x40
      [  495.093162]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      [  495.093168] The buggy address belongs to the object at ffff8882f3181a40
                      which belongs to the cache kmalloc-64 of size 64
      [  495.093173] The buggy address is located 48 bytes inside of
                      64-byte region [ffff8882f3181a40, ffff8882f3181a80)
      [  495.093175] The buggy address belongs to the page:
      [  495.093181] page:ffffea000bcc6000 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2f3180
      [  495.093186] head:ffffea000bcc6000 order:2 compound_mapcount:0 compound_pincount:0
      [  495.093194] flags: 0x17ffe0000010200(slab|head|node=0|zone=2|lastcpupid=0x3fff)
      [  495.093204] raw: 017ffe0000010200 ffffea0016e5fb08 ffffea0016921508 ffff888100050e00
      [  495.093211] raw: 0000000000000000 0000000000200020 00000001ffffffff 0000000000000000
      [  495.093213] page dumped because: kasan: bad access detected
      
      [  495.093216] Memory state around the buggy address:
      [  495.093222]  ffff8882f3181900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      [  495.093227]  ffff8882f3181980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      [  495.093231] >ffff8882f3181a00: fc fc fc fc fc fc fc fc 00 00 00 00 01 fc fc fc
      [  495.093234]                                                              ^
      [  495.093239]  ffff8882f3181a80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      [  495.093244]  ffff8882f3181b00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
      [  495.093246] ==================================================================
      
      After analysis on vmcore, it was found that the line "desc_ptr[len] =
      '\0';" has slab-out-of-bounds problem in ses_enclosure_data_process.
      In ses_enclosure_data_process, "desc_ptr" point to "buf", so it have
      to be limited in the memory of "buf", however. although there is
      "desc_ptr >= buf + page7_len" judgment, it does not work because
      "desc_ptr + 4 + len" may bigger than "buf + page7_len", which will
      lead to slab-out-of-bounds problem.
      
      Signed-off-by: default avatarZhang Wensheng <zhangwensheng5@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
      b101167f
  7. Jul 07, 2022
  8. Jun 02, 2022
  9. May 13, 2022
  10. Apr 15, 2022
  11. Mar 14, 2022
  12. Jan 29, 2022
  13. Jan 17, 2022
  14. Dec 30, 2021
  15. Dec 28, 2021
  16. Dec 22, 2021
  17. Dec 20, 2021
  18. Dec 08, 2021
  19. Nov 12, 2021
    • Maciej W. Rozycki's avatar
      scsi: BusLogic: Fix missing pr_cont() use · 75ec4ff6
      Maciej W. Rozycki authored
      stable inclusion
      from linux-4.19.207
      commit 33b8fcdedbde2b2a508c3d78d4bb34e4067391a0
      
      --------------------------------
      
      commit 44d01fc86d952f5a8b8b32bdb4841504d5833d95 upstream.
      
      Update BusLogic driver's messaging system to use pr_cont() for continuation
      lines, bringing messy output:
      
      pci 0000:00:13.0: PCI->APIC IRQ transform: INT A -> IRQ 17
      scsi: ***** BusLogic SCSI Driver Version 2.1.17 of 12 September 2013 *****
      scsi: Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>
      scsi0: Configuring BusLogic Model BT-958 PCI Wide Ultra SCSI Host Adapter
      scsi0:   Firmware Version: 5.07B, I/O Address: 0x7000, IRQ Channel: 17/Level
      scsi0:   PCI Bus: 0, Device: 19, Address:
      0xE0012000,
      Host Adapter SCSI ID: 7
      scsi0:   Parity Checking: Enabled, Extended Translation: Enabled
      scsi0:   Synchronous Negotiation: Ultra, Wide Negotiation: Enabled
      scsi0:   Disconnect/Reconnect: Enabled, Tagged Queuing: Enabled
      scsi0:   Scatter/Gather Limit: 128 of 8192 segments, Mailboxes: 211
      scsi0:   Driver Queue Depth: 211, Host Adapter Queue Depth: 192
      scsi0:   Tagged Queue Depth:
      Automatic
      , Untagged Queue Depth: 3
      scsi0:   SCSI Bus Termination: Both Enabled
      , SCAM: Disabled
      
      scsi0: *** BusLogic BT-958 Initialized Successfully ***
      scsi host0: BusLogic BT-958
      
      back to order:
      
      pci 0000:00:13.0: PCI->APIC IRQ transform: INT A -> IRQ 17
      scsi: ***** BusLogic SCSI Driver Version 2.1.17 of 12 September 2013 *****
      scsi: Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>
      scsi0: Configuring BusLogic Model BT-958 PCI Wide Ultra SCSI Host Adapter
      scsi0:   Firmware Version: 5.07B, I/O Address: 0x7000, IRQ Channel: 17/Level
      scsi0:   PCI Bus: 0, Device: 19, Address: 0xE0012000, Host Adapter SCSI ID: 7
      scsi0:   Parity Checking: Enabled, Extended Translation: Enabled
      scsi0:   Synchronous Negotiation: Ultra, Wide Negotiation: Enabled
      scsi0:   Disconnect/Reconnect: Enabled, Tagged Queuing: Enabled
      scsi0:   Scatter/Gather Limit: 128 of 8192 segments, Mailboxes: 211
      scsi0:   Driver Queue Depth: 211, Host Adapter Queue Depth: 192
      scsi0:   Tagged Queue Depth: Automatic, Untagged Queue Depth: 3
      scsi0:   SCSI Bus Termination: Both Enabled, SCAM: Disabled
      scsi0: *** BusLogic BT-958 Initialized Successfully ***
      scsi host0: BusLogic BT-958
      
      Also diagnostic output such as with the BusLogic=TraceConfiguration
      parameter is affected and becomes vertical and therefore hard to read.
      This has now been corrected, e.g.:
      
      pci 0000:00:13.0: PCI->APIC IRQ transform: INT A -> IRQ 17
      blogic_cmd(86) Status = 30:  4 ==>  4: FF 05 93 00
      blogic_cmd(95) Status = 28: (Modify I/O Address)
      blogic_cmd(91) Status = 30:  1 ==>  1: 01
      blogic_cmd(04) Status = 30:  4 ==>  4: 41 41 35 30
      blogic_cmd(8D) Status = 30: 14 ==> 14: 45 DC 00 20 00 00 00 00 00 40 30 37 42 1D
      scsi: ***** BusLogic SCSI Driver Version 2.1.17 of 12 September 2013 *****
      scsi: Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>
      blogic_cmd(04) Status = 30:  4 ==>  4: 41 41 35 30
      blogic_cmd(0B) Status = 30:  3 ==>  3: 00 08 07
      blogic_cmd(0D) Status = 30: 34 ==> 34: 03 01 07 04 00 00 00 00 00 00 00 00 00 00 00 00 FF 42 44 46 FF 00 00 00 00 00 00 00 00 00 FF 00 FF 00
      blogic_cmd(8D) Status = 30: 14 ==> 14: 45 DC 00 20 00 00 00 00 00 40 30 37 42 1D
      blogic_cmd(84) Status = 30:  1 ==>  1: 37
      blogic_cmd(8B) Status = 30:  5 ==>  5: 39 35 38 20 20
      blogic_cmd(85) Status = 30:  1 ==>  1: 42
      blogic_cmd(86) Status = 30:  4 ==>  4: FF 05 93 00
      blogic_cmd(91) Status = 30: 64 ==> 64: 41 46 3E 20 39 35 38 20 20 00 C4 00 04 01 07 2F 07 04 35 FF FF FF FF FF FF FF FF FF FF 01 00 FE FF 08 FF FF 00 00 00 00 00 00 00 01 00 01 00 00 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 FC
      scsi0: Configuring BusLogic Model BT-958 PCI Wide Ultra SCSI Host Adapter
      
      etc.
      
      Link: https://lore.kernel.org/r/alpine.DEB.2.21.2104201940430.44318@angie.orcam.me.uk
      
      
      Fixes: 4bcc595c ("printk: reinstate KERN_CONT for printing continuation lines")
      Cc: stable@vger.kernel.org # v4.9+
      Acked-by: default avatarKhalid Aziz <khalid@gonehiking.org>
      Signed-off-by: default avatarMaciej W. Rozycki <macro@orcam.me.uk>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      75ec4ff6
  20. Nov 04, 2021
  21. Nov 01, 2021
    • Ye Bin's avatar
      scsi: scsi_debug: Fix out-of-bound read in resp_report_tgtpgs() · ffceb572
      Ye Bin authored
      mainline inclusion
      from mainline-v5.16
      commit f347c26836c270199de1599c3cd466bb7747caa9
      category: bugfix
      bugzilla: 176010
      CVE: NA
      
      -----------------------------------------------
      
      The following issue was observed running syzkaller:
      
      BUG: KASAN: slab-out-of-bounds in memcpy include/linux/string.h:377 [inline]
      BUG: KASAN: slab-out-of-bounds in sg_copy_buffer+0x150/0x1c0 lib/scatterlist.c:831
      Read of size 2132 at addr ffff8880aea95dc8 by task syz-executor.0/9815
      
      CPU: 0 PID: 9815 Comm: syz-executor.0 Not tainted 4.19.202-00874-gfc0fe04215a9 #2
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0xe4/0x14a lib/dump_stack.c:118
       print_address_description+0x73/0x280 mm/kasan/report.c:253
       kasan_report_error mm/kasan/report.c:352 [inline]
       kasan_report+0x272/0x370 mm/kasan/report.c:410
       memcpy+0x1f/0x50 mm/kasan/kasan.c:302
       memcpy include/linux/string.h:377 [inline]
       sg_copy_buffer+0x150/0x1c0 lib/scatterlist.c:831
       fill_from_dev_buffer+0x14f/0x340 drivers/scsi/scsi_debug.c:1021
       resp_report_tgtpgs+0x5aa/0x770 drivers/scsi/scsi_debug.c:1772
       schedule_resp+0x464/0x12f0 drivers/scsi/scsi_debug.c:4429
       scsi_debug_queuecommand+0x467/0x1390 drivers/scsi/scsi_debug.c:5835
       scsi_dispatch_cmd+0x3fc/0x9b0 drivers/scsi/scsi_lib.c:1896
       scsi_request_fn+0x1042/0x1810 drivers/scsi/scsi_lib.c:2034
       __blk_run_queue_uncond block/blk-core.c:464 [inline]
       __blk_run_queue+0x1a4/0x380 block/blk-core.c:484
       blk_execute_rq_nowait+0x1c2/0x2d0 block/blk-exec.c:78
       sg_common_write.isra.19+0xd74/0x1dc0 drivers/scsi/sg.c:847
       sg_write.part.23+0x6e0/0xd00 drivers/scsi/sg.c:716
       sg_write+0x64/0xa0 drivers/scsi/sg.c:622
       __vfs_write+0xed/0x690 fs/read_write.c:485
      kill_bdev:block_device:00000000e138492c
       vfs_write+0x184/0x4c0 fs/read_write.c:549
       ksys_write+0x107/0x240 fs/read_write.c:599
       do_syscall_64+0xc2/0x560 arch/x86/entry/common.c:293
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      We get 'alen' from command its type is int. If userspace passes a large
      length we will get a negative 'alen'.
      
      Switch n, alen, and rlen to u32.
      
      Link: https://lore.kernel.org/r/20211013033913.2551004-3-yebin10@huawei.com
      
      
      Acked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      
      conflicts:
      drivers/scsi/scsi_debug.c
      
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      ffceb572
    • Ye Bin's avatar
      scsi: scsi_debug: Fix out-of-bound read in resp_readcap16() · a4489229
      Ye Bin authored
      mainline inclusion
      from mainline-v5.16
      commit 4e3ace0051e7e504b55d239daab8789dd89b863c
      category: bugfix
      bugzilla: 176010
      CVE: NA
      
      -----------------------------------------------
      
      The following warning was observed running syzkaller:
      
      [ 3813.830724] sg_write: data in/out 65466/242 bytes for SCSI command 0x9e-- guessing data in;
      [ 3813.830724]    program syz-executor not setting count and/or reply_len properly
      [ 3813.836956] ==================================================================
      [ 3813.839465] BUG: KASAN: stack-out-of-bounds in sg_copy_buffer+0x157/0x1e0
      [ 3813.841773] Read of size 4096 at addr ffff8883cf80f540 by task syz-executor/1549
      [ 3813.846612] Call Trace:
      [ 3813.846995]  dump_stack+0x108/0x15f
      [ 3813.847524]  print_address_description+0xa5/0x372
      [ 3813.848243]  kasan_report.cold+0x236/0x2a8
      [ 3813.849439]  check_memory_region+0x240/0x270
      [ 3813.850094]  memcpy+0x30/0x80
      [ 3813.850553]  sg_copy_buffer+0x157/0x1e0
      [ 3813.853032]  sg_copy_from_buffer+0x13/0x20
      [ 3813.853660]  fill_from_dev_buffer+0x135/0x370
      [ 3813.854329]  resp_readcap16+0x1ac/0x280
      [ 3813.856917]  schedule_resp+0x41f/0x1630
      [ 3813.858203]  scsi_debug_queuecommand+0xb32/0x17e0
      [ 3813.862699]  scsi_dispatch_cmd+0x330/0x950
      [ 3813.863329]  scsi_request_fn+0xd8e/0x1710
      [ 3813.863946]  __blk_run_queue+0x10b/0x230
      [ 3813.864544]  blk_execute_rq_nowait+0x1d8/0x400
      [ 3813.865220]  sg_common_write.isra.0+0xe61/0x2420
      [ 3813.871637]  sg_write+0x6c8/0xef0
      [ 3813.878853]  __vfs_write+0xe4/0x800
      [ 3813.883487]  vfs_write+0x17b/0x530
      [ 3813.884008]  ksys_write+0x103/0x270
      [ 3813.886268]  __x64_sys_write+0x77/0xc0
      [ 3813.886841]  do_syscall_64+0x106/0x360
      [ 3813.887415]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      This issue can be reproduced with the following syzkaller log:
      
      r0 = openat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', 0x26e1, 0x0)
      r1 = syz_open_procfs(0xffffffffffffffff, &(0x7f0000000000)='fd/3\x00')
      open_by_handle_at(r1, &(0x7f00000003c0)=ANY=[@ANYRESHEX], 0x602000)
      r2 = syz_open_dev$sg(&(0x7f0000000000), 0x0, 0x40782)
      write$binfmt_aout(r2, &(0x7f0000000340)=ANY=[@ANYBLOB="00000000deff000000000000000000000000000000000000000000000000000047f007af9e107a41ec395f1bded7be24277a1501ff6196a83366f4e6362bc0ff2b247f68a972989b094b2da4fb3607fcf611a22dd04310d28c75039d"], 0x126)
      
      In resp_readcap16() we get "int alloc_len" value -1104926854, and then pass
      the huge arr_len to fill_from_dev_buffer(), but arr is only 32 bytes. This
      leads to OOB in sg_copy_buffer().
      
      To solve this issue, define alloc_len as u32.
      
      Link: https://lore.kernel.org/r/20211013033913.2551004-2-yebin10@huawei.com
      
      
      Acked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      
      conflicts:
      drivers/scsi/scsi_debug.c
      
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Reviewed-by: default avatarJason Yan <yanaijie@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      a4489229
    • Yang Xingui's avatar
      scsi: hisi_sas: unsupported DIX between OS and HBA only for SATA device · c2381170
      Yang Xingui authored
      
      driver inclusion
      category: bugfix
      bugzilla: NA
      CVE: NA
      
      Signed-off-by: default avatarYang Xingui <yangxingui@huawei.com>
      Reviewed-by: default avatarOuyangdelong <ouyangdelong@huawei.com>
      Reviewed-by: default avatarKangfenglong <kangfenglong@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      c2381170
  22. Oct 30, 2021
  23. Oct 25, 2021
    • Sreekanth Reddy's avatar
      scsi: core: Avoid printing an error if target_alloc() returns -ENXIO · dd49b49c
      Sreekanth Reddy authored
      stable inclusion
      from linux-4.19.205
      commit 460add3104945704bfd2b92441b48a30b2ee9f1e
      
      --------------------------------
      
      [ Upstream commit 70edd2e6f652f67d854981fd67f9ad0f1deaea92 ]
      
      Avoid printing a 'target allocation failed' error if the driver
      target_alloc() callback function returns -ENXIO. This return value
      indicates that the corresponding H:C:T:L entry is empty.
      
      Removing this error reduces the scan time if the user issues SCAN_WILD_CARD
      scan operation through sysfs parameter on a host with a lot of empty
      H:C:T:L entries.
      
      Avoiding the printk on -ENXIO matches the behavior of the other callback
      functions during scanning.
      
      Link: https://lore.kernel.org/r/20210726115402.1936-1-sreekanth.reddy@broadcom.com
      
      
      Signed-off-by: default avatarSreekanth Reddy <sreekanth.reddy@broadcom.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      dd49b49c
    • Ye Bin's avatar
      scsi: scsi_dh_rdac: Avoid crash during rdac_bus_attach() · 0fce27d1
      Ye Bin authored
      stable inclusion
      from linux-4.19.205
      commit e25e7495d72649cb50b42865356bfe272b3a2a6d
      
      --------------------------------
      
      [ Upstream commit bc546c0c9abb3bb2fb46866b3d1e6ade9695a5f6 ]
      
      The following BUG_ON() was observed during RDAC scan:
      
      [595952.944297] kernel BUG at drivers/scsi/device_handler/scsi_dh_rdac.c:427!
      [595952.951143] Internal error: Oops - BUG: 0 [#1] SMP
      ......
      [595953.251065] Call trace:
      [595953.259054]  check_ownership+0xb0/0x118
      [595953.269794]  rdac_bus_attach+0x1f0/0x4b0
      [595953.273787]  scsi_dh_handler_attach+0x3c/0xe8
      [595953.278211]  scsi_dh_add_device+0xc4/0xe8
      [595953.282291]  scsi_sysfs_add_sdev+0x8c/0x2a8
      [595953.286544]  scsi_probe_and_add_lun+0x9fc/0xd00
      [595953.291142]  __scsi_scan_target+0x598/0x630
      [595953.295395]  scsi_scan_target+0x120/0x130
      [595953.299481]  fc_user_scan+0x1a0/0x1c0 [scsi_transport_fc]
      [595953.304944]  store_scan+0xb0/0x108
      [595953.308420]  dev_attr_store+0x44/0x60
      [595953.312160]  sysfs_kf_write+0x58/0x80
      [595953.315893]  kernfs_fop_write+0xe8/0x1f0
      [595953.319888]  __vfs_write+0x60/0x190
      [595953.323448]  vfs_write+0xac/0x1c0
      [595953.326836]  ksys_write+0x74/0xf0
      [595953.330221]  __arm64_sys_write+0x24/0x30
      
      Code is in check_ownership:
      
      	list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) {
      		/* h->sdev should always be valid */
      		BUG_ON(!tmp->sdev);
      		tmp->sdev->access_state = access_state;
      	}
      
      	rdac_bus_attach
      		initialize_controller
      			list_add_rcu(&h->node, &h->ctlr->dh_list);
      			h->sdev = sdev;
      
      	rdac_bus_detach
      		list_del_rcu(&h->node);
      		h->sdev = NULL;
      
      Fix the race between rdac_bus_attach() and rdac_bus_detach() where h->sdev
      is NULL when processing the RDAC attach.
      
      Link: https://lore.kernel.org/r/20210113063103.2698953-1-yebin10@huawei.com
      
      
      Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
      Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      0fce27d1