All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
@ 2022-05-24 11:23 ` Vaibhav Jain
  0 siblings, 0 replies; 6+ messages in thread
From: Vaibhav Jain @ 2022-05-24 11:23 UTC (permalink / raw)
  To: nvdimm, linuxppc-dev
  Cc: Vaibhav Jain, Dan Williams, Aneesh Kumar K . V, Michael Ellerman,
	Shivaprasad G Bhat, Sachin Sant

Sachin reported [1] that on a POWER-10 lpar he is seeing a kernel panic being
reported with vPMEM when papr_scm probe is being called. The panic is of the
form below and is observed only with following option disabled(profile) for the
said LPAR 'Enable Performance Information Collection' in the HMC:

 Kernel attempted to write user page (1c) - exploit attempt? (uid: 0)
 BUG: Kernel NULL pointer dereference on write at 0x0000001c
 Faulting instruction address: 0xc008000001b90844
 Oops: Kernel access of bad area, sig: 11 [#1]
<snip>
 NIP [c008000001b90844] drc_pmem_query_stats+0x5c/0x270 [papr_scm]
 LR [c008000001b92794] papr_scm_probe+0x2ac/0x6ec [papr_scm]
 Call Trace:
       0xc00000000941bca0 (unreliable)
       papr_scm_probe+0x2ac/0x6ec [papr_scm]
       platform_probe+0x98/0x150
       really_probe+0xfc/0x510
       __driver_probe_device+0x17c/0x230
<snip>
 ---[ end trace 0000000000000000 ]---
 Kernel panic - not syncing: Fatal exception

On investigation looks like this panic was caused due to a 'stat_buffer' of
size==0 being provided to drc_pmem_query_stats() to fetch all performance
stats-ids of an NVDIMM. However drc_pmem_query_stats() shouldn't have been called
since the vPMEM NVDIMM doesn't support and performance stat-id's. This was caused
due to missing check for 'p->stat_buffer_len' at the beginning of
papr_scm_pmu_check_events() which indicates that the NVDIMM doesn't support
performance-stats.

Fix this by introducing the check for 'p->stat_buffer_len' at the beginning of
papr_scm_pmu_check_events().

[1] https://lore.kernel.org/all/6B3A522A-6A5F-4CC9-B268-0C63AA6E07D3@linux.ibm.com

Fixes: 0e0946e22f3665d2732 ("powerpc/papr_scm: Fix leaking nvdimm_events_map elements")
Reported-by: Sachin Sant <sachinp@linux.ibm.com>
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 arch/powerpc/platforms/pseries/papr_scm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 181b855b3050..82cae08976bc 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -465,6 +465,9 @@ static int papr_scm_pmu_check_events(struct papr_scm_priv *p, struct nvdimm_pmu
 	u32 available_events;
 	int index, rc = 0;
 
+	if (!p->stat_buffer_len)
+		return -ENOENT;
+
 	available_events = (p->stat_buffer_len  - sizeof(struct papr_scm_perf_stats))
 			/ sizeof(struct papr_scm_perf_stat);
 	if (available_events == 0)
-- 
2.35.1


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

* [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
@ 2022-05-24 11:23 ` Vaibhav Jain
  0 siblings, 0 replies; 6+ messages in thread
From: Vaibhav Jain @ 2022-05-24 11:23 UTC (permalink / raw)
  To: nvdimm, linuxppc-dev
  Cc: Shivaprasad G Bhat, Sachin Sant, Aneesh Kumar K . V,
	Vaibhav Jain, Dan Williams

