Re: [PATCH] scsi: virtio_scsi: Fix a NULL pointer dereference in virtscsi_rescan_hotunplug()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/30/21 18:19, Zhou Qingyang wrote:
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -337,7 +337,11 @@ static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
  	unsigned char scsi_cmd[MAX_COMMAND_SIZE];
  	int result, inquiry_len, inq_result_len = 256;
  	char *inq_result = kmalloc(inq_result_len, GFP_KERNEL);
-
+	if (!inq_result) {
+		pr_err("%s:no enough memory for inq_result\n",
+			__func__);
+		return;
+	}
  	shost_for_each_device(sdev, shost) {
  		inquiry_len = sdev->inquiry_len ? sdev->inquiry_len : 36;

In practice this will never happen, since the kmalloc is very small, so I think it's easier to just return early without a printk. On the other hand, if the out-of-memory really could happen, this should be a pr_err_ratelimited.

Paolo



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux