driver/ata: fix potential null pointer dereference on pointer last_sge
PATCH 1/1 driver/ata: fix potential null pointer dereference on pointer last_sge
The pointer cs_desc could be null if the loop is not executed, so there is a potential NULL-PTR dereference issue. Fix this by adding a null check before dereference.
--- drivers/ata/sata_sil24.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/ata/sata_sil24.c +2 -0
@@ -785,6 +785,8 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc, sge++; } +if (!last_sge) +return ; last_sge->flags =cpu_to_le32 (SGE_TRM ); }
Signature · 1 line
2.17.1
Quoted 14 lines · Chengfeng Ye
The pointer
cs_desccould be null if the loop is not executed, so there is a potential NULL-PTR dereference issue. Fix this by adding a null check before dereference.Signed-off-by Chengfeng Ye <[email protected]>--- drivers/ata/sata_sil24.c | 2 ++ 1 file changed, 2 insertions(+)drivers/ata/sata_sil24.c +0
-0
drivers/ata/sata_sil24.c static inline void sil24_fill_sg(struct ata_queued_cmd *qc, · line 791
Quoted 7 lines
drivers/ata/sata_sil24.c +2
-0@@ -785,6 +785,8 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc, sge++; } +if (!last_sge) +return ; last_sge->flags =cpu_to_le32 (SGE_TRM ); }
I do not think that this fix is necessary: sil24_fill_sg() is called only if the qc has ATA_QCFLAG_DMAMAP set (see sil24_qc_prep()) and that in turn is only set if ata_sg_setup() sees at least one sg entry. So the loop in sil24_fill_sg() will always be executed for qc marked with ATA_QCFLAG_DMAMAP and so last_sg cannot be NULL.
Signature · 2 lines
Damien Le Moal Western Digital Research
Got it. Thanks for your reply in such detail.
Best Regards,
Chengfeng
-----邮件原件-----
发件人: Damien Le Moal <[email protected]>
发送时间: 2021年10月26日 12:10
收件人: YE Chengfeng <[email protected]>
抄送: [email protected]
主题: Re: [PATCH] driver/ata: fix potential null pointer dereference on pointer last_sge
Quoted 14 lines · Chengfeng Ye
The pointer
cs_desccould be null if the loop is not executed, so there is a potential NULL-PTR dereference issue. Fix this by adding a null check before dereference.Signed-off-by Chengfeng Ye <[email protected]>--- drivers/ata/sata_sil24.c | 2 ++ 1 file changed, 2 insertions(+)drivers/ata/sata_sil24.c index renamed from drivers/ata/sata_sil24.c +0
-0
06a1e27c4f84..2bd595da799f100644
drivers/ata/sata_sil24.c static inline void sil24_fill_sg(struct ata_queued_cmd *qc, · line 790
Quoted 6 lines
drivers/ata/sata_sil24.c +2
-0@@ -785,6 +785,8 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc, sge++; } +if (!last_sge) +return ; last_sge->flags =cpu_to_le32 (SGE_TRM ); }
I do not think that this fix is necessary: sil24_fill_sg() is called only if the qc has ATA_QCFLAG_DMAMAP set (see sil24_qc_prep()) and that in turn is only set if ata_sg_setup() sees at least one sg entry. So the loop in sil24_fill_sg() will always be executed for qc marked with ATA_QCFLAG_DMAMAP and so last_sg cannot be NULL.
--
Damien Le Moal
Western Digital Research