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
288int __init xbc_get_info(int *node_size, size_t *data_size);288int __init xbc_get_info(int *node_size, size_t *data_size);
289 289
290/* XBC cleanup data structures */290/* XBC cleanup data structures */
291void __init xbc_exit(void);291void __init _xbc_exit(bool early);
292
293static inline void xbc_exit(void)
294{
295 _xbc_exit(false);
296}
292 297
293/* XBC embedded bootconfig data in kernel */298/* XBC embedded bootconfig data in kernel */
294#ifdef CONFIG_BOOT_CONFIG_EMBED299#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
636 if (!saved_command_line)636 if (!saved_command_line)
637 panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);637 panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);
638 638
639 len = xlen + strlen(command_line) + 1;
640
639 static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);641 static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
640 if (!static_command_line)642 if (!static_command_line)
641 panic("%s: Failed to allocate %zu bytes\n", __func__, len);643 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
61 return memblock_alloc(size, SMP_CACHE_BYTES);61 return memblock_alloc(size, SMP_CACHE_BYTES);
62}62}
63 63
64static inline void __init xbc_free_mem(void *addr, size_t size)64static inline void __init xbc_free_mem(void *addr, size_t size, bool early)
65{65{
66 memblock_free(addr, size);66 if (early)
67 memblock_free(addr, size);
68 else if (addr)
69 memblock_free_late(__pa(addr), size);
67}70}
68 71
69#else /* !__KERNEL__ */72#else /* !__KERNEL__ */
@@ -73,7 +76,7 @@ static inline void *xbc_alloc_mem(size_t size) · 3 unmodified lines
73 return malloc(size);76 return malloc(size);
74}77}
75 78
76static inline void xbc_free_mem(void *addr, size_t size)79static inline void xbc_free_mem(void *addr, size_t size, bool early)
77{80{
78 free(addr);81 free(addr);
79}82}
@@ -898,19 +901,20 @@ static int __init xbc_parse_tree(void) · 818 unmodified lines
898}901}
899 902
900/**903/**
901 * xbc_exit() - Clean up all parsed bootconfig904 * _xbc_exit() - Clean up all parsed bootconfig
905 * @early: Set true if this is called before budy system is initialized.
902 *906 *
903 * This clears all data structures of parsed bootconfig on memory.907 * This clears all data structures of parsed bootconfig on memory.
904 * If you need to reuse xbc_init() with new boot config, you can908 * If you need to reuse xbc_init() with new boot config, you can
905 * use this.909 * use this.
906 */910 */
907void __init xbc_exit(void)911void __init _xbc_exit(bool early)
908{912{
909 xbc_free_mem(xbc_data, xbc_data_size);913 xbc_free_mem(xbc_data, xbc_data_size, early);
910 xbc_data = NULL;914 xbc_data = NULL;
911 xbc_data_size = 0;915 xbc_data_size = 0;
912 xbc_node_num = 0;916 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);
914 xbc_nodes = NULL;918 xbc_nodes = NULL;
915 brace_index = 0;919 brace_index = 0;
916}920}
@@ -963,7 +967,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) · 46 unmodified lines
963 if (!xbc_nodes) {967 if (!xbc_nodes) {
964 if (emsg)968 if (emsg)
965 *emsg = "Failed to allocate bootconfig nodes";969 *emsg = "Failed to allocate bootconfig nodes";
966 xbc_exit();970 _xbc_exit(true);
967 return -ENOMEM;971 return -ENOMEM;
968 }972 }
969 memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX);973 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
977 *epos = xbc_err_pos;981 *epos = xbc_err_pos;
978 if (emsg)982 if (emsg)
979 *emsg = xbc_err_msg;983 *emsg = xbc_err_msg;
980 xbc_exit();984 _xbc_exit(true);
981 } else985 } else
982 ret = xbc_node_num;986 ret = xbc_node_num;
983 987

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