1. 27 Sep, 2022 6 commits
    • Eli Cohen's avatar
      vdpa/mlx5: Fix MQ to support non power of two num queues · a43ae805
      Eli Cohen authored
      RQT objects require that a power of two value be configured for both
      rqt_max_size and rqt_actual size.
      
      For create_rqt, make sure to round up to the power of two the value of
      given by the user who created the vdpa device and given by
      ndev->rqt_size. The actual size is also rounded up to the power of two
      using the current number of VQs given by ndev->cur_num_vqs.
      
      Same goes with modify_rqt where we need to make sure act size is power
      of two based on the new number of QPs.
      
      Without this patch, attempt to create a device with non power of two QPs
      would result in error from firmware.
      
      Fixes: 52893733 ("vdpa/mlx5: Add multiqueue support")
      Signed-off-by: default avatarEli Cohen <elic@nvidia.com>
      Message-Id: <20220912125019.833708-1-elic@nvidia.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      a43ae805
    • Maxime Coquelin's avatar
      vduse: prevent uninitialized memory accesses · 46f8a292
      Maxime Coquelin authored
      If the VDUSE application provides a smaller config space
      than the driver expects, the driver may use uninitialized
      memory from the stack.
      
      This patch prevents it by initializing the buffer passed by
      the driver to store the config value.
      
      This fix addresses CVE-2022-2308.
      
      Cc: stable@vger.kernel.org # v5.15+
      Fixes: c8a6153b ("vduse: Introduce VDUSE - vDPA Device in Userspace")
      Reviewed-by: default avatarXie Yongji <xieyongji@bytedance.com>
      Acked-by: default avatarJason Wang <jasowang@redhat.com>
      Signed-off-by: default avatarMaxime Coquelin <maxime.coquelin@redhat.com>
      Message-Id: <20220831154923.97809-1-maxime.coquelin@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
      46f8a292
    • Suwan Kim's avatar
      virtio-blk: Fix WARN_ON_ONCE in virtio_queue_rq() · 37fafe6b
      Suwan Kim authored
      If a request fails at virtio_queue_rqs(), it is inserted to requeue_list
      and passed to virtio_queue_rq(). Then blk_mq_start_request() can be called
      again at virtio_queue_rq() and trigger WARN_ON_ONCE like below trace because
      request state was already set to MQ_RQ_IN_FLIGHT in virtio_queue_rqs()
      despite the failure.
      
      [    1.890468] ------------[ cut here ]------------
      [    1.890776] WARNING: CPU: 2 PID: 122 at block/blk-mq.c:1143
      blk_mq_start_request+0x8a/0xe0
      [    1.891045] Modules linked in:
      [    1.891250] CPU: 2 PID: 122 Comm: journal-offline Not tainted 5.19.0+ #44
      [    1.891504] Hardware name: ChromiumOS crosvm, BIOS 0
      [    1.891739] RIP: 0010:blk_mq_start_request+0x8a/0xe0
      [    1.891961] Code: 12 80 74 22 48 8b 4b 10 8b 89 64 01 00 00 8b 53
      20 83 fa ff 75 08 ba 00 00 00 80 0b 53 24 c1 e1 10 09 d1 89 48 34 5b
      41 5e c3 <0f> 0b eb b8 65 8b 05 2b 39 b6 7e 89 c0 48 0f a3 05 39 77 5b
      01 0f
      [    1.892443] RSP: 0018:ffffc900002777b0 EFLAGS: 00010202
      [    1.892673] RAX: 0000000000000000 RBX: ffff888004bc0000 RCX: 0000000000000000
      [    1.892952] RDX: 0000000000000000 RSI: ffff888003d7c200 RDI: ffff888004bc0000
      [    1.893228] RBP: 0000000000000000 R08: 0000000000000001 R09: ffff888004bc0100
      [    1.893506] R10: ffffffffffffffff R11: ffffffff8185ca10 R12: ffff888004bc0000
      [    1.893797] R13: ffffc90000277900 R14: ffff888004ab2340 R15: ffff888003d86e00
      [    1.894060] FS:  00007ffa143a4640(0000) GS:ffff88807dd00000(0000)
      knlGS:0000000000000000
      [    1.894412] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [    1.894682] CR2: 00005648577d9088 CR3: 00000000053da004 CR4: 0000000000170ee0
      [    1.894953] Call Trace:
      [    1.895139]  <TASK>
      [    1.895303]  virtblk_prep_rq+0x1e5/0x280
      [    1.895509]  virtio_queue_rq+0x5c/0x310
      [    1.895710]  ? virtqueue_add_sgs+0x95/0xb0
      [    1.895905]  ? _raw_spin_unlock_irqrestore+0x16/0x30
      [    1.896133]  ? virtio_queue_rqs+0x340/0x390
      [    1.896453]  ? sbitmap_get+0xfa/0x220
      [    1.896678]  __blk_mq_issue_directly+0x41/0x180
      [    1.896906]  blk_mq_plug_issue_direct+0xd8/0x2c0
      [    1.897115]  blk_mq_flush_plug_list+0x115/0x180
      [    1.897342]  blk_add_rq_to_plug+0x51/0x130
      [    1.897543]  blk_mq_submit_bio+0x3a1/0x570
      [    1.897750]  submit_bio_noacct_nocheck+0x418/0x520
      [    1.897985]  ? submit_bio_noacct+0x1e/0x260
      [    1.897989]  ext4_bio_write_page+0x222/0x420
      [    1.898000]  mpage_process_page_bufs+0x178/0x1c0
      [    1.899451]  mpage_prepare_extent_to_map+0x2d2/0x440
      [    1.899603]  ext4_writepages+0x495/0x1020
      [    1.899733]  do_writepages+0xcb/0x220
      [    1.899871]  ? __seccomp_filter+0x171/0x7e0
      [    1.900006]  file_write_and_wait_range+0xcd/0xf0
      [    1.900167]  ext4_sync_file+0x72/0x320
      [    1.900308]  __x64_sys_fsync+0x66/0xa0
      [    1.900449]  do_syscall_64+0x31/0x50
      [    1.900595]  entry_SYSCALL_64_after_hwframe+0x63/0xcd
      [    1.900747] RIP: 0033:0x7ffa16ec96ea
      [    1.900883] Code: b8 4a 00 00 00 0f 05 48 3d 00 f0 ff ff 77 41 c3
      48 83 ec 18 89 7c 24 0c e8 e3 02 f8 ff 8b 7c 24 0c 89 c2 b8 4a 00 00
      00 0f 05 <48> 3d 00 f0 ff ff 77 36 89 d7 89 44 24 0c e8 43 03 f8 ff 8b
      44 24
      [    1.901302] RSP: 002b:00007ffa143a3ac0 EFLAGS: 00000293 ORIG_RAX:
      000000000000004a
      [    1.901499] RAX: ffffffffffffffda RBX: 0000560277ec6fe0 RCX: 00007ffa16ec96ea
      [    1.901696] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000016
      [    1.901884] RBP: 0000560277ec5910 R08: 0000000000000000 R09: 00007ffa143a4640
      [    1.902082] R10: 00007ffa16e4d39e R11: 0000000000000293 R12: 00005602773f59e0
      [    1.902459] R13: 0000000000000000 R14: 00007fffbfc007ff R15: 00007ffa13ba4000
      [    1.902763]  </TASK>
      [    1.902877] ---[ end trace 0000000000000000 ]---
      
      To avoid calling blk_mq_start_request() twice, This patch moves the
      execution of blk_mq_start_request() to the end of virtblk_prep_rq().
      And instead of requeuing failed request to plug list in the error path of
      virtblk_add_req_batch(), it uses blk_mq_requeue_request() to change failed
      request state to MQ_RQ_IDLE. Then virtblk can safely handle the request
      on the next trial.
      
      Fixes: 0e9911fa ("virtio-blk: support mq_ops->queue_rqs()")
      Reported-by: default avatarAlexandre Courbot <acourbot@chromium.org>
      Tested-by: default avatarAlexandre Courbot <acourbot@chromium.org>
      Signed-off-by: default avatarSuwan Kim <suwan.kim027@gmail.com>
      Message-Id: <20220830150153.12627-1-suwan.kim027@gmail.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Acked-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarPankaj Raghav <p.raghav@samsung.com>
      37fafe6b
    • Xuan Zhuo's avatar
      virtio_test: fixup for vq reset · dbe449d8
      Xuan Zhuo authored
      Fix virtio test compilation failure caused by vq reset.
      
      ../../drivers/virtio/virtio_ring.c: In function ‘vring_create_virtqueue_packed’:
      ../../drivers/virtio/virtio_ring.c:1999:8: error: ‘struct virtqueue’ has no member named ‘reset’
       1999 |  vq->vq.reset = false;
            |        ^
      ../../drivers/virtio/virtio_ring.c: In function ‘__vring_new_virtqueue’:
      ../../drivers/virtio/virtio_ring.c:2493:8: error: ‘struct virtqueue’ has no member named ‘reset’
       2493 |  vq->vq.reset = false;
            |        ^
      ../../drivers/virtio/virtio_ring.c: In function ‘virtqueue_resize’:
      ../../drivers/virtio/virtio_ring.c:2587:18: error: ‘struct virtqueue’ has no member named ‘num_max’
       2587 |  if (num > vq->vq.num_max)
            |                  ^
      ../../drivers/virtio/virtio_ring.c:2596:11: error: ‘struct virtio_device’ has no member named ‘config’
       2596 |  if (!vdev->config->disable_vq_and_reset)
            |           ^~
      ../../drivers/virtio/virtio_ring.c:2599:11: error: ‘struct virtio_device’ has no member named ‘config’
       2599 |  if (!vdev->config->enable_vq_after_reset)
            |           ^~
      ../../drivers/virtio/virtio_ring.c:2602:12: error: ‘struct virtio_device’ has no member named ‘config’
       2602 |  err = vdev->config->disable_vq_and_reset(_vq);
            |            ^~
      ../../drivers/virtio/virtio_ring.c:2614:10: error: ‘struct virtio_device’ has no member named ‘config’
       2614 |  if (vdev->config->enable_vq_after_reset(_vq))
            |          ^~
      make: *** [<builtin>: virtio_ring.o] Error 1
      Signed-off-by: default avatarXuan Zhuo <xuanzhuo@linux.alibaba.com>
      Message-Id: <20220830110549.103168-1-xuanzhuo@linux.alibaba.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      dbe449d8
    • lei he's avatar
      virtio-crypto: fix memory-leak · 1bedcf22
      lei he authored
      Fix memory-leak for virtio-crypto akcipher request, this problem is
      introduced by 59ca6c93(virtio-crypto: implement RSA algorithm).
      The leak can be reproduced and tested with the following script
      inside virtual machine:
      
      #!/bin/bash
      
      LOOP_TIMES=10000
      
      # required module: pkcs8_key_parser, virtio_crypto
      modprobe pkcs8_key_parser # if CONFIG_PKCS8_PRIVATE_KEY_PARSER=m
      modprobe virtio_crypto # if CONFIG_CRYPTO_DEV_VIRTIO=m
      rm -rf /tmp/data
      dd if=/dev/random of=/tmp/data count=1 bs=230
      
      # generate private key and self-signed cert
      openssl req -nodes -x509 -newkey rsa:2048 -keyout key.pem \
      		-outform der -out cert.der  \
      		-subj "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=always.com/emailAddress=yy@always.com"
      # convert private key from pem to der
      openssl pkcs8 -in key.pem -topk8 -nocrypt -outform DER -out key.der
      
      # add key
      PRIV_KEY_ID=`cat key.der | keyctl padd asymmetric test_priv_key @s`
      echo "priv key id = "$PRIV_KEY_ID
      PUB_KEY_ID=`cat cert.der | keyctl padd asymmetric test_pub_key @s`
      echo "pub key id = "$PUB_KEY_ID
      
      # query key
      keyctl pkey_query $PRIV_KEY_ID 0
      keyctl pkey_query $PUB_KEY_ID 0
      
      # here we only run pkey_encrypt becasuse it is the fastest interface
      function bench_pub() {
      	keyctl pkey_encrypt $PUB_KEY_ID 0 /tmp/data enc=pkcs1 >/tmp/enc.pub
      }
      
      # do bench_pub in loop to obtain the memory leak
      for (( i = 0; i < ${LOOP_TIMES}; ++i )); do
      	bench_pub
      done
      Signed-off-by: default avatarlei he <helei.sig11@bytedance.com>
      Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: default avatarGonglei <arei.gonglei@huawei.com>
      Message-Id: <20220919075158.3625-1-helei.sig11@bytedance.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      1bedcf22
    • Angus Chen's avatar
      vdpa/ifcvf: fix the calculation of queuepair · db5db1a0
      Angus Chen authored
      The q_pair_id to address a queue pair in the lm bar should be
      calculated by queue_id / 2 rather than queue_id / nr_vring.
      
      Fixes: 2ddae773 ("vDPA/ifcvf: detect and use the onboard number of queues directly")
      Signed-off-by: default avatarAngus Chen <angus.chen@jaguarmicro.com>
      Reviewed-by: default avatarJason Wang <jasowang@redhat.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Acked-by: default avatarZhu Lingshan <lingshan.zhu@intel.com>
      Message-Id: <20220923091013.191-1-angus.chen@jaguarmicro.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      db5db1a0
  2. 25 Sep, 2022 8 commits
  3. 24 Sep, 2022 10 commits
  4. 23 Sep, 2022 16 commits