Sachin reported [1] that on a POWER-10 lpar he is seeing a kernel panic being
reported with vPMEM when papr_scm probe is being called. The panic is of the
form below and is observed only with following option disabled(profile) for the
said LPAR 'Enable Performance Information Collection' in the HMC:

 Kernel attempted to write user page (1c) - exploit attempt? (uid: 0)
 BUG: Kernel NULL pointer dereference on write at 0x0000001c
 Faulting instruction address: 0xc008000001b90844
 Oops: Kernel access of bad area, sig: 11 [#1]
<snip>
 NIP [c008000001b90844] drc_pmem_query_stats+0x5c/0x270 [papr_scm]
 LR [c008000001b92794] papr_scm_probe+0x2ac/0x6ec [papr_scm]
 Call Trace:
       0xc00000000941bca0 (unreliable)
       papr_scm_probe+0x2ac/0x6ec [papr_scm]
       platform_probe+0x98/0x150
       really_probe+0xfc/0x510
       __driver_probe_device+0x17c/0x230
<snip>
 ---[ end trace 0000000000000000 ]---
 Kernel panic - not syncing: Fatal exception

On investigation looks like this panic was caused due to a 'stat_buffer' of
size==0 being provided to drc_pmem_query_stats() to fetch all performance
stats-ids of an NVDIMM. However drc_pmem_query_stats() shouldn't have been called
since the vPMEM NVDIMM doesn't support and performance stat-id's. This was caused
due to missing check for 'p->stat_buffer_len' at the beginning of
papr_scm_pmu_check_events() which indicates that the NVDIMM doesn't support
performance-stats.

Fix this by introducing the check for 'p->stat_buffer_len' at the beginning of
papr_scm_pmu_check_events().

[1] https://lore.kernel.org/all/6B3A522A-6A5F-4CC9-B268-0C63AA6E07D3@linux.ibm.com

Fixes: 0e0946e22f3665d2732 ("powerpc/papr_scm: Fix leaking nvdimm_events_map elements")
Reported-by: Sachin Sant <sachinp@linux.ibm.com>
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 arch/powerpc/platforms/pseries/papr_scm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 181b855b3050..82cae08976bc 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -465,6 +465,9 @@ static int papr_scm_pmu_check_events(struct papr_scm_priv *p, struct nvdimm_pmu
 	u32 available_events;
 	int index, rc = 0;
 
+	if (!p->stat_buffer_len)
+		return -ENOENT;
+
 	available_events = (p->stat_buffer_len  - sizeof(struct papr_scm_perf_stats))
 			/ sizeof(struct papr_scm_perf_stat);
 	if (available_events == 0)
-- 
2.35.1


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

* Re: [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
  2022-05-24 11:23 ` Vaibhav Jain
@ 2022-05-24 13:51   ` Sachin Sant
  -1 siblings, 0 replies; 6+ messages in thread
From: Sachin Sant @ 2022-05-24 13:51 UTC (permalink / raw)
  To: Vaibhav Jain
  Cc: nvdimm, linuxppc-dev, Dan Williams, Aneesh Kumar K . V,
	Michael Ellerman, Shivaprasad G Bhat


> On 24-May-2022, at 4:53 PM, Vaibhav Jain <vaibhav@linux.ibm.com> wrote:
> 
> Sachin reported [1] that on a POWER-10 lpar he is seeing a kernel panic being
> reported with vPMEM when papr_scm probe is being called. The panic is of the
> form below and is observed only with following option disabled(profile) for the
> said LPAR 'Enable Performance Information Collection' in the HMC:
> 
> Kernel attempted to write user page (1c) - exploit attempt? (uid: 0)
> BUG: Kernel NULL pointer dereference on write at 0x0000001c
> Faulting instruction address: 0xc008000001b90844
> Oops: Kernel access of bad area, sig: 11 [#1]
> <snip>
> NIP [c008000001b90844] drc_pmem_query_stats+0x5c/0x270 [papr_scm]
> LR [c008000001b92794] papr_scm_probe+0x2ac/0x6ec [papr_scm]
> Call Trace:
>       0xc00000000941bca0 (unreliable)
>       papr_scm_probe+0x2ac/0x6ec [papr_scm]
>       platform_probe+0x98/0x150
>       really_probe+0xfc/0x510
>       __driver_probe_device+0x17c/0x230
> <snip>
> ---[ end trace 0000000000000000 ]---
> Kernel panic - not syncing: Fatal exception
> 
> On investigation looks like this panic was caused due to a 'stat_buffer' of
> size==0 being provided to drc_pmem_query_stats() to fetch all performance
> stats-ids of an NVDIMM. However drc_pmem_query_stats() shouldn't have been called
> since the vPMEM NVDIMM doesn't support and performance stat-id's. This was caused
> due to missing check for 'p->stat_buffer_len' at the beginning of
> papr_scm_pmu_check_events() which indicates that the NVDIMM doesn't support
> performance-stats.
> 
> Fix this by introducing the check for 'p->stat_buffer_len' at the beginning of
> papr_scm_pmu_check_events().
> 
> [1] https://lore.kernel.org/all/6B3A522A-6A5F-4CC9-B268-0C63AA6E07D3@linux.ibm.com
> 
> Fixes: 0e0946e22f3665d2732 ("powerpc/papr_scm: Fix leaking nvdimm_events_map elements")
> Reported-by: Sachin Sant <sachinp@linux.ibm.com>
> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> ---

Thanks Vaibhav for the patch. With the patch the reported problem is fixed.

Tested-by: Sachin Sant <sachinp@linux.ibm.com>

-Sachin


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

* Re: [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
@ 2022-05-24 13:51   ` Sachin Sant
  0 siblings, 0 replies; 6+ messages in thread
From: Sachin Sant @ 2022-05-24 13:51 UTC (permalink / raw)
  To: Vaibhav Jain
  Cc: nvdimm, Shivaprasad G Bhat, Aneesh Kumar K . V, Dan Williams,
	linuxppc-dev


> On 24-May-2022, at 4:53 PM, Vaibhav Jain <vaibhav@linux.ibm.com> wrote:
> 
> Sachin reported [1] that on a POWER-10 lpar he is seeing a kernel panic being
> reported with vPMEM when papr_scm probe is being called. The panic is of the
> form below and is observed only with following option disabled(profile) for the
> said LPAR 'Enable Performance Information Collection' in the HMC:
> 
> Kernel attempted to write user page (1c) - exploit attempt? (uid: 0)
> BUG: Kernel NULL pointer dereference on write at 0x0000001c
> Faulting instruction address: 0xc008000001b90844
> Oops: Kernel access of bad area, sig: 11 [#1]
> <snip>
> NIP [c008000001b90844] drc_pmem_query_stats+0x5c/0x270 [papr_scm]
> LR [c008000001b92794] papr_scm_probe+0x2ac/0x6ec [papr_scm]
> Call Trace:
>       0xc00000000941bca0 (unreliable)
>       papr_scm_probe+0x2ac/0x6ec [papr_scm]
>       platform_probe+0x98/0x150
>       really_probe+0xfc/0x510
>       __driver_probe_device+0x17c/0x230
> <snip>
> ---[ end trace 0000000000000000 ]---
> Kernel panic - not syncing: Fatal exception
> 
> On investigation looks like this panic was caused due to a 'stat_buffer' of
> size==0 being provided to drc_pmem_query_stats() to fetch all performance
> stats-ids of an NVDIMM. However drc_pmem_query_stats() shouldn't have been called
> since the vPMEM NVDIMM doesn't support and performance stat-id's. This was caused
> due to missing check for 'p->stat_buffer_len' at the beginning of
> papr_scm_pmu_check_events() which indicates that the NVDIMM doesn't support
> performance-stats.
> 
> Fix this by introducing the check for 'p->stat_buffer_len' at the beginning of
> papr_scm_pmu_check_events().
> 
> [1] https://lore.kernel.org/all/6B3A522A-6A5F-4CC9-B268-0C63AA6E07D3@linux.ibm.com
> 
> Fixes: 0e0946e22f3665d2732 ("powerpc/papr_scm: Fix leaking nvdimm_events_map elements")
> Reported-by: Sachin Sant <sachinp@linux.ibm.com>
> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> ---

Thanks Vaibhav for the patch. With the patch the reported problem is fixed.

Tested-by: Sachin Sant <sachinp@linux.ibm.com>

-Sachin


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

* Re: [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
  2022-05-24 11:23 ` Vaibhav Jain
@ 2022-06-09 14:44   ` Michael Ellerman
  -1 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2022-06-09 14:44 UTC (permalink / raw)
  To: linuxppc-dev, Vaibhav Jain, nvdimm
  Cc: Michael Ellerman, Dan Williams, Aneesh Kumar K . V, Sachin Sant,
	Shivaprasad G Bhat

On Tue, 24 May 2022 16:53:53 +0530, Vaibhav Jain wrote:
> Sachin reported [1] that on a POWER-10 lpar he is seeing a kernel panic being
> reported with vPMEM when papr_scm probe is being called. The panic is of the
> form below and is observed only with following option disabled(profile) for the
> said LPAR 'Enable Performance Information Collection' in the HMC:
> 
>  Kernel attempted to write user page (1c) - exploit attempt? (uid: 0)
>  BUG: Kernel NULL pointer dereference on write at 0x0000001c
>  Faulting instruction address: 0xc008000001b90844
>  Oops: Kernel access of bad area, sig: 11 [#1]
> <snip>
>  NIP [c008000001b90844] drc_pmem_query_stats+0x5c/0x270 [papr_scm]
>  LR [c008000001b92794] papr_scm_probe+0x2ac/0x6ec [papr_scm]
>  Call Trace:
>        0xc00000000941bca0 (unreliable)
>        papr_scm_probe+0x2ac/0x6ec [papr_scm]
>        platform_probe+0x98/0x150
>        really_probe+0xfc/0x510
>        __driver_probe_device+0x17c/0x230
> <snip>
>  ---[ end trace 0000000000000000 ]---
>  Kernel panic - not syncing: Fatal exception
> 
> [...]

Applied to powerpc/fixes.

[1/1] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
      https://git.kernel.org/powerpc/c/07bf9431b1590d1cd7a8d62075d0b50b073f0495

cheers

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

* Re: [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
@ 2022-06-09 14:44   ` Michael Ellerman
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2022-06-09 14:44 UTC (permalink / raw)
  To: linuxppc-dev, Vaibhav Jain, nvdimm
  Cc: Dan Williams, Shivaprasad G Bhat, Sachin Sant, Aneesh Kumar K . V

On Tue, 24 May 2022 16:53:53 +0530, Vaibhav Jain wrote:
> Sachin reported [1] that on a POWER-10 lpar he is seeing a kernel panic being
> reported with vPMEM when papr_scm probe is being called. The panic is of the
> form below and is observed only with following option disabled(profile) for the
> said LPAR 'Enable Performance Information Collection' in the HMC:
> 
>  Kernel attempted to write user page (1c) - exploit attempt? (uid: 0)
>  BUG: Kernel NULL pointer dereference on write at 0x0000001c
>  Faulting instruction address: 0xc008000001b90844
>  Oops: Kernel access of bad area, sig: 11 [#1]
> <snip>
>  NIP [c008000001b90844] drc_pmem_query_stats+0x5c/0x270 [papr_scm]
>  LR [c008000001b92794] papr_scm_probe+0x2ac/0x6ec [papr_scm]
>  Call Trace:
>        0xc00000000941bca0 (unreliable)
>        papr_scm_probe+0x2ac/0x6ec [papr_scm]
>        platform_probe+0x98/0x150
>        really_probe+0xfc/0x510
>        __driver_probe_device+0x17c/0x230
> <snip>
>  ---[ end trace 0000000000000000 ]---
>  Kernel panic - not syncing: Fatal exception
> 
> [...]

Applied to powerpc/fixes.

[1/1] powerpc/papr_scm: don't requests stats with '0' sized stats buffer
      https://git.kernel.org/powerpc/c/07bf9431b1590d1cd7a8d62075d0b50b073f0495

cheers

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

end of thread, other threads:[~2022-06-09 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24 11:23 [PATCH] powerpc/papr_scm: don't requests stats with '0' sized stats buffer Vaibhav Jain
2022-05-24 11:23 ` Vaibhav Jain
2022-05-24 13:51 ` Sachin Sant
2022-05-24 13:51   ` Sachin Sant
2022-06-09 14:44 ` Michael Ellerman
2022-06-09 14:44   ` Michael Ellerman

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.