dma-iommu: Add a check to avoid dereference null pointer in function iommu_dma_map_sg()
Subsystems (2)
PATCH 1/1 dma-iommu: Add a check to avoid dereference null pointer in function iommu_dma_map_sg()
From: Xiang Chen <[email protected]>
The issue is reported by tool TscanCode, and it is possible to deference null pointer when prev is NULL which is the initial value.
--- drivers/iommu/dma-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/dma-iommu.c +1 -1
@@ -1042,7 +1042,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,* iova_len == 0, thus we cannot dereference prev the first * time through here (i.e. before it has a meaningful value). */ -if (pad_len && pad_len < s_length -1 ) { +if (prev && pad_len && pad_len < s_length -1 ) { prev->length += pad_len; iova_len += pad_len; }
Signature · 6 lines
2.8.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
maintainerQuoted 4 lines · chenxiang
From: Xiang Chen <[email protected]>
The issue is reported by tool TscanCode, and it is possible to deference null pointer when prev is NULL which is the initial value.
No it isn't. This is literally explained in the comment visible in the diff context below...
Robin.
Quoted 11 lines
Signed-off-by Xiang Chen <[email protected]>--- drivers/iommu/dma-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/dma-iommu.c +0
-0
drivers/iommu/dma-iommu.c static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, · line 1048
Quoted 8 lines
drivers/iommu/dma-iommu.c +1
-1@@ -1042,7 +1042,7 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,* iova_len == 0, thus we cannot dereference prev the first * time through here (i.e. before it has a meaningful value). */ -if (pad_len && pad_len < s_length -1 ) { +if (prev && pad_len && pad_len < s_length -1 ) { prev->length += pad_len; iova_len += pad_len; }
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 9 lines · Robin Murphy
Quoted 4 lines · chenxiang
From: Xiang Chen <[email protected]>
The issue is reported by tool TscanCode, and it is possible to deference null pointer when prev is NULL which is the initial value.
No it isn't. This is literally explained in the comment visible in the diff context below...
Robin.
ok, thanks
Quoted 16 lines
Quoted 16 lines
Signed-off-by Xiang Chen <[email protected]>--- drivers/iommu/dma-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/dma-iommu.c +0
-0@@ -1042,7 +1042,7 @@ static int iommu_dma_map_sg(struct device *dev,struct scatterlist *sg, * iova_len == 0, thus we cannot dereference prev the first * time through here (i.e. before it has a meaningfulvalue).
*/
Quoted 9 lines
drivers/iommu/dma-iommu.c static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, · line 1048
Quoted 6 lines
drivers/iommu/dma-iommu.c +1
-1-if (pad_len && pad_len < s_length -1 ) { +if (prev && pad_len && pad_len < s_length -1 ) { prev->length += pad_len; iova_len += pad_len; }.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu