Skip to contentSkip to conversation

libosd: Fix NULL dereference BUG when target is none OSD conformant

PATCH In review Boaz Harrosh 1 participant 5 messages Feb 8, 2009 – Feb 16, 2009 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libosd: Fix NULL dereference BUG when target is none OSD conformant

Very old OSC's Target had a BUG in the Get/Set attributes where it was looking in the wrong places for attribute lists length. If used with the open-osd initiator, the initiator would dereference a NULL pointer when retrieving system_information attributes.

Checks are added if retrieval of each attributes was successful before accessing them.

---
 drivers/scsi/osd/osd_initiator.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/scsi/osd/osd_initiator.c +7 -4
index eeaec3e..1696130 100644
@@ -131,7 +131,7 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("PRODUCT_REVISION_LEVEL [%u]\n",
-		get_unaligned_be32(pFirst));
+		pFirst ? get_unaligned_be32(pFirst) : ~0U);
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("PRODUCT_SERIAL_NUMBER  [%s]\n",
@@ -143,15 +143,18 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("TOTAL_CAPACITY         [0x%llx]\n",
-		_LLU(get_unaligned_be64(pFirst)));
+		pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("USED_CAPACITY          [0x%llx]\n",
-		_LLU(get_unaligned_be64(pFirst)));
+		pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("NUMBER_OF_PARTITIONS   [%llu]\n",
-		_LLU(get_unaligned_be64(pFirst)));
+		pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
+
+	if (a >= nelem)
+		goto out;
 
 	/* FIXME: Where are the time utilities */
 	pFirst = get_attrs[a++].val_ptr;
Signature · 1 line
1.6.0.1
#1 lore raw
Quoted 10 lines · Boaz Harrosh

Very old OSC's Target had a BUG in the Get/Set attributes where it was looking in the wrong places for attribute lists length. If used with the open-osd initiator, the initiator would dereference a NULL pointer when retrieving system_information attributes.

Checks are added if retrieval of each attributes was successful before accessing them.

---

Lars I will need your Tested-by: ... here
I did not manage to run with your version of the target. It might crash farther on now.

(Or if you can identify where on git://git.open-osd.org/osc-osd is the point that best matches your version and I can test it here)

Thanks in advance
Boaz

#2 lore raw
Quoted 9 lines · Boaz Harrosh
Quoted 8 lines · Boaz Harrosh

Very old OSC's Target had a BUG in the Get/Set attributes where it was looking in the wrong places for attribute lists length. If used with the open-osd initiator, the initiator would dereference a NULL pointer when retrieving system_information attributes.

Checks are added if retrieval of each attributes was successful before accessing them.

Quoted 7 lines
Quoted 2 lines

---

Lars I will need your Tested-by: ... here
I did not manage to run with your version of the target. It might crash farther on now.

OK That patch will not work for you. I had another one in Q before that one. I've rebased so it will apply over current scsi-misc.

Sent as reply to first patch.

Sorry for the noise

Boaz

#3 lore raw

PATCH 1/1 libosd: Fix NULL dereference BUG when target is not OSD conformant

In reply to Boaz Harrosh

Very old OSC's Target had a BUG in the Get/Set attributes where it was looking in the wrong places for attribute lists length. If used with the open-osd initiator, the initiator would dereference a NULL pointer when retrieving system_information attributes.

Checks are added that retrieval of each attribute is successful before accessing its value.

---
 drivers/scsi/osd/osd_initiator.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/scsi/osd/osd_initiator.c +7 -4
index 0bbbf27..552f58b 100644
@@ -131,7 +131,7 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("OSD_ATTR_RI_PRODUCT_REVISION_LEVEL [%u]\n",
-		get_unaligned_be32(pFirst));
+		pFirst ? get_unaligned_be32(pFirst) : ~0U);
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("OSD_ATTR_RI_PRODUCT_SERIAL_NUMBER [%s]\n",
@@ -143,15 +143,18 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("OSD_ATTR_RI_TOTAL_CAPACITY [0x%llx]\n",
-		_LLU(get_unaligned_be64(pFirst)));
+		pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("OSD_ATTR_RI_USED_CAPACITY [0x%llx]\n",
-		_LLU(get_unaligned_be64(pFirst)));
+		pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
 
 	pFirst = get_attrs[a++].val_ptr;
 	OSD_INFO("OSD_ATTR_RI_NUMBER_OF_PARTITIONS [%llu]\n",
-		_LLU(get_unaligned_be64(pFirst)));
+		pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
+
+	if (a >= nelem)
+		goto out;
 
 	/* FIXME: Where are the time utilities */
 	pFirst = get_attrs[a++].val_ptr;
Signature · 1 line
1.6.0.1
author Tested-by Fuerst Lars on v1 1/1
#4 lore raw

Re: [osd-dev] [PATCH version 2] libosd: Fix NULL dereference BUG when target is not OSD conformant

Quoted 9 lines · Boaz Harrosh

Very old OSC's Target had a BUG in the Get/Set attributes where it was looking in the wrong places for attribute lists length. If used with the open-osd initiator, the initiator would dereference a NULL pointer when retrieving system_information attributes.

Checks are added that retrieval of each attribute is successful before accessing its value.

James please submit this patch on top of current scsi-misc for a fix of a serious BUG. It should be submitted together with the osd patches for 2.6.30.

Thanks in advance
Boaz