Skip to contentSkip to conversation

scsi: ses: out of bound accessing in ses_enclosure_data_process

BUG jianchao.wang 4 participants 7 messages Mar 14, 2019 – Mar 19, 2019 SCSI

lore
Share & tools
lore
#0 lore raw

Dear all

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

ses_enclosure_data_process

for (i = 0; i < types; i++, type_ptr += 4) {
for (j = 0; j < type_ptr[1]; j++) {
^^^^^^^^^^^
out of bound

With some debug log, I got following,

page1 ffff88042d1aad20 len 32 types 5 type_ptr ffff88042d1aad64

Would anyone please give some suggestions on this ?

Thanks
Jianchao

#1 lore raw

Would anyone please give some suggestions ?

It looks like there somethings wrong in the read-in data,

	/* skip all the enclosure descriptors */
	for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) {
		types += type_ptr[2];
		type_ptr += type_ptr[3] + 4; ----> here
	}

Then the typr_ptr got out of bound of the buffer.

Thanks
Jianchao

Quoted 21 lines · jianchao.wang

Dear all

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

ses_enclosure_data_process

for (i = 0; i < types; i++, type_ptr += 4) {
for (j = 0; j < type_ptr[1]; j++) {
^^^^^^^^^^^
out of bound

With some debug log, I got following,

page1 ffff88042d1aad20 len 32 types 5 type_ptr ffff88042d1aad64

Would anyone please give some suggestions on this ?

Thanks
Jianchao

#2 lore raw

Add lpfc maintainer James & Dick.  Could you help take a look?

Thanks,

Junxiao.

Quoted 37 lines · jianchao.wang

Would anyone please give some suggestions ?

It looks like there somethings wrong in the read-in data,

	/* skip all the enclosure descriptors */
	for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) {
		types += type_ptr[2];
		type_ptr += type_ptr[3] + 4; ----> here
	}

Then the typr_ptr got out of bound of the buffer.

Thanks
Jianchao

Quoted 21 lines · jianchao.wang

Dear all

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

ses_enclosure_data_process

for (i = 0; i < types; i++, type_ptr += 4) {
   for (j = 0; j < type_ptr[1]; j++) {
                    ^^^^^^^^^^^
                    out of bound

With some debug log, I got following,

page1 ffff88042d1aad20 len 32 types 5 type_ptr ffff88042d1aad64

Would anyone please give some suggestions on this ?

Thanks
Jianchao

#3 lore raw
In reply to jianchao.wang

Jianchao,

Quoted 3 lines

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

Please provide the output of:

# sg_ses -p 1 /dev/sgN
# sg_ses -p 7 /dev/sgN

for the enclosure device in question.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw

Hi Martin

Thanks for your kindly response.

Quoted 7 lines · Martin K. Petersen

Jianchao,

Quoted 3 lines

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

Quoted 6 lines

Please provide the output of:

# sg_ses -p 1 /dev/sgN
# sg_ses -p 7 /dev/sgN

for the enclosure device in question.

OK, I will send this to customer.
And share the result here after get feedback.

Thanks
Jianchao

#5 lore raw
In reply to Martin K. Petersen
Quoted 6 lines · Martin K. Petersen

Jianchao,

Quoted 3 lines

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

Quoted 7 lines

Please provide the output of:

# sg_ses -p 1 /dev/sgN
# sg_ses -p 7 /dev/sgN

for the enclosure device in question.

The ses driver is allocating kernel buffers based upon the size reported by RECEIVE DIAGNOSTIC commands, and is iterating through them based on sizes in the individual descriptors. It appears to be vulnerable to incorrect data from the device causing out-of-bounds memory access, because the for() test does not prevent the use of the pointer in subsequent code, e.g.:

        for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) {
                types += type_ptr[2];
                type_ptr += type_ptr[3] + 4;
        }

        ses_dev->page1_types = type_ptr;
        ses_dev->page1_num_types = types;

Whether or not this is the current problem, it's wrong.

-Ewan

#6 lore raw
Quoted 30 lines · Ewan D. Milne
Quoted 6 lines · Martin K. Petersen

Jianchao,

Quoted 3 lines

When our customer probe the lpfc devices, they encountered odd memory corruption issues, and we get 'out of bound' access warning at following position after open KASAN

Quoted 7 lines

Please provide the output of:

# sg_ses -p 1 /dev/sgN
# sg_ses -p 7 /dev/sgN

for the enclosure device in question.

The ses driver is allocating kernel buffers based upon the size reported by RECEIVE DIAGNOSTIC commands, and is iterating through them based on sizes in the individual descriptors. It appears to be vulnerable to incorrect data from the device causing out-of-bounds memory access, because the for() test does not prevent the use of the pointer in subsequent code, e.g.:

        for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) {
                types += type_ptr[2];
                type_ptr += type_ptr[3] + 4;
        }

        ses_dev->page1_types = type_ptr;
        ses_dev->page1_num_types = types;
Quoted 2 lines

Whether or not this is the current problem, it's wrong.

Yes, I definitely agree with this.
There should be some change here.

Thanks
Jianchao