Skip to contentSkip to conversation

Fix potential overlap dest buffer

PATCH Applied Nigel Croxon 4 participants 5 messages Aug 17, 2021 – Oct 8, 2021 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix potential overlap dest buffer

To meet requirements of Common Criteria certification vulnerablility assessment. Static code analysis has been run and found the following error. Overlapping_buffer: The source buffer potentially overlaps with the destination buffer, which results in undefined behavior for "memcpy".

The change is to use memmove instead of memcpy.

---
 sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sha1.c +1 -1
index 11be7045..89b32f46 100644
@@ -258,7 +258,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
 	{
 	  sha1_process_block (ctx->buffer, 64, ctx);
 	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
 	}
       ctx->buflen = left_over;
     }
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Nigel Croxon

To meet requirements of Common Criteria certification vulnerablility assessment. Static code analysis has been run and found the following error. Overlapping_buffer: The source buffer potentially overlaps with the destination buffer, which results in undefined behavior for "memcpy".

The change is to use memmove instead of memcpy.

Thanks,
NeilBrown

Quoted 21 lines
---
 sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sha1.c +1 -1
index 11be7045..89b32f46 100644
@@ -258,7 +258,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
 	{
 	  sha1_process_block (ctx->buffer, 64, ctx);
 	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
 	}
       ctx->buflen = left_over;
     }
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to Nigel Croxon

Dear Nigel,

Am 17.08.21 um 15:14 schrieb Nigel Croxon:

Quoted 1 line

To meet requirements of Common Criteria certification vulnerablility

vulnerability

Quoted 1 line

assessment.

That’s only part of a sentence? Is that supposed to be read as a continuation of the commit message summary: … to meet requirements …?

Quoted 2 lines

Static code analysis has been run and found the following error. Overlapping_buffer: The source buffer potentially overlaps

It’d be great, if you denoted, which tool was run. Maybe even add a Found-by tag.

Quoted 15 lines

with the destination buffer, which results in undefined behavior for "memcpy".

The change is to use memmove instead of memcpy.

---
  sha1.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
sha1.c +0 -0
index 11be7045..89b32f46 100644

sha1.c sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) · line 264

Quoted 8 lines
sha1.c +1 -1
@@ -258,7 +258,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
  	{
  	  sha1_process_block (ctx->buffer, 64, ctx);
  	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
  	}
        ctx->buflen = left_over;
      }

Kind regards,

Paul

#3 lore raw
Quoted 12 lines · Paul Menzel

Dear Nigel,

Am 17.08.21 um 15:14 schrieb Nigel Croxon:

Quoted 1 line

To meet requirements of Common Criteria certification vulnerablility

vulnerability

Quoted 1 line

assessment.

That’s only part of a sentence? Is that supposed to be read as a continuation of the commit message summary: … to meet requirements …?

Continuation of the commit message. Thanks for catching the spelling mistake.

Quoted 5 lines
Quoted 2 lines

Static code analysis has been run and found the following error.  Overlapping_buffer: The source buffer potentially overlaps

It’d be great, if you denoted, which tool was run. Maybe even add a Found-by tag.

I ran the Coverity scan on the latest build.
https://people.redhat.com/ncroxon/mdadm-4.2-rc2-scan-results.html

Quoted 32 lines
Quoted 23 lines

with the destination buffer, which results in undefined behavior for "memcpy".

The change is to use memmove instead of memcpy.

---
  sha1.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
sha1.c +1 -1
index 11be7045..89b32f46 100644
@@ -258,7 +258,7 @@ sha1_process_bytes (const void *buffer, size_t 
 len, struct sha1_ctx *ctx)
       {
         sha1_process_block (ctx->buffer, 64, ctx);
         left_over -= 64;
-      memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+      memmove (ctx->buffer, &ctx->buffer[16], left_over);
       }
         ctx->buflen = left_over;
Quoted 1 line

      }

Kind regards,

Paul

Applied
#4 lore raw
In reply to Nigel Croxon
Quoted 19 lines · Nigel Croxon

To meet requirements of Common Criteria certification vulnerablility assessment. Static code analysis has been run and found the following error. Overlapping_buffer: The source buffer potentially overlaps with the destination buffer, which results in undefined behavior for "memcpy".

The change is to use memmove instead of memcpy.

---
 sha1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sha1.c +0 -0
index 11be7045..89b32f46 100644

sha1.c sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) · line 264

Quoted 8 lines
sha1.c +1 -1
@@ -258,7 +258,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
 	{
 	  sha1_process_block (ctx->buffer, 64, ctx);
 	  left_over -= 64;
-	  memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+	  memmove (ctx->buffer, &ctx->buffer[16], left_over);
 	}
       ctx->buflen = left_over;
     }

Applied!

Thanks,
Jes