LinuxPPC-Dev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] powerpc/papr_scm: Fix an off-by-one check in papr_scm_meta_{get, set}
@ 2019-09-27  6:20 Vaibhav Jain
  2019-09-28 16:00 ` Aneesh Kumar K.V
  2019-10-12 10:00 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Vaibhav Jain @ 2019-09-27  6:20 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Vaibhav Jain, Oliver O'Halloran, Aneesh Kumar K . V

A validation check to prevent out of bounds read/write inside
functions papr_scm_meta_{get,set}() is off-by-one that prevent reads
and writes to the last byte of the label area.

This bug manifests as a failure to probe a dimm when libnvdimm is
unable to read the entire config-area as advertised by
ND_CMD_GET_CONFIG_SIZE. This usually happens when there are large
number of namespaces created in the region backed by the dimm and the
label-index spans max possible config-area. An error of the form below
usually reported in the kernel logs:

[  255.293912] nvdimm: probe of nmem0 failed with error -22

The patch fixes these validation checks there by letting libnvdimm
access the entire config-area.

Fixes: 53e80bd042773('powerpc/nvdimm: Add support for multibyte read/write for metadata')
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
---
 arch/powerpc/platforms/pseries/papr_scm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index a5ac371a3f06..0d0f4974a301 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -124,7 +124,7 @@ static int papr_scm_meta_get(struct papr_scm_priv *p,
 	int len, read;
 	int64_t ret;
 
-	if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)
+	if ((hdr->in_offset + hdr->in_length) > p->metadata_size)
 		return -EINVAL;
 
 	for (len = hdr->in_length; len; len -= read) {
@@ -178,7 +178,7 @@ static int papr_scm_meta_set(struct papr_scm_priv *p,
 	__be64 data_be;
 	int64_t ret;
 
-	if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)
+	if ((hdr->in_offset + hdr->in_length) > p->metadata_size)
 		return -EINVAL;
 
 	for (len = hdr->in_length; len; len -= wrote) {
-- 
2.21.0


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

* Re: [PATCH] powerpc/papr_scm: Fix an off-by-one check in papr_scm_meta_{get, set}
  2019-09-27  6:20 [PATCH] powerpc/papr_scm: Fix an off-by-one check in papr_scm_meta_{get, set} Vaibhav Jain
@ 2019-09-28 16:00 ` Aneesh Kumar K.V
  2019-10-12 10:00 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Aneesh Kumar K.V @ 2019-09-28 16:00 UTC (permalink / raw)
  To: Vaibhav Jain, linuxppc-dev; +Cc: Vaibhav Jain, Oliver O'Halloran

Vaibhav Jain <vaibhav@linux.ibm.com> writes:

> A validation check to prevent out of bounds read/write inside
> functions papr_scm_meta_{get,set}() is off-by-one that prevent reads
> and writes to the last byte of the label area.
>
> This bug manifests as a failure to probe a dimm when libnvdimm is
> unable to read the entire config-area as advertised by
> ND_CMD_GET_CONFIG_SIZE. This usually happens when there are large
> number of namespaces created in the region backed by the dimm and the
> label-index spans max possible config-area. An error of the form below
> usually reported in the kernel logs:
>
> [  255.293912] nvdimm: probe of nmem0 failed with error -22
>
> The patch fixes these validation checks there by letting libnvdimm
> access the entire config-area.
>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

> Fixes: 53e80bd042773('powerpc/nvdimm: Add support for multibyte read/write for metadata')
> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
> ---
>  arch/powerpc/platforms/pseries/papr_scm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
> index a5ac371a3f06..0d0f4974a301 100644
> --- a/arch/powerpc/platforms/pseries/papr_scm.c
> +++ b/arch/powerpc/platforms/pseries/papr_scm.c
> @@ -124,7 +124,7 @@ static int papr_scm_meta_get(struct papr_scm_priv *p,
>  	int len, read;
>  	int64_t ret;
>  
> -	if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)
> +	if ((hdr->in_offset + hdr->in_length) > p->metadata_size)
>  		return -EINVAL;
>  
>  	for (len = hdr->in_length; len; len -= read) {
> @@ -178,7 +178,7 @@ static int papr_scm_meta_set(struct papr_scm_priv *p,
>  	__be64 data_be;
>  	int64_t ret;
>  
> -	if ((hdr->in_offset + hdr->in_length) >= p->metadata_size)
> +	if ((hdr->in_offset + hdr->in_length) > p->metadata_size)
>  		return -EINVAL;
>  
>  	for (len = hdr->in_length; len; len -= wrote) {
> -- 
> 2.21.0

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

* Re: [PATCH] powerpc/papr_scm: Fix an off-by-one check in papr_scm_meta_{get, set}
  2019-09-27  6:20 [PATCH] powerpc/papr_scm: Fix an off-by-one check in papr_scm_meta_{get, set} Vaibhav Jain
  2019-09-28 16:00 ` Aneesh Kumar K.V
@ 2019-10-12 10:00 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2019-10-12 10:00 UTC (permalink / raw)
  To: Vaibhav Jain, linuxppc-dev
  Cc: Vaibhav Jain, Oliver O'Halloran, Aneesh Kumar K . V

On Fri, 2019-09-27 at 06:20:02 UTC, Vaibhav Jain wrote:
> A validation check to prevent out of bounds read/write inside
> functions papr_scm_meta_{get,set}() is off-by-one that prevent reads
> and writes to the last byte of the label area.
> 
> This bug manifests as a failure to probe a dimm when libnvdimm is
> unable to read the entire config-area as advertised by
> ND_CMD_GET_CONFIG_SIZE. This usually happens when there are large
> number of namespaces created in the region backed by the dimm and the
> label-index spans max possible config-area. An error of the form below
> usually reported in the kernel logs:
> 
> [  255.293912] nvdimm: probe of nmem0 failed with error -22
> 
> The patch fixes these validation checks there by letting libnvdimm
> access the entire config-area.
> 
> Fixes: 53e80bd042773('powerpc/nvdimm: Add support for multibyte read/write for metadata')
> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/612ee81b9461475b5a5612c2e8d71559dd3c7920

cheers

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27  6:20 [PATCH] powerpc/papr_scm: Fix an off-by-one check in papr_scm_meta_{get, set} Vaibhav Jain
2019-09-28 16:00 ` Aneesh Kumar K.V
2019-10-12 10:00 ` Michael Ellerman

LinuxPPC-Dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linuxppc-dev/0 linuxppc-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linuxppc-dev linuxppc-dev/ https://lore.kernel.org/linuxppc-dev \
		linuxppc-dev@lists.ozlabs.org linuxppc-dev@ozlabs.org
	public-inbox-index linuxppc-dev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linuxppc-dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git