1. 29 1月, 2022 1 次提交
    • G
      scsi: scsi_debug: Sanity check block descriptor length in resp_mode_select() · d2584a20
      George Kennedy 提交于
      stable inclusion
      from linux-4.19.222
      commit 04181973c38f3d6a353f9246dcf7fee08024fd9e
      
      --------------------------------
      
      commit e0a2c28d upstream.
      
      In resp_mode_select() sanity check the block descriptor len to avoid UAF.
      
      BUG: KASAN: use-after-free in resp_mode_select+0xa4c/0xb40 drivers/scsi/scsi_debug.c:2509
      Read of size 1 at addr ffff888026670f50 by task scsicmd/15032
      
      CPU: 1 PID: 15032 Comm: scsicmd Not tainted 5.15.0-01d0625 #15
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      Call Trace:
       <TASK>
       dump_stack_lvl+0x89/0xb5 lib/dump_stack.c:107
       print_address_description.constprop.9+0x28/0x160 mm/kasan/report.c:257
       kasan_report.cold.14+0x7d/0x117 mm/kasan/report.c:443
       __asan_report_load1_noabort+0x14/0x20 mm/kasan/report_generic.c:306
       resp_mode_select+0xa4c/0xb40 drivers/scsi/scsi_debug.c:2509
       schedule_resp+0x4af/0x1a10 drivers/scsi/scsi_debug.c:5483
       scsi_debug_queuecommand+0x8c9/0x1e70 drivers/scsi/scsi_debug.c:7537
       scsi_queue_rq+0x16b4/0x2d10 drivers/scsi/scsi_lib.c:1521
       blk_mq_dispatch_rq_list+0xb9b/0x2700 block/blk-mq.c:1640
       __blk_mq_sched_dispatch_requests+0x28f/0x590 block/blk-mq-sched.c:325
       blk_mq_sched_dispatch_requests+0x105/0x190 block/blk-mq-sched.c:358
       __blk_mq_run_hw_queue+0xe5/0x150 block/blk-mq.c:1762
       __blk_mq_delay_run_hw_queue+0x4f8/0x5c0 block/blk-mq.c:1839
       blk_mq_run_hw_queue+0x18d/0x350 block/blk-mq.c:1891
       blk_mq_sched_insert_request+0x3db/0x4e0 block/blk-mq-sched.c:474
       blk_execute_rq_nowait+0x16b/0x1c0 block/blk-exec.c:63
       sg_common_write.isra.18+0xeb3/0x2000 drivers/scsi/sg.c:837
       sg_new_write.isra.19+0x570/0x8c0 drivers/scsi/sg.c:775
       sg_ioctl_common+0x14d6/0x2710 drivers/scsi/sg.c:941
       sg_ioctl+0xa2/0x180 drivers/scsi/sg.c:1166
       __x64_sys_ioctl+0x19d/0x220 fs/ioctl.c:52
       do_syscall_64+0x3a/0x80 arch/x86/entry/common.c:50
       entry_SYSCALL_64_after_hwframe+0x44/0xae arch/x86/entry/entry_64.S:113
      
      Link: https://lore.kernel.org/r/1637262208-28850-1-git-send-email-george.kennedy@oracle.comReported-by: Nsyzkaller <syzkaller@googlegroups.com>
      Acked-by: NDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: NGeorge Kennedy <george.kennedy@oracle.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      d2584a20
  2. 01 11月, 2021 2 次提交
    • Y
      scsi: scsi_debug: Fix out-of-bound read in resp_report_tgtpgs() · ffceb572
      Ye Bin 提交于
      mainline inclusion
      from mainline-v5.16
      commit f347c268
      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.comAcked-by: NDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      
      conflicts:
      drivers/scsi/scsi_debug.c
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      ffceb572
    • Y
      scsi: scsi_debug: Fix out-of-bound read in resp_readcap16() · a4489229
      Ye Bin 提交于
      mainline inclusion
      from mainline-v5.16
      commit 4e3ace00
      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.comAcked-by: NDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      
      conflicts:
      drivers/scsi/scsi_debug.c
      Signed-off-by: NYe Bin <yebin10@huawei.com>
      Reviewed-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      a4489229
  3. 05 3月, 2020 1 次提交
  4. 27 12月, 2019 2 次提交
  5. 31 7月, 2018 1 次提交
  6. 13 7月, 2018 1 次提交
  7. 19 6月, 2018 1 次提交
    • L
      scsi: scsi_debug: Fix memory leak on module unload · 52ab9768
      Luis Henriques 提交于
      Since commit 80c49563 ("scsi: scsi_debug: implement IMMED bit") there
      are long delays in F_SYNC_DELAY and F_SSU_DELAY.  This can cause a memory
      leak in schedule_resp(), which can be invoked while unloading the
      scsi_debug module: free_all_queued() had already freed all sd_dp and
      schedule_resp will alloc a new one, which will never get freed.  Here's the
      kmemleak report while running xfstests generic/350:
      
      unreferenced object 0xffff88007d752b00 (size 128):
        comm "rmmod", pid 26940, jiffies 4295816945 (age 7.588s)
        hex dump (first 32 bytes):
          00 2b 75 7d 00 88 ff ff 00 00 00 00 00 00 00 00  .+u}............
          00 00 00 00 00 00 00 00 8e 31 a2 34 5f 03 00 00  .........1.4_...
        backtrace:
          [<000000002abd83d0>] 0xffffffffa000705e
          [<000000004c063fda>] scsi_dispatch_cmd+0xc7/0x1a0
          [<000000000c119a00>] scsi_request_fn+0x251/0x550
          [<000000009de0c736>] __blk_run_queue+0x3f/0x60
          [<000000001c4453c8>] blk_execute_rq_nowait+0x98/0xd0
          [<00000000d17ec79f>] blk_execute_rq+0x3a/0x50
          [<00000000a7654b6e>] scsi_execute+0x113/0x250
          [<00000000fd78f7cd>] sd_sync_cache+0x95/0x160
          [<0000000024dacb14>] sd_shutdown+0x9b/0xd0
          [<00000000e9101710>] sd_remove+0x5f/0xb0
          [<00000000c43f0d63>] device_release_driver_internal+0x13c/0x1f0
          [<00000000e8ad57b6>] bus_remove_device+0xe9/0x160
          [<00000000713a7b8a>] device_del+0x120/0x320
          [<00000000e5db670c>] __scsi_remove_device+0x115/0x150
          [<00000000eccbef30>] scsi_forget_host+0x20/0x60
          [<00000000cd5a0738>] scsi_remove_host+0x6d/0x120
      
      Cc: stable@vger.kernel.org # v4.17+
      Signed-off-by: NLuis Henriques <lhenriques@suse.com>
      Acked-by: NDouglas Gilbert <dgilbert@interlog.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      52ab9768
  8. 13 6月, 2018 2 次提交
    • K
      treewide: Use array_size() in vmalloc() · 42bc47b3
      Kees Cook 提交于
      The vmalloc() function has no 2-factor argument form, so multiplication
      factors need to be wrapped in array_size(). This patch replaces cases of:
      
              vmalloc(a * b)
      
      with:
              vmalloc(array_size(a, b))
      
      as well as handling cases of:
      
              vmalloc(a * b * c)
      
      with:
      
              vmalloc(array3_size(a, b, c))
      
      This does, however, attempt to ignore constant size factors like:
      
              vmalloc(4 * 1024)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        vmalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        vmalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        vmalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        vmalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
        vmalloc(
      -	sizeof(TYPE) * (COUNT_ID)
      +	array_size(COUNT_ID, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE) * COUNT_ID
      +	array_size(COUNT_ID, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE) * (COUNT_CONST)
      +	array_size(COUNT_CONST, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE) * COUNT_CONST
      +	array_size(COUNT_CONST, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * (COUNT_ID)
      +	array_size(COUNT_ID, sizeof(THING))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * COUNT_ID
      +	array_size(COUNT_ID, sizeof(THING))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * (COUNT_CONST)
      +	array_size(COUNT_CONST, sizeof(THING))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * COUNT_CONST
      +	array_size(COUNT_CONST, sizeof(THING))
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
        vmalloc(
      -	SIZE * COUNT
      +	array_size(COUNT, SIZE)
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        vmalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        vmalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        vmalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        vmalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        vmalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        vmalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        vmalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        vmalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        vmalloc(C1 * C2 * C3, ...)
      |
        vmalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants.
      @@
      expression E1, E2;
      constant C1, C2;
      @@
      
      (
        vmalloc(C1 * C2, ...)
      |
        vmalloc(
      -	E1 * E2
      +	array_size(E1, E2)
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      42bc47b3
    • K
      treewide: kzalloc() -> kcalloc() · 6396bb22
      Kees Cook 提交于
      The kzalloc() function has a 2-factor argument form, kcalloc(). This
      patch replaces cases of:
      
              kzalloc(a * b, gfp)
      
      with:
              kcalloc(a * b, gfp)
      
      as well as handling cases of:
      
              kzalloc(a * b * c, gfp)
      
      with:
      
              kzalloc(array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              kzalloc_array(array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              kzalloc(4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      type TYPE;
      expression THING, E;
      @@
      
      (
        kzalloc(
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        kzalloc(
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        kzalloc(
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        kzalloc(
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      identifier SIZE, COUNT;
      @@
      
      - kzalloc
      + kcalloc
        (
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        kzalloc(
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        kzalloc(
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        kzalloc(
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        kzalloc(
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        kzalloc(
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        kzalloc(
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        kzalloc(sizeof(THING) * C2, ...)
      |
        kzalloc(sizeof(TYPE) * C2, ...)
      |
        kzalloc(C1 * C2 * C3, ...)
      |
        kzalloc(C1 * C2, ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - kzalloc
      + kcalloc
        (
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      6396bb22
  9. 19 4月, 2018 1 次提交
  10. 09 3月, 2018 1 次提交
  11. 16 2月, 2018 1 次提交
  12. 14 2月, 2018 5 次提交
  13. 17 1月, 2018 1 次提交
    • D
      scsi: scsi_debug: delay stress fix · 10bde980
      Douglas Gilbert 提交于
      Introduce a state enum into sdebug_defer objects to indicate which, if
      any, defer method has been used with the associated command.  Also add 2
      bools to indicate which of the defer methods has been initialized. Those
      objects are re-used but the initialization only needs to be done
      once. This simplifies command cancellation handling.
      
      Now the delay associated with a deferred response of a command cannot be
      changed (once started) by changing the delay (and ndelay) parameters in
      sysfs. Command aborts and driver shutdown are still honoured immediately
      when received.
      
      [mkp: applied by hand]
      Signed-off-by: NDouglas Gilbert <dgilbert@interlog.com>
      Reviewed-by: NBart Van Assche <bart.vanassche@wdc.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      10bde980
  14. 11 1月, 2018 5 次提交
  15. 08 12月, 2017 2 次提交
  16. 05 12月, 2017 1 次提交
  17. 01 11月, 2017 1 次提交
  18. 17 10月, 2017 1 次提交
  19. 09 9月, 2017 1 次提交
  20. 26 8月, 2017 1 次提交
  21. 05 6月, 2017 1 次提交
  22. 01 6月, 2017 1 次提交
  23. 01 2月, 2017 1 次提交
  24. 26 12月, 2016 1 次提交
    • T
      ktime: Cleanup ktime_set() usage · 8b0e1953
      Thomas Gleixner 提交于
      ktime_set(S,N) was required for the timespec storage type and is still
      useful for situations where a Seconds and Nanoseconds part of a time value
      needs to be converted. For anything where the Seconds argument is 0, this
      is pointless and can be replaced with a simple assignment.
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      8b0e1953
  25. 27 10月, 2016 1 次提交
  26. 15 9月, 2016 2 次提交
  27. 13 7月, 2016 1 次提交