lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 2 Feb 2023 14:43:29 +0800
From:   Zheng Hacker <hackerzheng666@...il.com>
To:     Zheng Wang <zyytlz.wz@....com>
Cc:     mst@...hat.com, jasowang@...hat.com, pbonzini@...hat.com,
        stefanha@...hat.com, jejb@...ux.ibm.com,
        martin.petersen@...cle.com,
        virtualization@...ts.linux-foundation.org,
        linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
        security@...nel.org, alex000young@...il.com
Subject: Re: [PATCH v2] scsi: virtio_scsi: Fix poential NULL pointer
 dereference in virtscsi_rescan_hotunplug

After writing the patch, I found there is an old patch about this issue.
The link is : https://lore.kernel.org/all/ecb2f3c6-af8c-dd43-1dcf-0b5e8a9d8848@redhat.com/

Best regards,
Zheng Wang

Zheng Wang <zyytlz.wz@....com> 于2023年2月2日周四 14:42写道:
>
> There is no check about the return value of kmalloc in
> virtscsi_rescan_hotunplug. Add the check to avoid use
> of null pointer 'inq_result' in case of the failure
> of kmalloc.
>
> Signed-off-by: Zheng Wang <zyytlz.wz@....com>
> ---
> v2:
> - add kfree to avoid memory leak
> ---
>  drivers/scsi/virtio_scsi.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index d07d24c06b54..a66d8815d738 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -330,7 +330,7 @@ static void virtscsi_handle_param_change(struct virtio_scsi *vscsi,
>         scsi_device_put(sdev);
>  }
>
> -static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
> +static int virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
>  {
>         struct scsi_device *sdev;
>         struct Scsi_Host *shost = virtio_scsi_host(vscsi->vdev);
> @@ -338,6 +338,11 @@ static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
>         int result, inquiry_len, inq_result_len = 256;
>         char *inq_result = kmalloc(inq_result_len, GFP_KERNEL);
>
> +       if (!inq_result) {
> +               kfree(inq_result);
> +               return -ENOMEM;
> +       }
> +
>         shost_for_each_device(sdev, shost) {
>                 inquiry_len = sdev->inquiry_len ? sdev->inquiry_len : 36;
>
> @@ -366,6 +371,7 @@ static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
>         }
>
>         kfree(inq_result);
> +       return 0;
>  }
>
>  static void virtscsi_handle_event(struct work_struct *work)
> @@ -374,12 +380,15 @@ static void virtscsi_handle_event(struct work_struct *work)
>                 container_of(work, struct virtio_scsi_event_node, work);
>         struct virtio_scsi *vscsi = event_node->vscsi;
>         struct virtio_scsi_event *event = &event_node->event;
> +       int ret = 0;
>
>         if (event->event &
>             cpu_to_virtio32(vscsi->vdev, VIRTIO_SCSI_T_EVENTS_MISSED)) {
>                 event->event &= ~cpu_to_virtio32(vscsi->vdev,
>                                                    VIRTIO_SCSI_T_EVENTS_MISSED);
> -               virtscsi_rescan_hotunplug(vscsi);
> +               ret = virtscsi_rescan_hotunplug(vscsi);
> +               if (ret)
> +                       return;
>                 scsi_scan_host(virtio_scsi_host(vscsi->vdev));
>         }
>
> --
> 2.25.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