intel-iommu: Fix array overflow
PATCH 1/1 intel-iommu: Fix array overflow
Fix possible array overflow:
drivers/pci/intel-iommu.c: In function ‘dmar_get_fault_reason’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array bounds drivers/pci/intel-iommu.c: In function ‘iommu_page_fault’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array bounds
--- drivers/pci/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/intel-iommu.c +2 -2
@@ -749,8 +749,8 @@ static char *fault_reason_strings[] =char *dmar_get_fault_reason (u8 fault_reason) { -if (fault_reason >MAX_FAULT_REASON_IDX ) -return fault_reason_strings[MAX_FAULT_REASON_IDX ]; +if (fault_reason >=MAX_FAULT_REASON_IDX ) +return fault_reason_strings[MAX_FAULT_REASON_IDX -1 ];else return fault_reason_strings[fault_reason]; }
Quoted 18 lines · Takashi Iwai
Fix possible array overflow:
drivers/pci/intel-iommu.c: In function ‘dmar_get_fault_reason’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array boundsdrivers/pci/intel-iommu.c: In function ‘iommu_page_fault’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array boundsSigned-off-by Takashi Iwai <[email protected]>--- drivers/pci/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/intel-iommu.c +0
-0
drivers/pci/intel-iommu.c static char *fault_reason_strings[] = · line 753
Quoted 7 lines
drivers/pci/intel-iommu.c +2
-2@@ -749,8 +749,8 @@ static char *fault_reason_strings[] =char *dmar_get_fault_reason (u8 fault_reason) { -if (fault_reason >MAX_FAULT_REASON_IDX ) -return fault_reason_strings[MAX_FAULT_REASON_IDX ]; +if (fault_reason >=MAX_FAULT_REASON_IDX ) +return fault_reason_strings[MAX_FAULT_REASON_IDX -1 ];
This looks like what the code meant to implement. I guess future hardware may be able to generate more types of faults, otherwise I'd put a BUG here.
--mgross
Quoted 8 lines
drivers/pci/intel-iommu.c +0
-1else return fault_reason_strings[fault_reason]; } -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
At Wed, 24 Oct 2007 16:30:37 -0700,
Quoted 21 lines · Mark Gross
Quoted 19 lines · Takashi Iwai
Fix possible array overflow:
drivers/pci/intel-iommu.c: In function ‘dmar_get_fault_reason’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array boundsdrivers/pci/intel-iommu.c: In function ‘iommu_page_fault’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array boundsSigned-off-by Takashi Iwai <[email protected]>--- drivers/pci/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/intel-iommu.c +0
-0@@ -749,8 +749,8 @@ static char *fault_reason_strings[] =
Quoted 8 lines
drivers/pci/intel-iommu.c static char *fault_reason_strings[] = · line 753
Quoted 6 lines
drivers/pci/intel-iommu.c +2
-2char *dmar_get_fault_reason (u8 fault_reason) { -if (fault_reason >MAX_FAULT_REASON_IDX ) -return fault_reason_strings[MAX_FAULT_REASON_IDX ]; +if (fault_reason >=MAX_FAULT_REASON_IDX ) +return fault_reason_strings[MAX_FAULT_REASON_IDX -1 ];This looks like what the code meant to implement.
I think not. The size of fault_reason_strings[] is MAX_FAULT_REASON_IDX, not + 1. So gcc warning is correct. Maybe the main problem is that the constant name is confusing...
Takashi
Quoted 16 lines
I guess future
hardware may be able to generate more types of faults, otherwise I'd put a BUG here.--mgross
Quoted 8 lines
drivers/pci/intel-iommu.c +0
-1else return fault_reason_strings[fault_reason]; } -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 32 lines · Takashi Iwai
At Wed, 24 Oct 2007 16:30:37 -0700,
Quoted 21 lines · Mark Gross
Quoted 19 lines · Takashi Iwai
Fix possible array overflow:
drivers/pci/intel-iommu.c: In function ‘dmar_get_fault_reason’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array boundsdrivers/pci/intel-iommu.c: In function ‘iommu_page_fault’:drivers/pci/intel-iommu.c:753: warning: array subscript is above array boundsSigned-off-by Takashi Iwai <[email protected]>--- drivers/pci/intel-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/intel-iommu.c +0
-0@@ -749,8 +749,8 @@ static char *fault_reason_strings[] =Quoted 8 lines
drivers/pci/intel-iommu.c static char *fault_reason_strings[] = · line 753
Quoted 6 lines
drivers/pci/intel-iommu.c +2
-2char *dmar_get_fault_reason (u8 fault_reason) { -if (fault_reason >MAX_FAULT_REASON_IDX ) -return fault_reason_strings[MAX_FAULT_REASON_IDX ]; +if (fault_reason >=MAX_FAULT_REASON_IDX ) +return fault_reason_strings[MAX_FAULT_REASON_IDX -1 ];This looks like what the code meant to implement.
Quoted 3 lines
I think not. The size of fault_reason_strings[] is
MAX_FAULT_REASON_IDX, not + 1. So gcc warning is correct. Maybe the main problem is that the constant name is confusing...
Yup, GCC warning is correct. the size of fault_reason_strings[] is MAX_FAULT_REASON_IDX and hence the max array that can be referenced is [MAX_FAULT_REASON_IDX -1], hence the fix by Takashi is correct.
-Anil