ata: libata: fix ALL_SUB_MPAGES not to be performed when CDL is not supported
PATCH 1/1 ata: libata: fix ALL_SUB_MPAGES not to be performed when CDL is not supported
In the previous commit 602bcf212637 ("ata: libata: Improve CDL resource management"), the ata_cdl structure was added and the ata_cdl structure memory was allocated with kzalloc(). Because of this, if CDL is not supported, dev->cdl is a NULL pointer, so additional work should never be done.
However, even if CDL is not supported now, if spg is ALL_SUB_MPAGES, dereferencing dev->cdl will result in a NULL pointer dereference.
Therefore, I think it is appropriate to check dev->flags in ata_scsiop_mode_sense() if spg is ALL_SUB_MPAGES to see if CDL is supported.
--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ata/libata-scsi.c +3 -1
@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ; +if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;case CDL_T2A_SUB_MPAGE :case CDL_T2B_SUB_MPAGE :case ATA_FEATURE_SUB_MPAGE :
--
Damien Le Moal
maintainerQuoted 25 lines · Jeongjun Park
In the previous commit
602bcf212637("ata: libata: Improve CDL resource management"), theata_cdlstructure was added and theata_cdlstructure memory was allocated withkzalloc(). Because of this, if CDL is not supported,dev->cdlis a NULL pointer, so additional work should never be done.However, even if CDL is not supported now, if spg is
ALL_SUB_MPAGES, dereferencingdev->cdlwill result in a NULL pointer dereference.Therefore, I think it is appropriate to check
dev->flagsinata_scsiop_mode_sense()if spg isALL_SUB_MPAGESto see if CDL is supported.Reported-by [email protected]Tested-by [email protected]Fixes 602bcf212637 ("ata: libata: Improve CDL resource management")Signed-off-by Jeongjun Park <[email protected]>--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ata/libata-scsi.c +0
-0
drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) · line 2447
Quoted 7 lines
drivers/ata/libata-scsi.c +3
-1@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ; +if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;
I do not think this is correct at all. If the user request all sub mpages, we need to give that list regardless of CDL support. What needs to be fixed is that if CDL is NOT supported, we should not try to add the information for the T2A and T2B sub pages. So the fix should be this:
drivers/ata/libata-scsi.c +6 -1
@@ -2256,10 +2256,15 @@ static inline u16 ata_xlat_cdl_limit(u8 *buf)static unsigned int ata_msense_control_spgt2 (struct ata_device *dev,u8 *buf,u8 spg) { -u8 *b, *cdl = dev->cdl->desc_log_buf, *desc; +u8 *b, *cdl, *desc;u32 policy;int i; +if (!(dev->flags &ATA_DFLAG_CDL ) || !dev->cdl) +return 0 ; + + cdl = dev->cdl->desc_log_buf; +/* * Fill the subpage. The first four bytes of the T2A/T2B mode pages * are a header. The PAGE LENGTH field is the size of the page
Quoted 4 lines
drivers/ata/libata-scsi.c +0
-1case CDL_T2A_SUB_MPAGE :case CDL_T2B_SUB_MPAGE :case ATA_FEATURE_SUB_MPAGE : --
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 31 lines · Damien Le Moal
Quoted 29 lines · Jeongjun Park
In the previous commit
602bcf212637("ata: libata: Improve CDL resource management"), theata_cdlstructure was added and theata_cdlstructure memory was allocated withkzalloc(). Because of this, if CDL is not supported,dev->cdlis a NULL pointer, so additional work should never be done.However, even if CDL is not supported now, if spg is
ALL_SUB_MPAGES, dereferencingdev->cdlwill result in a NULL pointer dereference.Therefore, I think it is appropriate to check
dev->flagsinata_scsiop_mode_sense()if spg isALL_SUB_MPAGESto see if CDL is supported.Reported-by [email protected]Tested-by [email protected]Fixes 602bcf212637 ("ata: libata: Improve CDL resource management")Signed-off-by Jeongjun Park <[email protected]>--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ata/libata-scsi.c +0
-1@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ;
Quoted 8 lines
drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) · line 2447
Quoted 3 lines
drivers/ata/libata-scsi.c +3
-0+if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;I do not think this is correct at all. If the user request all sub mpages, we need to give that list regardless of CDL support. What needs to be fixed is that if CDL is NOT supported, we should not try to add the information for the T2A and T2B sub pages. So the fix should be this:
Okay. But after looking into it further, I think it would be more appropriate to also check the ATA_DFLAG_CDL_ENABLED flag when checking if CDL is not supported. So it seems like it would be better to modify the condition as below.
What do you think?
if (!(dev->flags & ATA_DFLAG_CDL
dev->flags & ATA_DFLAG_CDL_ENABLED) || !dev->cdl)
return 0;Regards,
Jeongjun Park
Quoted 33 lines
drivers/ata/libata-scsi.c +6
-1@@ -2256,10 +2256,15 @@ static inline u16 ata_xlat_cdl_limit(u8 *buf)static unsigned int ata_msense_control_spgt2 (struct ata_device *dev,u8 *buf,u8 spg) { -u8 *b, *cdl = dev->cdl->desc_log_buf, *desc; +u8 *b, *cdl, *desc;u32 policy;int i; +if (!(dev->flags &ATA_DFLAG_CDL ) || !dev->cdl) +return 0 ; + + cdl = dev->cdl->desc_log_buf; +/* * Fill the subpage. The first four bytes of the T2A/T2B mode pages * are a header. The PAGE LENGTH field is the size of the page drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)
Quoted 6 lines
drivers/ata/libata-scsi.c +0
-1case CDL_T2A_SUB_MPAGE :case CDL_T2B_SUB_MPAGE :case ATA_FEATURE_SUB_MPAGE : ----
Damien Le Moal
Western Digital Research
Quoted 47 lines · Jeongjun Park
Quoted 31 lines · Damien Le Moal
Quoted 29 lines · Jeongjun Park
In the previous commit
602bcf212637("ata: libata: Improve CDL resource management"), theata_cdlstructure was added and theata_cdlstructure memory was allocated withkzalloc(). Because of this, if CDL is not supported,dev->cdlis a NULL pointer, so additional work should never be done.However, even if CDL is not supported now, if spg is
ALL_SUB_MPAGES, dereferencingdev->cdlwill result in a NULL pointer dereference.Therefore, I think it is appropriate to check
dev->flagsinata_scsiop_mode_sense()if spg isALL_SUB_MPAGESto see if CDL is supported.Reported-by [email protected]Tested-by [email protected]Fixes 602bcf212637 ("ata: libata: Improve CDL resource management")Signed-off-by Jeongjun Park <[email protected]>--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ata/libata-scsi.c +0
-1@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ;Quoted 8 lines
drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) · line 2447
Quoted 3 lines
drivers/ata/libata-scsi.c +3
-0+if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;I do not think this is correct at all. If the user request all sub mpages, we need to give that list regardless of CDL support. What needs to be fixed is that if CDL is NOT supported, we should not try to add the information for the T2A and T2B sub pages. So the fix should be this:
Okay. But after looking into it further, I think it would be more appropriate to also check the
ATA_DFLAG_CDL_ENABLEDflag when checking if CDL is not supported. So it seems like it would be better to modify the condition as below.
Quoted 5 lines
What do you think?
if (!(dev->flags &
ATA_DFLAG_CDLdev->flags & ATA_DFLAG_CDL_ENABLED) || !dev->cdl) return 0;
if (!(dev->flags & ATA_DFLAG_CDL &&
dev->flags & ATA_DFLAG_CDL_ENABLED) || !dev->cdl)
return 0;Quoted 37 lines
Regards,
Jeongjun ParkQuoted 33 lines
drivers/ata/libata-scsi.c +6
-1@@ -2256,10 +2256,15 @@ static inline u16 ata_xlat_cdl_limit(u8 *buf)static unsigned int ata_msense_control_spgt2 (struct ata_device *dev,u8 *buf,u8 spg) { -u8 *b, *cdl = dev->cdl->desc_log_buf, *desc; +u8 *b, *cdl, *desc;u32 policy;int i; +if (!(dev->flags &ATA_DFLAG_CDL ) || !dev->cdl) +return 0 ; + + cdl = dev->cdl->desc_log_buf; +/* * Fill the subpage. The first four bytes of the T2A/T2B mode pages * are a header. The PAGE LENGTH field is the size of the page drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)
Quoted 6 lines
drivers/ata/libata-scsi.c +0
-1case CDL_T2A_SUB_MPAGE :case CDL_T2B_SUB_MPAGE :case ATA_FEATURE_SUB_MPAGE : ----
Damien Le Moal
Western Digital Research
Damien Le Moal
maintainerQuoted 46 lines · Jeongjun Park
Quoted 31 lines · Damien Le Moal
Quoted 29 lines · Jeongjun Park
In the previous commit
602bcf212637("ata: libata: Improve CDL resource management"), theata_cdlstructure was added and theata_cdlstructure memory was allocated withkzalloc(). Because of this, if CDL is not supported,dev->cdlis a NULL pointer, so additional work should never be done.However, even if CDL is not supported now, if spg is
ALL_SUB_MPAGES, dereferencingdev->cdlwill result in a NULL pointer dereference.Therefore, I think it is appropriate to check
dev->flagsinata_scsiop_mode_sense()if spg isALL_SUB_MPAGESto see if CDL is supported.Reported-by [email protected]Tested-by [email protected]Fixes 602bcf212637 ("ata: libata: Improve CDL resource management")Signed-off-by Jeongjun Park <[email protected]>--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ata/libata-scsi.c +0
-1@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ;Quoted 8 lines
drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) · line 2447
Quoted 3 lines
drivers/ata/libata-scsi.c +3
-0+if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;I do not think this is correct at all. If the user request all sub mpages, we need to give that list regardless of CDL support. What needs to be fixed is that if CDL is NOT supported, we should not try to add the information for the T2A and T2B sub pages. So the fix should be this:
Okay. But after looking into it further, I think it would be more appropriate to also check the
ATA_DFLAG_CDL_ENABLEDflag when checking if CDL is not supported. So it seems like it would be better to modify the condition as below.
Quoted 5 lines
What do you think?
if (!(dev->flags &
ATA_DFLAG_CDLdev->flags & ATA_DFLAG_CDL_ENABLED) || !dev->cdl) return 0;
No, that would be wrong. The mode sense is to report if CDL is *supported*, not if it is enabled or not. So we always must report the T2A and T2B pages for SATA drives that support CDL, even if the CDL feature is disabled.
The flag ATA_DFLAG_CDL_ENABLED is not checked in ata_scsiop_mode_sense() for this reason. Adding that check in ata_msense_control_spgt2() would be wrong.
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 54 lines · Damien Le Moal
Quoted 46 lines · Jeongjun Park
Quoted 31 lines · Damien Le Moal
Quoted 29 lines · Jeongjun Park
In the previous commit
602bcf212637("ata: libata: Improve CDL resource management"), theata_cdlstructure was added and theata_cdlstructure memory was allocated withkzalloc(). Because of this, if CDL is not supported,dev->cdlis a NULL pointer, so additional work should never be done.However, even if CDL is not supported now, if spg is
ALL_SUB_MPAGES, dereferencingdev->cdlwill result in a NULL pointer dereference.Therefore, I think it is appropriate to check
dev->flagsinata_scsiop_mode_sense()if spg isALL_SUB_MPAGESto see if CDL is supported.Reported-by [email protected]Tested-by [email protected]Fixes 602bcf212637 ("ata: libata: Improve CDL resource management")Signed-off-by Jeongjun Park <[email protected]>--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ata/libata-scsi.c +0
-1@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ;Quoted 8 lines
drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) · line 2447
Quoted 3 lines
drivers/ata/libata-scsi.c +3
-0+if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;I do not think this is correct at all. If the user request all sub mpages, we need to give that list regardless of CDL support. What needs to be fixed is that if CDL is NOT supported, we should not try to add the information for the T2A and T2B sub pages. So the fix should be this:
Okay. But after looking into it further, I think it would be more appropriate to also check the
ATA_DFLAG_CDL_ENABLEDflag when checking if CDL is not supported. So it seems like it would be better to modify the condition as below.Quoted 5 lines
What do you think?
if (!(dev->flags &
ATA_DFLAG_CDLdev->flags & ATA_DFLAG_CDL_ENABLED) || !dev->cdl) return 0;
Quoted 7 lines
No, that would be wrong. The mode sense is to report if CDL is *supported*, not if it is enabled or not. So we always must report the T2A and T2B pages for SATA drives that support CDL, even if the CDL feature is disabled.
The flag
ATA_DFLAG_CDL_ENABLEDis not checked inata_scsiop_mode_sense()for this reason. Adding that check inata_msense_control_spgt2()would be wrong.
Thanks for your reply! I will write a v2 patch to meet the requirements you provided
and send it to you.
Regards,
Jeongjun Park
Quoted 4 lines
--
Damien Le Moal
Western Digital Research
Damien Le Moal
maintainerQuoted 59 lines · Jeongjun Park
Quoted 58 lines · Damien Le Moal
Quoted 46 lines · Jeongjun Park
Quoted 31 lines · Damien Le Moal
Quoted 29 lines · Jeongjun Park
In the previous commit
602bcf212637("ata: libata: Improve CDL resource management"), theata_cdlstructure was added and theata_cdlstructure memory was allocated withkzalloc(). Because of this, if CDL is not supported,dev->cdlis a NULL pointer, so additional work should never be done.However, even if CDL is not supported now, if spg is
ALL_SUB_MPAGES, dereferencingdev->cdlwill result in a NULL pointer dereference.Therefore, I think it is appropriate to check
dev->flagsinata_scsiop_mode_sense()if spg isALL_SUB_MPAGESto see if CDL is supported.Reported-by [email protected]Tested-by [email protected]Fixes 602bcf212637 ("ata: libata: Improve CDL resource management")Signed-off-by Jeongjun Park <[email protected]>--- drivers/ata/libata-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ata/libata-scsi.c +0
-1@@ -2442,7 +2442,9 @@ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf)if (spg) {switch (spg) {case ALL_SUB_MPAGES : -break ;Quoted 8 lines
drivers/ata/libata-scsi.c static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) · line 2447
Quoted 3 lines
drivers/ata/libata-scsi.c +3
-0+if (dev->flags &ATA_DFLAG_CDL ) +break ; + fallthrough;I do not think this is correct at all. If the user request all sub mpages, we need to give that list regardless of CDL support. What needs to be fixed is that if CDL is NOT supported, we should not try to add the information for the T2A and T2B sub pages. So the fix should be this:
Okay. But after looking into it further, I think it would be more appropriate to also check the
ATA_DFLAG_CDL_ENABLEDflag when checking if CDL is not supported. So it seems like it would be better to modify the condition as below.Quoted 5 lines
What do you think?
if (!(dev->flags &
ATA_DFLAG_CDLdev->flags & ATA_DFLAG_CDL_ENABLED) || !dev->cdl) return 0;No, that would be wrong. The mode sense is to report if CDL is *supported*, not if it is enabled or not. So we always must report the T2A and T2B pages for SATA drives that support CDL, even if the CDL feature is disabled.
Quoted 7 lines
Quoted 3 lines
The flag
ATA_DFLAG_CDL_ENABLEDis not checked inata_scsiop_mode_sense()for this reason. Adding that check inata_msense_control_spgt2()would be wrong.Thanks for your reply! I will write a v2 patch to meet the requirements you provided
and send it to you.
No need. I have the fix patch already. And while writing it, I also noticed that ata_msense_control() is wrong (the ALL_SUB_MPAGES case adds the T2A page twice instead of adding the T2A page and then the T2B page. So I have another patch to fix that.
Will be posting soon.
Quoted 8 lines
Regards,
Jeongjun ParkQuoted 4 lines
--
Damien Le Moal
Western Digital Research
Signature · 2 lines
Damien Le Moal Western Digital Research