public inbox for linux-ide@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ata: libata: fix ALL_SUB_MPAGES not to be performed when CDL is not supported
@ 2024-09-21 12:41 Jeongjun Park
  2024-09-23  8:49 ` Damien Le Moal
  0 siblings, 1 reply; 7+ messages in thread
From: Jeongjun Park @ 2024-09-21 12:41 UTC (permalink / raw)
  To: dlemoal, cassel
  Cc: syzbot+37757dc11ee77ef850bb, linux-ide, linux-kernel,
	Jeongjun Park

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.

Reported-by: syzbot+37757dc11ee77ef850bb@syzkaller.appspotmail.com
Tested-by: syzbot+37757dc11ee77ef850bb@syzkaller.appspotmail.com
Fixes: 602bcf212637 ("ata: libata: Improve CDL resource management")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 drivers/ata/libata-scsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 3328a6febc13..6f5527f12b0e 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -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:
--

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-09-23 13:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-21 12:41 [PATCH] ata: libata: fix ALL_SUB_MPAGES not to be performed when CDL is not supported Jeongjun Park
2024-09-23  8:49 ` Damien Le Moal
2024-09-23 11:15   ` Jeongjun Park
2024-09-23 11:24     ` Jeongjun Park
2024-09-23 13:07     ` Damien Le Moal
2024-09-23 13:22       ` Jeongjun Park
2024-09-23 13:24         ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox