]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 5.15
authorSasha Levin <sashal@kernel.org>
Mon, 3 Feb 2025 16:25:50 +0000 (11:25 -0500)
committerSasha Levin <sashal@kernel.org>
Mon, 3 Feb 2025 16:25:50 +0000 (11:25 -0500)
Signed-off-by: Sasha Levin <sashal@kernel.org>
12 files changed:
queue-5.15/genksyms-fix-memory-leak-when-the-same-symbol-is-add.patch [new file with mode: 0644]
queue-5.15/genksyms-fix-memory-leak-when-the-same-symbol-is-rea.patch [new file with mode: 0644]
queue-5.15/hexagon-fix-unbalanced-spinlock-in-die.patch [new file with mode: 0644]
queue-5.15/hexagon-fix-using-plain-integer-as-null-pointer-warn.patch [new file with mode: 0644]
queue-5.15/kconfig-add-warn-unknown-symbols-sanity-check.patch [new file with mode: 0644]
queue-5.15/kconfig-deduplicate-code-in-conf_read_simple.patch [new file with mode: 0644]
queue-5.15/kconfig-fix-file-name-in-warnings-when-loading-kconf.patch [new file with mode: 0644]
queue-5.15/kconfig-fix-memory-leak-in-sym_warn_unmet_dep.patch [new file with mode: 0644]
queue-5.15/kconfig-remove-unused-code-for-s_def_auto-in-conf_re.patch [new file with mode: 0644]
queue-5.15/kconfig-require-a-space-after-for-valid-input.patch [new file with mode: 0644]
queue-5.15/kconfig-werror-unmet-symbol-dependency.patch [new file with mode: 0644]
queue-5.15/series

