diff options
author | Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> | 2018-10-30 21:50:25 -0400 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2018-11-05 14:34:08 -0500 |
commit | af31b04b67f4fd7f639fd465a507c154c46fc9fb (patch) | |
tree | 8e5d243cca7c1ea46bab279cd0fad2120174bb1c | |
parent | 651022382c7f8da46cb4872a545ee1da6d097d2a (diff) |
tools/testing/nvdimm: Fix the array size for dimm devices.
KASAN reports following global out of bounds access while
nfit_test is being loaded. The out of bound access happens
the following reference to dimm_fail_cmd_flags[dimm]. 'dimm' is
over than the index value, NUM_DCR (==5).
static int override_return_code(int dimm, unsigned int func, int rc)
{
if ((1 << func) & dimm_fail_cmd_flags[dimm]) {
dimm_fail_cmd_flags[] definition:
static unsigned long dimm_fail_cmd_flags[NUM_DCR];
'dimm' is the return value of get_dimm(), and get_dimm() returns
the index of handle[] array. The handle[] has 7 index. Let's use
ARRAY_SIZE(handle) as the array size.
KASAN report:
==================================================================
BUG: KASAN: global-out-of-bounds in nfit_test_ctl+0x47bb/0x55b0 [nfit_test]
Read of size 8 at addr ffffffffc10cbbe8 by task kworker/u41:0/8
...
Call Trace:
dump_stack+0xea/0x1b0
? dump_stack_print_info.cold.0+0x1b/0x1b
? kmsg_dump_rewind_nolock+0xd9/0xd9
print_address_description+0x65/0x22e
? nfit_test_ctl+0x47bb/0x55b0 [nfit_test]
kasan_report.cold.6+0x92/0x1a6
nfit_test_ctl+0x47bb/0x55b0 [nfit_test]
...
The buggy address belongs to the variable:
dimm_fail_cmd_flags+0x28/0xffffffffffffa440 [nfit_test]
==================================================================
Fixes: 39611e83a28c ("tools/testing/nvdimm: Make DSM failure code injection...")
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r-- | tools/testing/nvdimm/test/nfit.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c index 9527d47a1070..01ec04bf91b5 100644 --- a/tools/testing/nvdimm/test/nfit.c +++ b/tools/testing/nvdimm/test/nfit.c | |||
@@ -140,8 +140,8 @@ static u32 handle[] = { | |||
140 | [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), | 140 | [6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1), |
141 | }; | 141 | }; |
142 | 142 | ||
143 | static unsigned long dimm_fail_cmd_flags[NUM_DCR]; | 143 | static unsigned long dimm_fail_cmd_flags[ARRAY_SIZE(handle)]; |
144 | static int dimm_fail_cmd_code[NUM_DCR]; | 144 | static int dimm_fail_cmd_code[ARRAY_SIZE(handle)]; |
145 | 145 | ||
146 | static const struct nd_intel_smart smart_def = { | 146 | static const struct nd_intel_smart smart_def = { |
147 | .flags = ND_INTEL_SMART_HEALTH_VALID | 147 | .flags = ND_INTEL_SMART_HEALTH_VALID |
@@ -205,7 +205,7 @@ struct nfit_test { | |||
205 | unsigned long deadline; | 205 | unsigned long deadline; |
206 | spinlock_t lock; | 206 | spinlock_t lock; |
207 | } ars_state; | 207 | } ars_state; |
208 | struct device *dimm_dev[NUM_DCR]; | 208 | struct device *dimm_dev[ARRAY_SIZE(handle)]; |
209 | struct nd_intel_smart *smart; | 209 | struct nd_intel_smart *smart; |
210 | struct nd_intel_smart_threshold *smart_threshold; | 210 | struct nd_intel_smart_threshold *smart_threshold; |
211 | struct badrange badrange; | 211 | struct badrange badrange; |
@@ -2680,7 +2680,7 @@ static int nfit_test_probe(struct platform_device *pdev) | |||
2680 | u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; | 2680 | u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle; |
2681 | int i; | 2681 | int i; |
2682 | 2682 | ||
2683 | for (i = 0; i < NUM_DCR; i++) | 2683 | for (i = 0; i < ARRAY_SIZE(handle); i++) |
2684 | if (nfit_handle == handle[i]) | 2684 | if (nfit_handle == handle[i]) |
2685 | dev_set_drvdata(nfit_test->dimm_dev[i], | 2685 | dev_set_drvdata(nfit_test->dimm_dev[i], |
2686 | nfit_mem); | 2686 | nfit_mem); |