mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-10 15:10:38 +00:00
Bootconfig fixes for v6.9-rc4:
- 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 previously we did). - Use memblock_free_late() in xbc_exit() instead of memblock_free() after the buddy system is initialized. - Fix a kerneldoc warning. -----BEGIN PGP SIGNATURE----- iQFPBAABCgA5FiEEh7BulGwFlgAOi5DV2/sHvwUrPxsFAmYgN1kbHG1hc2FtaS5o aXJhbWF0c3VAZ21haWwuY29tAAoJENv7B78FKz8b/yEH/1FFgb7UJDtQLbtHl5/b bcxLbSzfb/N37Bc+sE/AKZYrt5QAMjaOmdtzQz9kdLtycxWcQinne4jqGxd6zfTU UIisfDjEZr46/Rs5sJg+5i8wWrud1TJOmlMsqiSVcorl0f/wE4S7PqgYXRNWZ0p+ KipjuCCV43ITmVjsiq2NxfZGDaWzow/EJXwZzpQkJE1zaU13w2nzgzg64JW3f/lf Dx/o9jlYEoLkCjiQJ6XaRuTpHbPP1grozSMbvE3z1WnxCaiFHlzXGi6WUhto+pTu vt/pUrIFYE7k0IFHAVEgBjOkfCm5y9FwOdPLqwy3harQ5ek9D6h6bFnDhbZw7I27 6V8= =e2c5 -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
9c6e84e4ba
@ -288,7 +288,12 @@ int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos);
|
||||
int __init xbc_get_info(int *node_size, size_t *data_size);
|
||||
|
||||
/* XBC cleanup data structures */
|
||||
void __init xbc_exit(void);
|
||||
void __init _xbc_exit(bool early);
|
||||
|
||||
static inline void xbc_exit(void)
|
||||
{
|
||||
_xbc_exit(false);
|
||||
}
|
||||
|
||||
/* XBC embedded bootconfig data in kernel */
|
||||
#ifdef CONFIG_BOOT_CONFIG_EMBED
|
||||
|
@ -636,6 +636,8 @@ static void __init setup_command_line(char *command_line)
|
||||
if (!saved_command_line)
|
||||
panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);
|
||||
|
||||
len = xlen + strlen(command_line) + 1;
|
||||
|
||||
static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
|
||||
if (!static_command_line)
|
||||
panic("%s: Failed to allocate %zu bytes\n", __func__, len);
|
||||
|
@ -61,9 +61,12 @@ static inline void * __init xbc_alloc_mem(size_t size)
|
||||
return memblock_alloc(size, SMP_CACHE_BYTES);
|
||||
}
|
||||
|
||||
static inline void __init xbc_free_mem(void *addr, size_t size)
|
||||
static inline void __init xbc_free_mem(void *addr, size_t size, bool early)
|
||||
{
|
||||
memblock_free(addr, size);
|
||||
if (early)
|
||||
memblock_free(addr, size);
|
||||
else if (addr)
|
||||
memblock_free_late(__pa(addr), size);
|
||||
}
|
||||
|
||||
#else /* !__KERNEL__ */
|
||||
@ -73,7 +76,7 @@ static inline void *xbc_alloc_mem(size_t size)
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static inline void xbc_free_mem(void *addr, size_t size)
|
||||
static inline void xbc_free_mem(void *addr, size_t size, bool early)
|
||||
{
|
||||
free(addr);
|
||||
}
|
||||
@ -898,19 +901,20 @@ static int __init xbc_parse_tree(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* xbc_exit() - Clean up all parsed bootconfig
|
||||
* _xbc_exit() - Clean up all parsed bootconfig
|
||||
* @early: Set true if this is called before budy system is initialized.
|
||||
*
|
||||
* This clears all data structures of parsed bootconfig on memory.
|
||||
* If you need to reuse xbc_init() with new boot config, you can
|
||||
* use this.
|
||||
*/
|
||||
void __init xbc_exit(void)
|
||||
void __init _xbc_exit(bool early)
|
||||
{
|
||||
xbc_free_mem(xbc_data, xbc_data_size);
|
||||
xbc_free_mem(xbc_data, xbc_data_size, early);
|
||||
xbc_data = NULL;
|
||||
xbc_data_size = 0;
|
||||
xbc_node_num = 0;
|
||||
xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX);
|
||||
xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX, early);
|
||||
xbc_nodes = NULL;
|
||||
brace_index = 0;
|
||||
}
|
||||
@ -963,7 +967,7 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos)
|
||||
if (!xbc_nodes) {
|
||||
if (emsg)
|
||||
*emsg = "Failed to allocate bootconfig nodes";
|
||||
xbc_exit();
|
||||
_xbc_exit(true);
|
||||
return -ENOMEM;
|
||||
}
|
||||
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)
|
||||
*epos = xbc_err_pos;
|
||||
if (emsg)
|
||||
*emsg = xbc_err_msg;
|
||||
xbc_exit();
|
||||
_xbc_exit(true);
|
||||
} else
|
||||
ret = xbc_node_num;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user