1. 12 1月, 2019 1 次提交
  2. 19 12月, 2018 1 次提交
  3. 13 12月, 2018 1 次提交
  4. 08 12月, 2018 3 次提交
  5. 09 11月, 2018 1 次提交
  6. 08 11月, 2018 3 次提交
  7. 06 11月, 2018 1 次提交
  8. 24 10月, 2018 1 次提交
  9. 03 10月, 2018 1 次提交
  10. 28 9月, 2018 2 次提交
  11. 12 9月, 2018 12 次提交
  12. 03 8月, 2018 5 次提交
  13. 20 7月, 2018 3 次提交
  14. 11 7月, 2018 1 次提交
    • H
      scsi: qla2xxx: Fix kernel crash due to late workqueue allocation · d48cc67c
      himanshu.madhani@cavium.com 提交于
      This patch fixes crash for FCoE adapter. Once driver initialization is
      complete, firmware will start posting Asynchronous Event, However driver
      has not yet allocated workqueue to process and queue up work.  This delay
      of allocating workqueue results into NULL pointer access.
      
      The following stack trace is seen:
      
      [   24.577259] BUG: unable to handle kernel NULL pointer dereference at 0000000000000102
      [   24.623133] PGD 0 P4D 0
      [   24.636760] Oops: 0000 [#1] SMP NOPTI
      [   24.656942] Modules linked in: i2c_algo_bit drm_kms_helper sr_mod(+) syscopyarea sysfillrect sysimgblt cdrom fb_sys_fops ata_generic ttm pata_acpi sd_mod ahci pata_atiixp sfc(+) qla2xxx(+) libahci drm qla4xxx(+) nvme_fc hpsa mdio libiscsi qlcnic(+) nvme_fabrics scsi_transport_sas serio_raw mtd crc32c_intel libata nvme_core i2c_core scsi_transport_iscsi tg3 scsi_transport_fc bnx2 iscsi_boot_sysfs dm_multipath dm_mirror dm_region_hash dm_log dm_mod
      [   24.887449] CPU: 0 PID: 177 Comm: kworker/0:3 Not tainted 4.17.0-rc6 #1
      [   24.925119] Hardware name: HP ProLiant DL385 G7, BIOS A18 08/15/2012
      [   24.962106] Workqueue: events work_for_cpu_fn
      [   24.987098] RIP: 0010:__queue_work+0x1f/0x3a0
      [   25.011672] RSP: 0018:ffff992642ceba10 EFLAGS: 00010082
      [   25.042116] RAX: 0000000000000082 RBX: 0000000000000082 RCX: 0000000000000000
      [   25.083293] RDX: ffff8cf9abc6d7d0 RSI: 0000000000000000 RDI: 0000000000002000
      [   25.123094] RBP: 0000000000000000 R08: 0000000000025a40 R09: ffff8cf9aade2880
      [   25.164087] R10: 0000000000000000 R11: ffff992642ceb6f0 R12: ffff8cf9abc6d7d0
      [   25.202280] R13: 0000000000002000 R14: ffff8cf9abc6d7b8 R15: 0000000000002000
      [   25.242050] FS:  0000000000000000(0000) f9b5c00000(0000) knlGS:0000000000000000
      [   25.977565] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   26.010457] CR2: 0000000000000102 CR3: 000000030760a000 CR4: 00000000000406f0
      [   26.051048] Call Trace:
      [   26.063572]  ? __switch_to_asm+0x34/0x70
      [   26.086079]  queue_work_on+0x24/0x40
      [   26.107090]  qla2x00_post_work+0x81/0xb0 [qla2xxx]
      [   26.133356]  qla2x00_async_event+0x1ad/0x1a20 [qla2xxx]
      [   26.164075]  ? lock_timer_base+0x67/0x80
      [   26.186420]  ? try_to_del_timer_sync+0x4d/0x80
      [   26.212284]  ? del_timer_sync+0x35/0x40
      [   26.234080]  ? schedule_timeout+0x165/0x2f0
      [   26.259575]  qla82xx_poll+0x13e/0x180 [qla2xxx]
      [   26.285740]  qla2x00_mailbox_command+0x74b/0xf50 [qla2xxx]
      [   26.319040]  qla82xx_set_driver_version+0x13b/0x1c0 [qla2xxx]
      [   26.352108]  ? qla2x00_init_rings+0x206/0x3f0 [qla2xxx]
      [   26.381733]  qla2x00_initialize_adapter+0x35c/0x7f0 [qla2xxx]
      [   26.413240]  qla2x00_probe_one+0x1479/0x2390 [qla2xxx]
      [   26.442055]  local_pci_probe+0x3f/0xa0
      [   26.463108]  work_for_cpu_fn+0x10/0x20
      [   26.483295]  process_one_work+0x152/0x350
      [   26.505730]  worker_thread+0x1cf/0x3e0
      [   26.527090]  kthread+0xf5/0x130
      [   26.545085]  ? max_active_store+0x80/0x80
      [   26.568085]  ? kthread_bind+0x10/0x10
      [   26.589533]  ret_from_fork+0x22/0x40
      [   26.610192] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 41 57 41 89 ff 41 56 41 55 41 89 fd 41 54 49 89 d4 55 48 89 f5 53 48 83 ec 0 86 02 01 00 00 01 0f 85 80 02 00 00 49 c7 c6 c0 ec 01 00 41
      [   27.308540] RIP: __queue_work+0x1f/0x3a0 RSP: ffff992642ceba10
      [   27.341591] CR2: 0000000000000102
      [   27.360208] ---[ end trace 01b7b7ae2c005cf3 ]---
      
      Cc: <stable@vger.kernel.org> # v4.17+
      Fixes: 9b3e0f4d ("scsi: qla2xxx: Move work element processing out of DPC thread"
      Reported-by: NLi Wang <liwang@redhat.com>
      Tested-by: NLi Wang <liwang@redhat.com>
      Signed-off-by: NHimanshu Madhani <himanshu.madhani@cavium.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      d48cc67c
  15. 13 6月, 2018 1 次提交
    • 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
  16. 08 5月, 2018 1 次提交
  17. 10 4月, 2018 1 次提交
    • B
      scsi: qla2xxx: Fix small memory leak in qla2x00_probe_one on probe failure · 6d634067
      Bill Kuzeja 提交于
      The code that fixes the crashes in the following commit introduced a small
      memory leak:
      
      commit 6a2cf8d3 ("scsi: qla2xxx: Fix crashes in qla2x00_probe_one on probe failure")
      
      Fixing this requires a bit of reworking, which I've explained. Also provide
      some code cleanup.
      
      There is a small window in qla2x00_probe_one where if qla2x00_alloc_queues
      fails, we end up never freeing req and rsp and leak 0xc0 and 0xc8 bytes
      respectively (the sizes of req and rsp).
      
      I originally put in checks to test for this condition which were based on
      the incorrect assumption that if ha->rsp_q_map and ha->req_q_map were
      allocated, then rsp and req were allocated as well. This is incorrect.
      There is a window between these allocations:
      
             ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
                      goto probe_hw_failed;
      
      [if successful, both rsp and req allocated]
      
             base_vha = qla2x00_create_host(sht, ha);
                      goto probe_hw_failed;
      
             ret = qla2x00_request_irqs(ha, rsp);
                      goto probe_failed;
      
             if (qla2x00_alloc_queues(ha, req, rsp)) {
                      goto probe_failed;
      
      [if successful, now ha->rsp_q_map and ha->req_q_map allocated]
      
      To simplify this, we should just set req and rsp to NULL after we free
      them. Sounds simple enough? The problem is that req and rsp are pointers
      defined in the qla2x00_probe_one and they are not always passed by reference
      to the routines that free them.
      
      Here are paths which can free req and rsp:
      
      PATH 1:
      qla2x00_probe_one
         ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
         [req and rsp are passed by reference, but if this fails, we currently
          do not NULL out req and rsp. Easily fixed]
      
      PATH 2:
      qla2x00_probe_one
         failing in qla2x00_request_irqs or qla2x00_alloc_queues
            probe_failed:
               qla2x00_free_device(base_vha);
                  qla2x00_free_req_que(ha, req)
                  qla2x00_free_rsp_que(ha, rsp)
      
      PATH 3:
      qla2x00_probe_one:
         failing in qla2x00_mem_alloc or qla2x00_create_host
            probe_hw_failed:
               qla2x00_free_req_que(ha, req)
               qla2x00_free_rsp_que(ha, rsp)
      
      PATH 1: This should currently work, but it doesn't because rsp and rsp are
      not set to NULL in qla2x00_mem_alloc. Easily remedied.
      
      PATH 2: req and rsp aren't passed in at all to qla2x00_free_device but are
      derived from ha->req_q_map[0] and ha->rsp_q_map[0]. These are only set up if
      qla2x00_alloc_queues succeeds.
      
      In qla2x00_free_queues, we are protected from crashing if these don't exist
      because req_qid_map and rsp_qid_map are only set on their allocation. We are
      guarded in this way:
      
              for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
                      if (!test_bit(cnt, ha->req_qid_map))
                              continue;
      
      PATH 3: This works. We haven't freed req or rsp yet (or they were never
      allocated if qla2x00_mem_alloc failed), so we'll attempt to free them here.
      
      To summarize, there are a few small changes to make this work correctly and
      (and for some cleanup):
      
      1) (For PATH 1) Set *rsp and *req to NULL in case of failure in
      qla2x00_mem_alloc so these are correctly set to NULL back in
      qla2x00_probe_one
      
      2) After jumping to probe_failed: and calling qla2x00_free_device,
      explicitly set rsp and req to NULL so further calls with these pointers do
      not crash, i.e. the free queue calls in the probe_hw_failed section we fall
      through to.
      
      3) Fix return code check in the call to qla2x00_alloc_queues. We currently
      drop the return code on the floor. The probe fails but the caller of the
      probe doesn't have an error code, so it attaches to pci. This can result in
      a crash on module shutdown.
      
      4) Remove unnecessary NULL checks in qla2x00_free_req_que,
      qla2x00_free_rsp_que, and the egregious NULL checks before kfrees and vfrees
      in qla2x00_mem_free.
      
      I tested this out running a scenario where the card breaks at various times
      during initialization. I made sure I forced every error exit path in
      qla2x00_probe_one.
      
      Cc: <stable@vger.kernel.org> # v4.16
      Fixes: 6a2cf8d3 ("scsi: qla2xxx: Fix crashes in qla2x00_probe_one on probe failure")
      Signed-off-by: NBill Kuzeja <william.kuzeja@stratus.com>
      Acked-by: NHimanshu Madhani <himanshu.madhani@cavium.com>
      Signed-off-by: NMartin K. Petersen <martin.petersen@oracle.com>
      6d634067
  18. 28 3月, 2018 1 次提交