Miroslav Franc 18ebb4
From: Vasily Gorbik <gor@linux.ibm.com>
Miroslav Franc 18ebb4
Date: Sun, 17 Jun 2018 00:30:43 +0200
Miroslav Franc 18ebb4
Subject: s390/extmem: fix gcc 8 stringop-overflow warning
Miroslav Franc 18ebb4
Git-commit: 6b2ddf33baec23dace85bd647e3fc4ac070963e8
Miroslav Franc 18ebb4
Patch-mainline: v4.19-rc1
Miroslav Franc 18ebb4
References: git-fixes bsc#1211363
Miroslav Franc 18ebb4
Miroslav Franc 18ebb4
arch/s390/mm/extmem.c: In function '__segment_load':
Miroslav Franc 18ebb4
arch/s390/mm/extmem.c:436:2: warning: 'strncat' specified bound 7 equals
Miroslav Franc 18ebb4
source length [-Wstringop-overflow=]
Miroslav Franc 18ebb4
  strncat(seg->res_name, " (DCSS)", 7);
Miroslav Franc 18ebb4
Miroslav Franc 18ebb4
What gcc complains about here is the misuse of strncat function, which
Miroslav Franc 18ebb4
in this case does not limit a number of bytes taken from "src", so it is
Miroslav Franc 18ebb4
in the end the same as strcat(seg->res_name, " (DCSS)");
Miroslav Franc 18ebb4
Miroslav Franc 18ebb4
Keeping in mind that a res_name is 15 bytes, strncat in this case
Miroslav Franc 18ebb4
would overflow the buffer and write 0 into alignment byte between the
Miroslav Franc 18ebb4
fields in the struct. To avoid that increasing res_name size to 16,
Miroslav Franc 18ebb4
and reusing strlcat.
Miroslav Franc 18ebb4
Miroslav Franc 18ebb4
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Miroslav Franc 18ebb4
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Miroslav Franc 18ebb4
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Miroslav Franc 18ebb4
Acked-by: Miroslav Franc <mfranc@suse.cz>
Miroslav Franc 18ebb4
---
Miroslav Franc 18ebb4
 arch/s390/mm/extmem.c | 4 ++--
Miroslav Franc 18ebb4
 1 file changed, 2 insertions(+), 2 deletions(-)
Miroslav Franc 18ebb4
Miroslav Franc 18ebb4
diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
Miroslav Franc 18ebb4
index 6ad15d3fab81..84111a43ea29 100644
Miroslav Franc 18ebb4
--- a/arch/s390/mm/extmem.c
Miroslav Franc 18ebb4
+++ b/arch/s390/mm/extmem.c
Miroslav Franc 18ebb4
@@ -80,7 +80,7 @@ struct qin64 {
Miroslav Franc 18ebb4
 struct dcss_segment {
Miroslav Franc 18ebb4
 	struct list_head list;
Miroslav Franc 18ebb4
 	char dcss_name[8];
Miroslav Franc 18ebb4
-	char res_name[15];
Miroslav Franc 18ebb4
+	char res_name[16];
Miroslav Franc 18ebb4
 	unsigned long start_addr;
Miroslav Franc 18ebb4
 	unsigned long end;
Miroslav Franc 18ebb4
 	atomic_t ref_count;
Miroslav Franc 18ebb4
@@ -433,7 +433,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
Miroslav Franc 18ebb4
 	memcpy(&seg->res_name, seg->dcss_name, 8);
Miroslav Franc 18ebb4
 	EBCASC(seg->res_name, 8);
Miroslav Franc 18ebb4
 	seg->res_name[8] = '\0';
Miroslav Franc 18ebb4
-	strncat(seg->res_name, " (DCSS)", 7);
Miroslav Franc 18ebb4
+	strlcat(seg->res_name, " (DCSS)", sizeof(seg->res_name));
Miroslav Franc 18ebb4
 	seg->res->name = seg->res_name;
Miroslav Franc 18ebb4
 	rc = seg->vm_segtype;
Miroslav Franc 18ebb4
 	if (rc == SEG_TYPE_SC ||
Miroslav Franc 18ebb4