All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/testing/nvdimm: Fix the index for dimm devices.
@ 2018-10-29 19:10 Masayoshi Mizuma
  2018-10-30 22:25 ` Dan Williams
  2018-10-30 22:30 ` Dan Williams
  0 siblings, 2 replies; 4+ messages in thread
From: Masayoshi Mizuma @ 2018-10-29 19:10 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Masayoshi Mizuma

From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>

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, and the
index #0 to #4 is for nfit_test.0 and #5, #6 is for nfit_test.1.
NUM_DCR is only for nfit_test.0. Let's add for nfit_test.1.

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]
==================================================================

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
---
 tools/testing/nvdimm/test/nfit.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
index 9527d47a1070..38f066ce2f47 100644
--- a/tools/testing/nvdimm/test/nfit.c
+++ b/tools/testing/nvdimm/test/nfit.c
@@ -104,6 +104,8 @@
 enum {
 	NUM_PM  = 3,
 	NUM_DCR = 5,
+	NUM_DCR_ALL = NUM_DCR + 2, /* 5 DCRs for test.0, 2 DCRs for test.1 */
+
 	NUM_HINTS = 8,
 	NUM_BDW = NUM_DCR,
 	NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW,
@@ -140,8 +142,8 @@ static u32 handle[] = {
 	[6] = NFIT_DIMM_HANDLE(1, 0, 0, 0, 1),
 };
 
-static unsigned long dimm_fail_cmd_flags[NUM_DCR];
-static int dimm_fail_cmd_code[NUM_DCR];
+static unsigned long dimm_fail_cmd_flags[NUM_DCR_ALL];
+static int dimm_fail_cmd_code[NUM_DCR_ALL];
 
 static const struct nd_intel_smart smart_def = {
 	.flags = ND_INTEL_SMART_HEALTH_VALID
@@ -205,7 +207,7 @@ struct nfit_test {
 		unsigned long deadline;
 		spinlock_t lock;
 	} ars_state;
-	struct device *dimm_dev[NUM_DCR];
+	struct device *dimm_dev[NUM_DCR_ALL];
 	struct nd_intel_smart *smart;
 	struct nd_intel_smart_threshold *smart_threshold;
 	struct badrange badrange;
@@ -2680,7 +2682,7 @@ static int nfit_test_probe(struct platform_device *pdev)
 		u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle;
 		int i;
 
-		for (i = 0; i < NUM_DCR; i++)
+		for (i = 0; i < NUM_DCR_ALL; i++)
 			if (nfit_handle == handle[i])
 				dev_set_drvdata(nfit_test->dimm_dev[i],
 						nfit_mem);
-- 
2.18.0

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] tools/testing/nvdimm: Fix the index for dimm devices.
  2018-10-29 19:10 [PATCH] tools/testing/nvdimm: Fix the index for dimm devices Masayoshi Mizuma
@ 2018-10-30 22:25 ` Dan Williams
  2018-10-30 22:30 ` Dan Williams
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Williams @ 2018-10-30 22:25 UTC (permalink / raw)
  To: Masayoshi Mizuma; +Cc: Masayoshi Mizuma, linux-nvdimm

On Mon, Oct 29, 2018 at 12:11 PM Masayoshi Mizuma <msys.mizuma@gmail.com> wrote:
>
> From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
>
> 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, and the
> index #0 to #4 is for nfit_test.0 and #5, #6 is for nfit_test.1.
> NUM_DCR is only for nfit_test.0. Let's add for nfit_test.1.
>
> 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]
> ==================================================================

Thanks, good catch. This mostly looks ok just one change request below...

>
> Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> ---
>  tools/testing/nvdimm/test/nfit.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
> index 9527d47a1070..38f066ce2f47 100644
> --- a/tools/testing/nvdimm/test/nfit.c
> +++ b/tools/testing/nvdimm/test/nfit.c
> @@ -104,6 +104,8 @@
>  enum {
>         NUM_PM  = 3,
>         NUM_DCR = 5,
> +       NUM_DCR_ALL = NUM_DCR + 2, /* 5 DCRs for test.0, 2 DCRs for test.1 */

Let's just use ARRAY_SIZE(handle) in place of introducing NUM_DCR_ALL.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] tools/testing/nvdimm: Fix the index for dimm devices.
  2018-10-29 19:10 [PATCH] tools/testing/nvdimm: Fix the index for dimm devices Masayoshi Mizuma
  2018-10-30 22:25 ` Dan Williams
@ 2018-10-30 22:30 ` Dan Williams
  2018-10-31  1:45   ` Masayoshi Mizuma
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Williams @ 2018-10-30 22:30 UTC (permalink / raw)
  To: Masayoshi Mizuma; +Cc: Masayoshi Mizuma, linux-nvdimm

On Mon, Oct 29, 2018 at 12:11 PM Masayoshi Mizuma <msys.mizuma@gmail.com> wrote:
>
> From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
>
> 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).
>
> ---

One more small comment, please be careful to not use "---" in the
changelog because this causes "git am" to stop parsing the changelog
right at this point. I lost your sign-off and debug information when
test applying this.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] tools/testing/nvdimm: Fix the index for dimm devices.
  2018-10-30 22:30 ` Dan Williams
@ 2018-10-31  1:45   ` Masayoshi Mizuma
  0 siblings, 0 replies; 4+ messages in thread
From: Masayoshi Mizuma @ 2018-10-31  1:45 UTC (permalink / raw)
  To: Dan Williams; +Cc: Masayoshi Mizuma, linux-nvdimm

On Tue, Oct 30, 2018 at 03:30:05PM -0700, Dan Williams wrote:
> On Mon, Oct 29, 2018 at 12:11 PM Masayoshi Mizuma <msys.mizuma@gmail.com> wrote:
> >
> > From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
> >
> > 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).
> >
> > ---
> 
> One more small comment, please be careful to not use "---" in the
> changelog because this causes "git am" to stop parsing the changelog
> right at this point. I lost your sign-off and debug information when
> test applying this.

Sorry. Got it.

- Masa
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2018-10-31  1:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-29 19:10 [PATCH] tools/testing/nvdimm: Fix the index for dimm devices Masayoshi Mizuma
2018-10-30 22:25 ` Dan Williams
2018-10-30 22:30 ` Dan Williams
2018-10-31  1:45   ` Masayoshi Mizuma

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.