Skip to contentSkip to conversation

libata: zpodd: Fix small read overflow in zpodd_get_mech_type()

PATCH Superseded Kees Cook 2 participants 3 messages Jul 20, 2019 – Jul 22, 2019 libata

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 libata: zpodd: Fix small read overflow in zpodd_get_mech_type()

Much like commit 18c9a99bce2a ("libata: zpodd: small read overflow in eject_tray()"), this fixes a cdb[] buffer length, this time in zpodd_get_mech_type():

We read from the cdb[] buffer in ata_exec_internal_sg(). It has to be ATAPI_CDB_LEN (16) bytes long, but this buffer is only 12 bytes.

The KASAN report was:

BUG: KASAN: global-out-of-bounds in ata_exec_internal_sg+0x50f/0xc70
Read of size 16 at addr ffffffff91f41f80 by task scsi_eh_1/149
...
The buggy address belongs to the variable:
 cdb.48319+0x0/0x40
Fixes afe759511808c ("libata: identify and init ZPODD devices")
---
 drivers/ata/libata-zpodd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libata-zpodd.c +1 -1
index 173e6f2dd9af..eefda51f97d3 100644
@@ -56,7 +56,7 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
 	unsigned int ret;
 	struct rm_feature_desc *desc;
 	struct ata_taskfile tf;
-	static const char cdb[] = {  GPCMD_GET_CONFIGURATION,
+	static const char cdb[ATAPI_CDB_LEN] = {  GPCMD_GET_CONFIGURATION,
 			2,      /* only 1 feature descriptor requested */
 			0, 3,   /* 3, removable medium feature */
 			0, 0, 0,/* reserved */
Signature · 5 lines
2.17.1


-- 
Kees Cook
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Kees Cook

Much like commit 18c9a99bce2a ("libata: zpodd: small read overflow in eject_tray()"), this fixes a cdb[] buffer length, this time in zpodd_get_mech_type():

We read from the cdb[] buffer in ata_exec_internal_sg(). It has to be ATAPI_CDB_LEN (16) bytes long, but this buffer is only 12 bytes.

The KASAN report was:

BUG: KASAN: global-out-of-bounds in ata_exec_internal_sg+0x50f/0xc70
Read of size 16 at addr ffffffff91f41f80 by task scsi_eh_1/149
...
The buggy address belongs to the variable:
 cdb.48319+0x0/0x40
Quoted 3 lines
Fixes afe759511808c ("libata: identify and init ZPODD devices")

Interesting, both initializer lists are less than ATAPI_CDB_LEN (16) elements, yet ata_exec_internal_sg() in drivers/ata/libata-core.c very clearly has a ATAPI_CDB_LEN byte memcpy on that element. Probably both initializer lists should just lead off the trailing zero's or provide the entire 16 elements. For now, thank you for the patch.

Quoted 23 lines
---
 drivers/ata/libata-zpodd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libata-zpodd.c +1 -2
index 173e6f2dd9af..eefda51f97d3 100644
@@ -56,7 +56,7 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
        unsigned int ret;
        struct rm_feature_desc *desc;
        struct ata_taskfile tf;
-       static const char cdb[] = {  GPCMD_GET_CONFIGURATION,
+       static const char cdb[ATAPI_CDB_LEN] = {  GPCMD_GET_CONFIGURATION,
                        2,      /* only 1 feature descriptor requested */
                        0, 3,   /* 3, removable medium feature */
                        0, 0, 0,/* reserved */
--

2.17.1

--
Kees Cook

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#2 lore raw
Quoted 21 lines · Nick Desaulniers
Quoted 16 lines · Kees Cook

Much like commit 18c9a99bce2a ("libata: zpodd: small read overflow in eject_tray()"), this fixes a cdb[] buffer length, this time in zpodd_get_mech_type():

We read from the cdb[] buffer in ata_exec_internal_sg(). It has to be ATAPI_CDB_LEN (16) bytes long, but this buffer is only 12 bytes.

The KASAN report was:

BUG: KASAN: global-out-of-bounds in ata_exec_internal_sg+0x50f/0xc70
Read of size 16 at addr ffffffff91f41f80 by task scsi_eh_1/149
...
The buggy address belongs to the variable:
 cdb.48319+0x0/0x40
Quoted 3 lines
Fixes afe759511808c ("libata: identify and init ZPODD devices")
Quoted 5 lines

Interesting, both initializer lists are less than ATAPI_CDB_LEN (16) elements, yet ata_exec_internal_sg() in drivers/ata/libata-core.c very clearly has a ATAPI_CDB_LEN byte memcpy on that element. Probably both initializer lists should just lead off the trailing zero's or provide the entire 16 elements. For now, thank you for the patch.

Yup, with the specific size added it'll be zero-padded.

Quoted 1 line

Thanks!

-Kees

Quoted 30 lines
Quoted 24 lines
---
 drivers/ata/libata-zpodd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libata-zpodd.c +1 -2
index 173e6f2dd9af..eefda51f97d3 100644
@@ -56,7 +56,7 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
        unsigned int ret;
        struct rm_feature_desc *desc;
        struct ata_taskfile tf;
-       static const char cdb[] = {  GPCMD_GET_CONFIGURATION,
+       static const char cdb[ATAPI_CDB_LEN] = {  GPCMD_GET_CONFIGURATION,
                        2,      /* only 1 feature descriptor requested */
                        0, 3,   /* 3, removable medium feature */
                        0, 0, 0,/* reserved */
--

2.17.1

--
Kees Cook

Signature · 2 lines
Thanks,
~Nick Desaulniers
Signature · 1 line
Kees Cook