diff --git a/queue-5.15/genksyms-fix-memory-leak-when-the-same-symbol-is-add.patch b/queue-5.15/genksyms-fix-memory-leak-when-the-same-symbol-is-add.patch
new file mode 100644 (file)
index 0000000..42f50fe
--- /dev/null
@@ -0,0 +1,149 @@
+From c437531b6e0f09335ed0cfd36a5103a8cb59f4fe Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 3 Jan 2025 16:30:38 +0900
+Subject: genksyms: fix memory leak when the same symbol is added from source
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit 45c9c4101d3d2fdfa00852274bbebba65fcc3cf2 ]
+
+When a symbol that is already registered is added again, __add_symbol()
+returns without freeing the symbol definition, making it unreachable.
+
+The following test cases demonstrate different memory leak points.
+
+[Test Case 1]
+
+Forward declaration with exactly the same definition
+
+  $ cat foo.c
+  #include <linux/export.h>
+  void foo(void);
+  void foo(void) {}
+  EXPORT_SYMBOL(foo);
+
+[Test Case 2]
+
+Forward declaration with a different definition (e.g. attribute)
+
+  $ cat foo.c
+  #include <linux/export.h>
+  void foo(void);
+  __attribute__((__section__(".ref.text"))) void foo(void) {}
+  EXPORT_SYMBOL(foo);
+
+[Test Case 3]
+
+Preserving an overridden symbol (compile with KBUILD_PRESERVE=1)
+
+  $ cat foo.c
+  #include <linux/export.h>
+  void foo(void);
+  void foo(void) { }
+  EXPORT_SYMBOL(foo);
+
+  $ cat foo.symref
+  override foo void foo ( int )
+
+The memory leaks in Test Case 1 and 2 have existed since the introduction
+of genksyms into the kernel tree. [1]
+
+The memory leak in Test Case 3 was introduced by commit 5dae9a550a74
+("genksyms: allow to ignore symbol checksum changes").
+
+When multiple init_declarators are reduced to an init_declarator_list,
+the decl_spec must be duplicated. Otherwise, the following Test Case 4
+would result in a double-free bug.
+
+[Test Case 4]
+
+  $ cat foo.c
+  #include <linux/export.h>
+
+  extern int foo, bar;
+
+  int foo, bar;
+  EXPORT_SYMBOL(foo);
+
+In this case, 'foo' and 'bar' share the same decl_spec, 'int'. It must
+be unshared before being passed to add_symbol().
+
+[1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=46bd1da672d66ccd8a639d3c1f8a166048cca608
+
+Fixes: 5dae9a550a74 ("genksyms: allow to ignore symbol checksum changes")
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/genksyms/genksyms.c |  3 +++
+ scripts/genksyms/parse.y    | 14 ++++++++++++--
+ 2 files changed, 15 insertions(+), 2 deletions(-)
+
+diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
+index 4827c5abe5b71..de64aea6e8b4c 100644
+--- a/scripts/genksyms/genksyms.c
++++ b/scripts/genksyms/genksyms.c
+@@ -241,6 +241,7 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
+                                               "unchanged\n");
+                               }
+                               sym->is_declared = 1;
++                              free_list(defn, NULL);
+                               return sym;
+                       } else if (!sym->is_declared) {
+                               if (sym->is_override && flag_preserve) {
+@@ -249,6 +250,7 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
+                                       print_type_name(type, name);
+                                       fprintf(stderr, " modversion change\n");
+                                       sym->is_declared = 1;
++                                      free_list(defn, NULL);
+                                       return sym;
+                               } else {
+                                       status = is_unknown_symbol(sym) ?
+@@ -256,6 +258,7 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
+                               }
+                       } else {
+                               error_with_pos("redefinition of %s", name);
++                              free_list(defn, NULL);
+                               return sym;
+                       }
+                       break;
+diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
+index 8e9b5e69e8f01..840371d01bf48 100644
+--- a/scripts/genksyms/parse.y
++++ b/scripts/genksyms/parse.y
+@@ -152,14 +152,19 @@ simple_declaration:
+       ;
+ init_declarator_list_opt:
+-      /* empty */                             { $$ = NULL; }
+-      | init_declarator_list
++      /* empty */                     { $$ = NULL; }
++      | init_declarator_list          { free_list(decl_spec, NULL); $$ = $1; }
+       ;
+ init_declarator_list:
+       init_declarator
+               { struct string_list *decl = *$1;
+                 *$1 = NULL;
++
++                /* avoid sharing among multiple init_declarators */
++                if (decl_spec)
++                  decl_spec = copy_list_range(decl_spec, NULL);
++
+                 add_symbol(current_name,
+                            is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern);
+                 current_name = NULL;
+@@ -170,6 +175,11 @@ init_declarator_list:
+                 *$3 = NULL;
+                 free_list(*$2, NULL);
+                 *$2 = decl_spec;
++
++                /* avoid sharing among multiple init_declarators */
++                if (decl_spec)
++                  decl_spec = copy_list_range(decl_spec, NULL);
++
+                 add_symbol(current_name,
+                            is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern);
+                 current_name = NULL;
+-- 
+2.39.5
+
diff --git a/queue-5.15/genksyms-fix-memory-leak-when-the-same-symbol-is-rea.patch b/queue-5.15/genksyms-fix-memory-leak-when-the-same-symbol-is-rea.patch
new file mode 100644 (file)
index 0000000..34b4baa
--- /dev/null
@@ -0,0 +1,108 @@
+From 6bf4874dbc4d78f7444692767625fe5d93baf72d Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 3 Jan 2025 16:30:39 +0900
+Subject: genksyms: fix memory leak when the same symbol is read from *.symref
+ file
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit be2fa44b5180a1f021efb40c55fdf63c249c3209 ]
+
+When a symbol that is already registered is read again from *.symref
+file, __add_symbol() removes the previous one from the hash table without
+freeing it.
+
+[Test Case]
+
+  $ cat foo.c
+  #include <linux/export.h>
+  void foo(void);
+  void foo(void) {}
+  EXPORT_SYMBOL(foo);
+
+  $ cat foo.symref
+  foo void foo ( void )
+  foo void foo ( void )
+
+When a symbol is removed from the hash table, it must be freed along
+with its ->name and ->defn members. However, sym->name cannot be freed
+because it is sometimes shared with node->string, but not always. If
+sym->name and node->string share the same memory, free(sym->name) could
+lead to a double-free bug.
+
+To resolve this issue, always assign a strdup'ed string to sym->name.
+
+Fixes: 64e6c1e12372 ("genksyms: track symbol checksum changes")
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/genksyms/genksyms.c | 8 ++++++--
+ scripts/genksyms/genksyms.h | 2 +-
+ scripts/genksyms/parse.y    | 4 ++--
+ 3 files changed, 9 insertions(+), 5 deletions(-)
+
+diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
+index de64aea6e8b4c..0c4d780fbbd83 100644
+--- a/scripts/genksyms/genksyms.c
++++ b/scripts/genksyms/genksyms.c
+@@ -274,11 +274,15 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
+                               break;
+                       }
+               }
++
++              free_list(sym->defn, NULL);
++              free(sym->name);
++              free(sym);
+               --nsyms;
+       }
+       sym = xmalloc(sizeof(*sym));
+-      sym->name = name;
++      sym->name = xstrdup(name);
+       sym->type = type;
+       sym->defn = defn;
+       sym->expansion_trail = NULL;
+@@ -485,7 +489,7 @@ static void read_reference(FILE *f)
+                       defn = def;
+                       def = read_node(f);
+               }
+-              subsym = add_reference_symbol(xstrdup(sym->string), sym->tag,
++              subsym = add_reference_symbol(sym->string, sym->tag,
+                                             defn, is_extern);
+               subsym->is_override = is_override;
+               free_node(sym);
+diff --git a/scripts/genksyms/genksyms.h b/scripts/genksyms/genksyms.h
+index 21ed2ec2d98ca..5621533dcb8e4 100644
+--- a/scripts/genksyms/genksyms.h
++++ b/scripts/genksyms/genksyms.h
+@@ -32,7 +32,7 @@ struct string_list {
+ struct symbol {
+       struct symbol *hash_next;
+-      const char *name;
++      char *name;
+       enum symbol_type type;
+       struct string_list *defn;
+       struct symbol *expansion_trail;
+diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
+index 840371d01bf48..689cb6bb40b65 100644
+--- a/scripts/genksyms/parse.y
++++ b/scripts/genksyms/parse.y
+@@ -482,12 +482,12 @@ enumerator_list:
+ enumerator:
+       IDENT
+               {
+-                      const char *name = strdup((*$1)->string);
++                      const char *name = (*$1)->string;
+                       add_symbol(name, SYM_ENUM_CONST, NULL, 0);
+               }
+       | IDENT '=' EXPRESSION_PHRASE
+               {
+-                      const char *name = strdup((*$1)->string);
++                      const char *name = (*$1)->string;
+                       struct string_list *expr = copy_list_range(*$3, *$2);
+                       add_symbol(name, SYM_ENUM_CONST, expr, 0);
+               }
+-- 
+2.39.5
+
diff --git a/queue-5.15/hexagon-fix-unbalanced-spinlock-in-die.patch b/queue-5.15/hexagon-fix-unbalanced-spinlock-in-die.patch
new file mode 100644 (file)
index 0000000..bc1f0a0
--- /dev/null
@@ -0,0 +1,45 @@
+From 7a3603f439daaa8b7fbb41efc206c0cf1774450c Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Mon, 22 May 2023 02:56:08 +0000
+Subject: hexagon: Fix unbalanced spinlock in die()
+
+From: Lin Yujun <linyujun809@huawei.com>
+
+[ Upstream commit 03410e87563a122075c3721acc7d5510e41d8332 ]
+
+die executes holding the spinlock of &die.lock and unlock
+it after printing the oops message.
+However in the code if the notify_die() returns NOTIFY_STOP
+, die() exit with returning 1 but never unlocked the spinlock.
+
+Fix this by adding spin_unlock_irq(&die.lock) before returning.
+
+Fixes: cf9750bae262 ("Hexagon: Provide basic debugging and system trap support.")
+Signed-off-by: Lin Yujun <linyujun809@huawei.com>
+Link: https://lore.kernel.org/r/20230522025608.2515558-1-linyujun809@huawei.com
+Signed-off-by: Brian Cain <bcain@quicinc.com>
+Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ arch/hexagon/kernel/traps.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/arch/hexagon/kernel/traps.c b/arch/hexagon/kernel/traps.c
+index 1240f038cce02..7aca1c329f944 100644
+--- a/arch/hexagon/kernel/traps.c
++++ b/arch/hexagon/kernel/traps.c
+@@ -195,8 +195,10 @@ int die(const char *str, struct pt_regs *regs, long err)
+       printk(KERN_EMERG "Oops: %s[#%d]:\n", str, ++die.counter);
+       if (notify_die(DIE_OOPS, str, regs, err, pt_cause(regs), SIGSEGV) ==
+-          NOTIFY_STOP)
++          NOTIFY_STOP) {
++              spin_unlock_irq(&die.lock);
+               return 1;
++      }
+       print_modules();
+       show_regs(regs);
+-- 
+2.39.5
+
diff --git a/queue-5.15/hexagon-fix-using-plain-integer-as-null-pointer-warn.patch b/queue-5.15/hexagon-fix-using-plain-integer-as-null-pointer-warn.patch
new file mode 100644 (file)
index 0000000..35d8dd5
--- /dev/null
@@ -0,0 +1,61 @@
+From 60bee7cfefa6dc1032291ad379c66e68251ec372 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Tue, 3 Dec 2024 17:17:34 -0500
+Subject: hexagon: fix using plain integer as NULL pointer warning in cmpxchg
+
+From: Willem de Bruijn <willemb@google.com>
+
+[ Upstream commit 8a20030038742b9915c6d811a4e6c14b126cafb4 ]
+
+Sparse reports
+
+    net/ipv4/inet_diag.c:1511:17: sparse: sparse: Using plain integer as NULL pointer
+
+Due to this code calling cmpxchg on a non-integer type
+struct inet_diag_handler *
+
+    return !cmpxchg((const struct inet_diag_handler**)&inet_diag_table[type],
+                    NULL, h) ? 0 : -EEXIST;
+
+While hexagon's cmpxchg assigns an integer value to a variable of this
+type.
+
+    __typeof__(*(ptr)) __oldval = 0;
+
+Update this assignment to cast 0 to the correct type.
+
+The original issue is easily reproduced at head with the below block,
+and is absent after this change.
+
+    make LLVM=1 ARCH=hexagon defconfig
+    make C=1 LLVM=1 ARCH=hexagon net/ipv4/inet_diag.o
+
+Fixes: 99a70aa051d2 ("Hexagon: Add processor and system headers")
+Reported-by: kernel test robot <lkp@intel.com>
+Closes: https://lore.kernel.org/oe-kbuild-all/202411091538.PGSTqUBi-lkp@intel.com/
+Signed-off-by: Willem de Bruijn <willemb@google.com>
+Tested-by: Christian Gmeiner <cgmeiner@igalia.com>
+Link: https://lore.kernel.org/r/20241203221736.282020-1-willemdebruijn.kernel@gmail.com
+Signed-off-by: Brian Cain <bcain@quicinc.com>
+Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ arch/hexagon/include/asm/cmpxchg.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/arch/hexagon/include/asm/cmpxchg.h b/arch/hexagon/include/asm/cmpxchg.h
+index cdb705e1496af..72c6e16c3f237 100644
+--- a/arch/hexagon/include/asm/cmpxchg.h
++++ b/arch/hexagon/include/asm/cmpxchg.h
+@@ -56,7 +56,7 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
+       __typeof__(ptr) __ptr = (ptr);                          \
+       __typeof__(*(ptr)) __old = (old);                       \
+       __typeof__(*(ptr)) __new = (new);                       \
+-      __typeof__(*(ptr)) __oldval = 0;                        \
++      __typeof__(*(ptr)) __oldval = (__typeof__(*(ptr))) 0;   \
+                                                               \
+       asm volatile(                                           \
+               "1:     %0 = memw_locked(%1);\n"                \
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-add-warn-unknown-symbols-sanity-check.patch b/queue-5.15/kconfig-add-warn-unknown-symbols-sanity-check.patch
new file mode 100644 (file)
index 0000000..60a911c
--- /dev/null
@@ -0,0 +1,115 @@
+From f5fb5fc2e72109cf56b58a4f998078779548ac0c Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 30 Aug 2023 09:49:36 +0900
+Subject: kconfig: add warn-unknown-symbols sanity check
+
+From: Sergey Senozhatsky <senozhatsky@chromium.org>
+
+[ Upstream commit 7cd343008b967423b06af8f6d3236749c67d12e8 ]
+
+Introduce KCONFIG_WARN_UNKNOWN_SYMBOLS environment variable,
+which makes Kconfig warn about unknown config symbols.
+
+This is especially useful for continuous kernel uprevs when
+some symbols can be either removed or renamed between kernel
+releases (which can go unnoticed otherwise).
+
+By default KCONFIG_WARN_UNKNOWN_SYMBOLS generates warnings,
+which are non-terminal. There is an additional environment
+variable KCONFIG_WERROR that overrides this behaviour and
+turns warnings into errors.
+
+Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Stable-dep-of: a409fc1463d6 ("kconfig: fix memory leak in sym_warn_unmet_dep()")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ Documentation/kbuild/kconfig.rst |  9 +++++++++
+ scripts/kconfig/confdata.c       | 21 +++++++++++++++++++--
+ 2 files changed, 28 insertions(+), 2 deletions(-)
+
+diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst
+index 5967c79c3baa7..eee0d298774ab 100644
+--- a/Documentation/kbuild/kconfig.rst
++++ b/Documentation/kbuild/kconfig.rst
+@@ -54,6 +54,15 @@ KCONFIG_OVERWRITECONFIG
+ If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not
+ break symlinks when .config is a symlink to somewhere else.
++KCONFIG_WARN_UNKNOWN_SYMBOLS
++----------------------------
++This environment variable makes Kconfig warn about all unrecognized
++symbols in the config input.
++
++KCONFIG_WERROR
++--------------
++If set, Kconfig treats warnings as errors.
++
+ `CONFIG_`
+ ---------
+ If you set `CONFIG_` in the environment, Kconfig will prefix all symbols
+diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+index 469450b0a5176..033f2882436d3 100644
+--- a/scripts/kconfig/confdata.c
++++ b/scripts/kconfig/confdata.c
+@@ -351,7 +351,11 @@ int conf_read_simple(const char *name, int def)
+       char *p, *p2;
+       struct symbol *sym;
+       int i, def_flags;
++      const char *warn_unknown;
++      const char *werror;
++      warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
++      werror = getenv("KCONFIG_WERROR");
+       if (name) {
+               in = zconf_fopen(name);
+       } else {
+@@ -441,6 +445,10 @@ int conf_read_simple(const char *name, int def)
+                       if (def == S_DEF_USER) {
+                               sym = sym_find(line + 2 + strlen(CONFIG_));
+                               if (!sym) {
++                                      if (warn_unknown)
++                                              conf_warning("unknown symbol: %s",
++                                                           line + 2 + strlen(CONFIG_));
++
+                                       conf_set_changed(true);
+                                       continue;
+                               }
+@@ -475,7 +483,7 @@ int conf_read_simple(const char *name, int def)
+                       sym = sym_find(line + strlen(CONFIG_));
+                       if (!sym) {
+-                              if (def == S_DEF_AUTO)
++                              if (def == S_DEF_AUTO) {
+                                       /*
+                                        * Reading from include/config/auto.conf
+                                        * If CONFIG_FOO previously existed in
+@@ -483,8 +491,13 @@ int conf_read_simple(const char *name, int def)
+                                        * include/config/FOO must be touched.
+                                        */
+                                       conf_touch_dep(line + strlen(CONFIG_));
+-                              else
++                              } else {
++                                      if (warn_unknown)
++                                              conf_warning("unknown symbol: %s",
++                                                           line + strlen(CONFIG_));
++
+                                       conf_set_changed(true);
++                              }
+                               continue;
+                       }
+@@ -523,6 +536,10 @@ int conf_read_simple(const char *name, int def)
+       }
+       free(line);
+       fclose(in);
++
++      if (conf_warnings && werror)
++              exit(1);
++
+       return 0;
+ }
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-deduplicate-code-in-conf_read_simple.patch b/queue-5.15/kconfig-deduplicate-code-in-conf_read_simple.patch
new file mode 100644 (file)
index 0000000..797fdeb
--- /dev/null
@@ -0,0 +1,159 @@
+From b042f89aaa1231656dc2cad3188f86bc51683346 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 18 Nov 2023 16:59:09 +0900
+Subject: kconfig: deduplicate code in conf_read_simple()
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit d854b4b21de684a16a7d6163c7b0e9c5ff8a09d3 ]
+
+Kconfig accepts both "# CONFIG_FOO is not set" and "CONFIG_FOO=n" as
+a valid input, but conf_read_simple() duplicates similar code to handle
+them. Factor out the common code.
+
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Stable-dep-of: a409fc1463d6 ("kconfig: fix memory leak in sym_warn_unmet_dep()")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/kconfig/confdata.c | 89 +++++++++++++++-----------------------
+ 1 file changed, 35 insertions(+), 54 deletions(-)
+
+diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+index 8349f6ecd9dc7..ef9deb1e22f8c 100644
+--- a/scripts/kconfig/confdata.c
++++ b/scripts/kconfig/confdata.c
+@@ -348,11 +348,10 @@ int conf_read_simple(const char *name, int def)
+       FILE *in = NULL;
+       char   *line = NULL;
+       size_t  line_asize = 0;
+-      char *p, *p2;
++      char *p, *p2, *val;
+       struct symbol *sym;
+       int i, def_flags;
+-      const char *warn_unknown;
+-      const char *werror;
++      const char *warn_unknown, *werror, *sym_name;
+       warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
+       werror = getenv("KCONFIG_WERROR");
+@@ -432,77 +431,34 @@ int conf_read_simple(const char *name, int def)
+       while (compat_getline(&line, &line_asize, in) != -1) {
+               conf_lineno++;
+-              sym = NULL;
+               if (line[0] == '#') {
+                       if (line[1] != ' ')
+                               continue;
+-                      if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
++                      p = line + 2;
++                      if (memcmp(p, CONFIG_, strlen(CONFIG_)))
+                               continue;
+-                      p = strchr(line + 2 + strlen(CONFIG_), ' ');
++                      sym_name = p + strlen(CONFIG_);
++                      p = strchr(sym_name, ' ');
+                       if (!p)
+                               continue;
+                       *p++ = 0;
+                       if (strncmp(p, "is not set", 10))
+                               continue;
+-                      sym = sym_find(line + 2 + strlen(CONFIG_));
+-                      if (!sym) {
+-                              if (warn_unknown)
+-                                      conf_warning("unknown symbol: %s",
+-                                                   line + 2 + strlen(CONFIG_));
+-
+-                              conf_set_changed(true);
+-                              continue;
+-                      }
+-                      if (sym->flags & def_flags) {
+-                              conf_warning("override: reassigning to symbol %s", sym->name);
+-                      }
+-                      switch (sym->type) {
+-                      case S_BOOLEAN:
+-                      case S_TRISTATE:
+-                              sym->def[def].tri = no;
+-                              sym->flags |= def_flags;
+-                              break;
+-                      default:
+-                              ;
+-                      }
++                      val = "n";
+               } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
+-                      p = strchr(line + strlen(CONFIG_), '=');
++                      sym_name = line + strlen(CONFIG_);
++                      p = strchr(sym_name, '=');
+                       if (!p)
+                               continue;
+                       *p++ = 0;
++                      val = p;
+                       p2 = strchr(p, '\n');
+                       if (p2) {
+                               *p2-- = 0;
+                               if (*p2 == '\r')
+                                       *p2 = 0;
+                       }
+-
+-                      sym = sym_find(line + strlen(CONFIG_));
+-                      if (!sym) {
+-                              if (def == S_DEF_AUTO) {
+-                                      /*
+-                                       * Reading from include/config/auto.conf
+-                                       * If CONFIG_FOO previously existed in
+-                                       * auto.conf but it is missing now,
+-                                       * include/config/FOO must be touched.
+-                                       */
+-                                      conf_touch_dep(line + strlen(CONFIG_));
+-                              } else {
+-                                      if (warn_unknown)
+-                                              conf_warning("unknown symbol: %s",
+-                                                           line + strlen(CONFIG_));
+-
+-                                      conf_set_changed(true);
+-                              }
+-                              continue;
+-                      }
+-
+-                      if (sym->flags & def_flags) {
+-                              conf_warning("override: reassigning to symbol %s", sym->name);
+-                      }
+-                      if (conf_set_sym_val(sym, def, def_flags, p))
+-                              continue;
+               } else {
+                       if (line[0] != '\r' && line[0] != '\n')
+                               conf_warning("unexpected data: %.*s",
+@@ -511,6 +467,31 @@ int conf_read_simple(const char *name, int def)
+                       continue;
+               }
++              sym = sym_find(sym_name);
++              if (!sym) {
++                      if (def == S_DEF_AUTO) {
++                              /*
++                               * Reading from include/config/auto.conf.
++                               * If CONFIG_FOO previously existed in auto.conf
++                               * but it is missing now, include/config/FOO
++                               * must be touched.
++                               */
++                              conf_touch_dep(sym_name);
++                      } else {
++                              if (warn_unknown)
++                                      conf_warning("unknown symbol: %s", sym_name);
++
++                              conf_set_changed(true);
++                      }
++                      continue;
++              }
++
++              if (sym->flags & def_flags)
++                      conf_warning("override: reassigning to symbol %s", sym->name);
++
++              if (conf_set_sym_val(sym, def, def_flags, val))
++                      continue;
++
+               if (sym && sym_is_choice_value(sym)) {
+                       struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
+                       switch (sym->def[def].tri) {
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-fix-file-name-in-warnings-when-loading-kconf.patch b/queue-5.15/kconfig-fix-file-name-in-warnings-when-loading-kconf.patch
new file mode 100644 (file)
index 0000000..2b4fec6
--- /dev/null
@@ -0,0 +1,74 @@
+From 3dd522096d26350b804fd3fd2e179a4c960f20fa Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Mon, 20 Jan 2025 16:59:14 +0900
+Subject: kconfig: fix file name in warnings when loading
+ KCONFIG_DEFCONFIG_LIST
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit a314f52a0210730d0d556de76bb7388e76d4597d ]
+
+Most 'make *config' commands use .config as the base configuration file.
+
+When .config does not exist, Kconfig tries to load a file listed in
+KCONFIG_DEFCONFIG_LIST instead.
+
+However, since commit b75b0a819af9 ("kconfig: change defconfig_list
+option to environment variable"), warning messages have displayed an
+incorrect file name in such cases.
+
+Below is a demonstration using Debian Trixie. While loading
+/boot/config-6.12.9-amd64, the warning messages incorrectly show .config
+as the file name.
+
+With this commit, the correct file name is displayed in warnings.
+
+[Before]
+
+  $ rm -f .config
+  $ make config
+  #
+  # using defaults found in /boot/config-6.12.9-amd64
+  #
+  .config:6804:warning: symbol value 'm' invalid for FB_BACKLIGHT
+  .config:9895:warning: symbol value 'm' invalid for ANDROID_BINDER_IPC
+
+[After]
+
+  $ rm -f .config
+  $ make config
+  #
+  # using defaults found in /boot/config-6.12.9-amd64
+  #
+  /boot/config-6.12.9-amd64:6804:warning: symbol value 'm' invalid for FB_BACKLIGHT
+  /boot/config-6.12.9-amd64:9895:warning: symbol value 'm' invalid for ANDROID_BINDER_IPC
+
+Fixes: b75b0a819af9 ("kconfig: change defconfig_list option to environment variable")
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/kconfig/confdata.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+index 797c8bad3837a..469450b0a5176 100644
+--- a/scripts/kconfig/confdata.c
++++ b/scripts/kconfig/confdata.c
+@@ -384,10 +384,12 @@ int conf_read_simple(const char *name, int def)
+                       *p = '\0';
+-                      in = zconf_fopen(env);
++                      name = env;
++
++                      in = zconf_fopen(name);
+                       if (in) {
+                               conf_message("using defaults found in %s",
+-                                           env);
++                                           name);
+                               goto load;
+                       }
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-fix-memory-leak-in-sym_warn_unmet_dep.patch b/queue-5.15/kconfig-fix-memory-leak-in-sym_warn_unmet_dep.patch
new file mode 100644 (file)
index 0000000..6d1e92a
--- /dev/null
@@ -0,0 +1,35 @@
+From 16e8a0e26c72f08f0291248368fbaf1379d94862 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Mon, 20 Jan 2025 17:10:31 +0900
+Subject: kconfig: fix memory leak in sym_warn_unmet_dep()
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit a409fc1463d664002ea9bf700ae4674df03de111 ]
+
+The string allocated in sym_warn_unmet_dep() is never freed, leading
+to a memory leak when an unmet dependency is detected.
+
+Fixes: f8f69dc0b4e0 ("kconfig: make unmet dependency warnings readable")
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Reviewed-by: Petr Vorel <pvorel@suse.cz>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/kconfig/symbol.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
+index 15d958ba99880..d1e9c06456ae6 100644
+--- a/scripts/kconfig/symbol.c
++++ b/scripts/kconfig/symbol.c
+@@ -321,6 +321,7 @@ static void sym_warn_unmet_dep(struct symbol *sym)
+                              "  Selected by [m]:\n");
+       fputs(str_get(&gs), stderr);
++      str_free(&gs);
+       sym_warnings++;
+ }
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-remove-unused-code-for-s_def_auto-in-conf_re.patch b/queue-5.15/kconfig-remove-unused-code-for-s_def_auto-in-conf_re.patch
new file mode 100644 (file)
index 0000000..1b33962
--- /dev/null
@@ -0,0 +1,57 @@
+From 5b6753973a36b9a516c778c57e57f8b3ef772553 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 18 Nov 2023 16:59:08 +0900
+Subject: kconfig: remove unused code for S_DEF_AUTO in conf_read_simple()
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit 92d4fe0a48f1ab6cf20143dd0b376f4fe842854b ]
+
+The 'else' arm here is unreachable in practical use cases.
+
+include/config/auto.conf does not include "# CONFIG_... is not set"
+line unless it is manually hacked.
+
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Stable-dep-of: a409fc1463d6 ("kconfig: fix memory leak in sym_warn_unmet_dep()")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/kconfig/confdata.c | 21 ++++++++-------------
+ 1 file changed, 8 insertions(+), 13 deletions(-)
+
+diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+index 80160aee01ff6..8349f6ecd9dc7 100644
+--- a/scripts/kconfig/confdata.c
++++ b/scripts/kconfig/confdata.c
+@@ -444,20 +444,15 @@ int conf_read_simple(const char *name, int def)
+                       *p++ = 0;
+                       if (strncmp(p, "is not set", 10))
+                               continue;
+-                      if (def == S_DEF_USER) {
+-                              sym = sym_find(line + 2 + strlen(CONFIG_));
+-                              if (!sym) {
+-                                      if (warn_unknown)
+-                                              conf_warning("unknown symbol: %s",
+-                                                           line + 2 + strlen(CONFIG_));
+-                                      conf_set_changed(true);
+-                                      continue;
+-                              }
+-                      } else {
+-                              sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
+-                              if (sym->type == S_UNKNOWN)
+-                                      sym->type = S_BOOLEAN;
++                      sym = sym_find(line + 2 + strlen(CONFIG_));
++                      if (!sym) {
++                              if (warn_unknown)
++                                      conf_warning("unknown symbol: %s",
++                                                   line + 2 + strlen(CONFIG_));
++
++                              conf_set_changed(true);
++                              continue;
+                       }
+                       if (sym->flags & def_flags) {
+                               conf_warning("override: reassigning to symbol %s", sym->name);
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-require-a-space-after-for-valid-input.patch b/queue-5.15/kconfig-require-a-space-after-for-valid-input.patch
new file mode 100644 (file)
index 0000000..6344bf9
--- /dev/null
@@ -0,0 +1,45 @@
+From 918fc223905f1cbc8e9ac6b6a6776378c58d1354 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Sat, 18 Nov 2023 16:59:07 +0900
+Subject: kconfig: require a space after '#' for valid input
+
+From: Masahiro Yamada <masahiroy@kernel.org>
+
+[ Upstream commit 4d137ab0107ead0f2590fc0314e627431e3b9e3f ]
+
+Currently, when an input line starts with '#', (line + 2) is passed to
+memcmp() without checking line[1].
+
+It means that line[1] can be any arbitrary character. For example,
+"#KCONFIG_FOO is not set" is accepted as valid input, functioning the
+same as "# CONFIG_FOO is not set".
+
+More importantly, this can potentially lead to a buffer overrun if
+line[1] == '\0'. It occurs if the input only contains '#', as
+(line + 2) points to an uninitialized buffer.
+
+Check line[1], and skip the line if it is not a space.
+
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Stable-dep-of: a409fc1463d6 ("kconfig: fix memory leak in sym_warn_unmet_dep()")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/kconfig/confdata.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+index 033f2882436d3..80160aee01ff6 100644
+--- a/scripts/kconfig/confdata.c
++++ b/scripts/kconfig/confdata.c
+@@ -434,6 +434,8 @@ int conf_read_simple(const char *name, int def)
+               conf_lineno++;
+               sym = NULL;
+               if (line[0] == '#') {
++                      if (line[1] != ' ')
++                              continue;
+                       if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
+                               continue;
+                       p = strchr(line + 2 + strlen(CONFIG_), ' ');
+-- 
+2.39.5
+
diff --git a/queue-5.15/kconfig-werror-unmet-symbol-dependency.patch b/queue-5.15/kconfig-werror-unmet-symbol-dependency.patch
new file mode 100644 (file)
index 0000000..afa5ae3
--- /dev/null
@@ -0,0 +1,138 @@
+From a85d312ff6d0cf241c90f0a5a41e41112ab50f68 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 22 Nov 2023 12:47:45 +0900
+Subject: kconfig: WERROR unmet symbol dependency
+
+From: Sergey Senozhatsky <senozhatsky@chromium.org>
+
+[ Upstream commit 15d3f7664d2776c086f813f1efbfe2ae20a85e89 ]
+
+When KCONFIG_WERROR env variable is set treat unmet direct
+symbol dependency as a terminal condition (error).
+
+Suggested-by: Stefan Reinauer <reinauer@google.com>
+Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
+Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
+Stable-dep-of: a409fc1463d6 ("kconfig: fix memory leak in sym_warn_unmet_dep()")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ scripts/kconfig/conf.c      |  6 ++++++
+ scripts/kconfig/confdata.c  | 13 ++++++++-----
+ scripts/kconfig/lkc_proto.h |  2 ++
+ scripts/kconfig/symbol.c    |  9 +++++++++
+ 4 files changed, 25 insertions(+), 5 deletions(-)
+
+diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
+index 5d84b44a2a2a7..ab1c41eb6d035 100644
+--- a/scripts/kconfig/conf.c
++++ b/scripts/kconfig/conf.c
+@@ -838,6 +838,9 @@ int main(int ac, char **av)
+               break;
+       }
++      if (conf_errors())
++              exit(1);
++
+       if (sync_kconfig) {
+               name = getenv("KCONFIG_NOSILENTUPDATE");
+               if (name && *name) {
+@@ -898,6 +901,9 @@ int main(int ac, char **av)
+               break;
+       }
++      if (sym_dep_errors())
++              exit(1);
++
+       if (input_mode == savedefconfig) {
+               if (conf_write_defconfig(defconfig_file)) {
+                       fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n",
+diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
+index ef9deb1e22f8c..06d98ca4b612f 100644
+--- a/scripts/kconfig/confdata.c
++++ b/scripts/kconfig/confdata.c
+@@ -173,6 +173,13 @@ static void conf_message(const char *fmt, ...)
+ static const char *conf_filename;
+ static int conf_lineno, conf_warnings;
++bool conf_errors(void)
++{
++      if (conf_warnings)
++              return getenv("KCONFIG_WERROR");
++      return false;
++}
++
+ static void conf_warning(const char *fmt, ...)
+ {
+       va_list ap;
+@@ -351,10 +358,9 @@ int conf_read_simple(const char *name, int def)
+       char *p, *p2, *val;
+       struct symbol *sym;
+       int i, def_flags;
+-      const char *warn_unknown, *werror, *sym_name;
++      const char *warn_unknown, *sym_name;
+       warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
+-      werror = getenv("KCONFIG_WERROR");
+       if (name) {
+               in = zconf_fopen(name);
+       } else {
+@@ -515,9 +521,6 @@ int conf_read_simple(const char *name, int def)
+       free(line);
+       fclose(in);
+-      if (conf_warnings && werror)
+-              exit(1);
+-
+       return 0;
+ }
+diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
+index a11626bdc421c..d7783bc0a4f79 100644
+--- a/scripts/kconfig/lkc_proto.h
++++ b/scripts/kconfig/lkc_proto.h
+@@ -12,6 +12,7 @@ void conf_set_changed(bool val);
+ bool conf_get_changed(void);
+ void conf_set_changed_callback(void (*fn)(void));
+ void conf_set_message_callback(void (*fn)(const char *s));
++bool conf_errors(void);
+ /* symbol.c */
+ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
+@@ -22,6 +23,7 @@ const char * sym_escape_string_value(const char *in);
+ struct symbol ** sym_re_search(const char *pattern);
+ const char * sym_type_name(enum symbol_type type);
+ void sym_calc_value(struct symbol *sym);
++bool sym_dep_errors(void);
+ enum symbol_type sym_get_type(struct symbol *sym);
+ bool sym_tristate_within_range(struct symbol *sym,tristate tri);
+ bool sym_set_tristate_value(struct symbol *sym,tristate tri);
+diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
+index f9786621a178e..15d958ba99880 100644
+--- a/scripts/kconfig/symbol.c
++++ b/scripts/kconfig/symbol.c
+@@ -40,6 +40,7 @@ static struct symbol symbol_empty = {
+ struct symbol *modules_sym;
+ static tristate modules_val;
++static int sym_warnings;
+ enum symbol_type sym_get_type(struct symbol *sym)
+ {
+@@ -320,6 +321,14 @@ static void sym_warn_unmet_dep(struct symbol *sym)
+                              "  Selected by [m]:\n");
+       fputs(str_get(&gs), stderr);
++      sym_warnings++;
++}
++
++bool sym_dep_errors(void)
++{
++      if (sym_warnings)
++              return getenv("KCONFIG_WERROR");
++      return false;
+ }
+ void sym_calc_value(struct symbol *sym)
+-- 
+2.39.5
+
index adb8a3b5035cf2aa2a8805aba1091bf1b612ab5e..9047a7e0d39f069ad773fa37e34260dc77f15282 100644 (file)
@@ -189,3 +189,14 @@ vsock-allow-retrying-on-connect-failure.patch
 bgmac-reduce-max-frame-size-to-support-just-mtu-1500.patch
 net-sh_eth-fix-missing-rtnl-lock-in-suspend-resume-p.patch
 net-hsr-fix-fill_frame_info-regression-vs-vlan-packe.patch
+genksyms-fix-memory-leak-when-the-same-symbol-is-add.patch
+genksyms-fix-memory-leak-when-the-same-symbol-is-rea.patch
+kconfig-fix-file-name-in-warnings-when-loading-kconf.patch
+kconfig-add-warn-unknown-symbols-sanity-check.patch
+kconfig-require-a-space-after-for-valid-input.patch
+kconfig-remove-unused-code-for-s_def_auto-in-conf_re.patch
+kconfig-deduplicate-code-in-conf_read_simple.patch
+kconfig-werror-unmet-symbol-dependency.patch
+kconfig-fix-memory-leak-in-sym_warn_unmet_dep.patch
+hexagon-fix-using-plain-integer-as-null-pointer-warn.patch
+hexagon-fix-unbalanced-spinlock-in-die.patch