From 80970472179a45609c0b11b80619bc8c32b15f77 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 13 Sep 2013 14:51:40 -0700 Subject: Makefile: enable -Werror=implicit-int and -Werror=strict-prototypes by default The common error found in forward-ported/backported patches is missing headers. One recent example (files and function names are mangled): void foo(){} EXPORT_SYMBOL(foo); gave only warning foo.c:12345678:5: warning: function declaration isn't a prototype [-Wstrict-prototypes] void foo(){} ^ foo.c:12345679:5: warning: data definition has no type or storage class [enabled by default] EXPORT_SYMBOL(foo); foo.c:12345679:5: warning: type defaults to 'int' in declaration of 'EXORT_SYMBOL' [-Werror=implicit-int] Now it's a fatal error. Tested on x86_64 allyesconfig. [akpm@linux-foundation.org: fix typos in comments] Signed-off-by: Sergei Trofimovich Cc: Geert Uytterhoeven Signed-off-by: Andrew Morton Signed-off-by: Michal Marek diff --git a/Makefile b/Makefile index de004ce..c060363 100644 --- a/Makefile +++ b/Makefile @@ -659,6 +659,12 @@ KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow) # conserve stack if available KBUILD_CFLAGS += $(call cc-option,-fconserve-stack) +# disallow errors like 'EXPORT_GPL(foo);' with missing header +KBUILD_CFLAGS += $(call cc-option,-Werror=implicit-int) + +# require functions to have arguments in prototypes, not empty 'int foo()' +KBUILD_CFLAGS += $(call cc-option,-Werror=strict-prototypes) + # use the deterministic mode of AR if available KBUILD_ARFLAGS := $(call ar-option,D) -- cgit v0.10.2 From eea0e9cbb9e65cd553d302a4aefd4c7b70d9fd90 Mon Sep 17 00:00:00 2001 From: Joe Mario Date: Wed, 23 Oct 2013 15:06:53 +0200 Subject: kbuild: Increase kallsyms max symbol length [AK: This seems like a ticking time bomb even without LTO, so should be merged now. It causes very weird problems. Thanks to Joe for tracking them down.] With the added postfixes that LTO adds for local symbols, the longest name in the kernel overflows the namebuf[KSYM_NAME_LEN] array by two bytes. That name is: __pci_fixup_resumePCI_VENDOR_ID_SERVERWORKSPCI_DEVICE_ID_SERVERWORKS_HT1000SBquirk_disable_broadcom_boot_interrupt.1488004.672802 Double the max symbol name length. v2: Use 255 (Joe Perches) Signed-off-by: Andi Kleen Signed-off-by: Michal Marek diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index 6883e19..5648870 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -9,7 +9,7 @@ #include #include -#define KSYM_NAME_LEN 128 +#define KSYM_NAME_LEN 255 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) -- cgit v0.10.2 From f3462aa952cfc8f4b095103cb9b3d306dd216558 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Wed, 23 Oct 2013 15:07:53 +0200 Subject: Kbuild: Handle longer symbols in kallsyms.c Also warn for too long symbols v2: Add missing newline. Use 255 max (Joe Perches) Signed-off-by: Andi Kleen Signed-off-by: Michal Marek diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 487ac6f..967522a 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -27,7 +27,7 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #endif -#define KSYM_NAME_LEN 128 +#define KSYM_NAME_LEN 255 struct sym_entry { unsigned long long addr; @@ -111,6 +111,12 @@ static int read_symbol(FILE *in, struct sym_entry *s) fprintf(stderr, "Read error or end of file.\n"); return -1; } + if (strlen(str) > KSYM_NAME_LEN) { + fprintf(stderr, "Symbol %s too long for kallsyms (%lu vs %d).\n" + "Please increase KSYM_NAME_LEN both in kernel and kallsyms.c\n", + str, strlen(str), KSYM_NAME_LEN); + return -1; + } sym = str; /* skip prefix char */ -- cgit v0.10.2 From 21cf6e584ce35b79374581e6344dd7c74f8b4a2b Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Tue, 22 Oct 2013 08:46:23 -0700 Subject: kbuild, bloat-o-meter: fix static detection Disable static detection: the static currently drops a lot of useful information including clones generated by gcc. Drop this. The statics will appear now without static. prefix. But remove the LTO .NUMBER postfixes that look ugly Signed-off-by: Andi Kleen Signed-off-by: Michal Marek diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index 6129020..855198c 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -20,8 +20,8 @@ def getsizes(file): if type in "tTdDbBrR": # strip generated symbols if name[:6] == "__mod_": continue - # function names begin with '.' on 64-bit powerpc - if "." in name[1:]: name = "static." + name.split(".")[0] + # statics and some other optimizations adds random .NUMBER + name = re.sub(r'\.[0-9]+', '', name) sym[name] = sym.get(name, 0) + int(size, 16) return sym -- cgit v0.10.2 From 849464d1ba97a13b388fee9a69fbbeee175b349c Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 25 Oct 2013 06:14:43 -0700 Subject: kbuild: replace unbounded sprintf call in modpost The modpost tool could overflow its stack buffer if someone was running with an insane shell environment. Regardless, it's technically a bug, so this fixes it to truncate the string instead of seg-faulting. Found by Coverity. Signed-off-by: Kees Cook Signed-off-by: Michal Marek diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c index 9dfcd6d..deb2994 100644 --- a/scripts/mod/sumversion.c +++ b/scripts/mod/sumversion.c @@ -416,7 +416,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen) basename = strrchr(modname, '/') + 1; else basename = modname; - sprintf(filelist, "%s/%.*s.mod", modverdir, + snprintf(filelist, sizeof(filelist), "%s/%.*s.mod", modverdir, (int) strlen(basename) - 2, basename); file = grab_file(filelist, &len); -- cgit v0.10.2 From 5a7b2d27960c7390f1729b6b81eaf94d9e7f3837 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 7 Nov 2013 12:03:06 +1100 Subject: scripts/bloat-o-meter: ignore changes in the size of linux_banner linux_banner can change size due to changes in the compiler, build number, or the user@host the system was compiled on; ignore size changes in linux_banner entirely. Signed-off-by: Josh Triplett Signed-off-by: Andrew Morton Signed-off-by: Michal Marek diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index 855198c..cd2916c 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -20,6 +20,7 @@ def getsizes(file): if type in "tTdDbBrR": # strip generated symbols if name[:6] == "__mod_": continue + if name == "linux_banner": continue # statics and some other optimizations adds random .NUMBER name = re.sub(r'\.[0-9]+', '', name) sym[name] = sym.get(name, 0) + int(size, 16) -- cgit v0.10.2 From c2e182fab04c1fb50e7dac05d0fd78d331225ad0 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 7 Nov 2013 12:03:06 +1100 Subject: scripts/bloat-o-meter: use .startswith rather than fragile slicing str.startswith has existed since at least Python 2.0, in 2000; use it rather than a fragile comparison against an initial slice of a string, which requires hard-coding the length of the string to compare against. Signed-off-by: Josh Triplett Signed-off-by: Andrew Morton Signed-off-by: Michal Marek diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index cd2916c..549d0ab 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -19,7 +19,7 @@ def getsizes(file): size, type, name = l[:-1].split() if type in "tTdDbBrR": # strip generated symbols - if name[:6] == "__mod_": continue + if name.startswith("__mod_"): continue if name == "linux_banner": continue # statics and some other optimizations adds random .NUMBER name = re.sub(r'\.[0-9]+', '', name) -- cgit v0.10.2 From 6f62259b1a7696a335d5c3f2c89cce1d28912bf2 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Fri, 8 Nov 2013 00:45:01 -0200 Subject: scripts: kallsyms: Use %zu to print 'size_t' Commit f3462aa95 (Kbuild: Handle longer symbols in kallsyms.c) introduced the following warning on ARM: scripts/kallsyms.c:121:4: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' [-Wformat] Use %zu to print 'size_t'. Signed-off-by: Fabio Estevam Signed-off-by: Michal Marek diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 967522a..48afa20 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -112,7 +112,7 @@ static int read_symbol(FILE *in, struct sym_entry *s) return -1; } if (strlen(str) > KSYM_NAME_LEN) { - fprintf(stderr, "Symbol %s too long for kallsyms (%lu vs %d).\n" + fprintf(stderr, "Symbol %s too long for kallsyms (%zu vs %d).\n" "Please increase KSYM_NAME_LEN both in kernel and kallsyms.c\n", str, strlen(str), KSYM_NAME_LEN); return -1; -- cgit v0.10.2 From ab7474ea5361f5fe883feb5ae637a1c948df1507 Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Mon, 11 Nov 2013 15:27:43 +0100 Subject: Kbuild: Ignore GREP_OPTIONS env variable When building the kernel in a shell which defines GREP_OPTIONS so that grep behavior is modified, we can break the generation of the syscalls table like so: __SYSCALL_COMMON(^[[01;31m^[[K0^[[m^[[K, sys_read, sys_read) __SYSCALL_COMMON(^[[01;31m^[[K1^[[m^[[K, sys_write, sys_write) __SYSCALL_COMMON(^[[01;31m^[[K1^[[m^[[K0, sys_mprotect, sys_mprotect) ... This is just the initial breakage, later we barf when generating modules. In this case, GREP_OPTIONS contains "--color=always" which adds the shell colors markup and completely fudges the headers under ...generated/asm/. Fix that by unexporting the GREP_OPTIONS variable for the whole kernel build as we tend to use grep at a bunch of places. Signed-off-by: Borislav Petkov Signed-off-by: Michal Marek diff --git a/Makefile b/Makefile index c060363..2f6c0e9 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ LC_COLLATE=C LC_NUMERIC=C export LC_COLLATE LC_NUMERIC +# Avoid interference with shell env settings +unexport GREP_OPTIONS + # We are using a recursive build, so we need to do a little thinking # to get the ordering right. # -- cgit v0.10.2 From 480f439c3db0d45d817d66caf3fa8e81a6fac01a Mon Sep 17 00:00:00 2001 From: Michal Marek Date: Mon, 11 Nov 2013 14:23:08 +0100 Subject: kallsyms: Revert back to 128 max symbol length This reverts commits f3462aa (Kbuild: Handle longer symbols in kallsyms.c) and eea0e9c (kbuild: Increase kallsyms max symbol length) except for the added overflow check. The reason is a regression caused by increasing the buffer: http://marc.info/?l=linux-kernel&m=138387700415675. Reported-by: Fengguang Wu Cc: Andi Kleen Cc: Joe Mario Signed-off-by: Michal Marek diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index 5648870..6883e19 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -9,7 +9,7 @@ #include #include -#define KSYM_NAME_LEN 255 +#define KSYM_NAME_LEN 128 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \ 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 48afa20..518da86 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -27,7 +27,7 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #endif -#define KSYM_NAME_LEN 255 +#define KSYM_NAME_LEN 128 struct sym_entry { unsigned long long addr; -- cgit v0.10.2