History

Merge tag 'bootconfig-fixes-v6.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull bootconfig fixes from Masami Hiramatsu: - Fix potential static_command_line buffer overrun. Currently we allocate the memory for static_command_line based on "boot_command_line", but it will copy "command_line" into it. So we use the length of "command_line" instead of "boot_command_line" (as we previously did) - Use memblock_free_late() in xbc_exit() instead of memblock_free() after the buddy system is initialized - Fix a kerneldoc warning * tag 'bootconfig-fixes-v6.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: bootconfig: Fix the kerneldoc of _xbc_exit() bootconfig: use memblock_free_late to free xbc memory to buddy init/main.c: Fix potential static_command_line memory overflow

Linus Torvalds committed 2 years ago

Commit 9c6e84e2 parents dbe0a7b 298b8713 files · +21 −10Browse files

Unified · Split

3 files
  1. include/linux/bootconfig.h +6 −1
  2. init/main.c +2 −0
  3. lib/bootconfig.c +13 −9
include/linux/bootconfig.h+6−1
@@ -288,7 +288,12 @@ int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos); · 287 unmodified lines
288288 int __init xbc_get_info(int *node_size, size_t *data_size);
289289
290290 /* XBC cleanup data structures */
291−void __init xbc_exit(void);
291+void __init _xbc_exit(bool early);
292+
293+static inline void xbc_exit(void)
294+{
295+ _xbc_exit(false);
296+}
292297
293298 /* XBC embedded bootconfig data in kernel */
294299 #ifdef CONFIG_BOOT_CONFIG_EMBED
init/main.c+2−0
@@ -636,6 +636,8 @@ static void __init setup_command_line(char *command_line) · 635 unmodified lines
636636 if (!saved_command_line)
637637 panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);
638638
639+ len = xlen + strlen(command_line) + 1;
640+
639641 static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
640642 if (!static_command_line)
641643 panic("%s: Failed to allocate %zu bytes\n", __func__, len);
lib/bootconfig.c+13−9
@@ -61,9 +61,12 @@ static inline void * __init xbc_alloc_mem(size_t size) · 60 unmodified lines
6161 return memblock_alloc(size, SMP_CACHE_BYTES);
6262 }
6363
64−static inline void __init xbc_free_mem(void *addr, size_t size)
64+static inline void __init xbc_free_mem(void *addr, size_t size, bool early)
6565 {
66− memblock_free(addr, size);
66+ if (early)
67+ memblock_free(addr, size);
68+ else if (addr)
69+ memblock_free_late(__pa(addr), size);
6770 }
6871
6972 #else /* !__KERNEL__ */
@@ -73,7 +76,7 @@ static inline void *xbc_alloc_mem(size_t size) · 3 unmodified lines
7376 return malloc(size);
7477 }
7578
76−static inline void xbc_free_mem(void *addr, size_t size)
79+static inline void xbc_free_mem(void *addr, size_t size, bool early)
7780 {
7881 free(addr);
7982 }
@@ -898,19 +901,20 @@ static int __init xbc_parse_tree(void) · 818 unmodified lines
898901 }
899902
900903 /**
901− * xbc_exit() - Clean up all parsed bootconfig
904+ * _xbc_exit() - Clean up all parsed bootconfig
905+ * @early: Set true if this is called before budy system is initialized.
902906 *
903907 * This clears all data structures of parsed bootconfig on memory.
904908 * If you need to reuse xbc_init() with new boot config, you can
905909 * use this.
906910 */
907−void __init xbc_exit(void)
911+void __init _xbc_exit(bool early)
908912 {
909− xbc_free_mem(xbc_data, xbc_data_size);
913+ xbc_free_mem(xbc_data, xbc_data_size, early);
910914 xbc_data = NULL;
911915 xbc_data_size = 0;
912916 xbc_node_num = 0;
913− xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX);
917+ xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX, early);
914918 xbc_nodes = NULL;
915919 brace_index = 0;
916920 }
@@ -963,7 +967,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) · 46 unmodified lines
963967 if (!xbc_nodes) {
964968 if (emsg)
965969 *emsg = "Failed to allocate bootconfig nodes";
966− xbc_exit();
970+ _xbc_exit(true);
967971 return -ENOMEM;
968972 }
969973 memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX);
@@ -977,7 +981,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) · 7 unmodified lines
977981 *epos = xbc_err_pos;
978982 if (emsg)
979983 *emsg = xbc_err_msg;
980− xbc_exit();
984+ _xbc_exit(true);
981985 } else
982986 ret = xbc_node_num;
983987

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t