Commit 6bf0c9c0 authored by Vasily Gorbik's avatar Vasily Gorbik Committed by Kleber Sacilotto de Souza

s390/extmem: fix gcc 8 stringop-overflow warning

BugLink: https://bugs.launchpad.net/bugs/1798770

[ Upstream commit 6b2ddf33 ]

arch/s390/mm/extmem.c: In function '__segment_load':
arch/s390/mm/extmem.c:436:2: warning: 'strncat' specified bound 7 equals
source length [-Wstringop-overflow=]
  strncat(seg->res_name, " (DCSS)", 7);

What gcc complains about here is the misuse of strncat function, which
in this case does not limit a number of bytes taken from "src", so it is
in the end the same as strcat(seg->res_name, " (DCSS)");

Keeping in mind that a res_name is 15 bytes, strncat in this case
would overflow the buffer and write 0 into alignment byte between the
fields in the struct. To avoid that increasing res_name size to 16,
and reusing strlcat.
Reviewed-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 569cda7c
...@@ -79,7 +79,7 @@ struct qin64 { ...@@ -79,7 +79,7 @@ struct qin64 {
struct dcss_segment { struct dcss_segment {
struct list_head list; struct list_head list;
char dcss_name[8]; char dcss_name[8];
char res_name[15]; char res_name[16];
unsigned long start_addr; unsigned long start_addr;
unsigned long end; unsigned long end;
atomic_t ref_count; atomic_t ref_count;
...@@ -434,7 +434,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long ...@@ -434,7 +434,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
memcpy(&seg->res_name, seg->dcss_name, 8); memcpy(&seg->res_name, seg->dcss_name, 8);
EBCASC(seg->res_name, 8); EBCASC(seg->res_name, 8);
seg->res_name[8] = '\0'; seg->res_name[8] = '\0';
strncat(seg->res_name, " (DCSS)", 7); strlcat(seg->res_name, " (DCSS)", sizeof(seg->res_name));
seg->res->name = seg->res_name; seg->res->name = seg->res_name;
rc = seg->vm_segtype; rc = seg->vm_segtype;
if (rc == SEG_TYPE_SC || if (rc == SEG_TYPE_SC ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment