The patch titled Subject: bootconfig: fix off-by-one in xbc_node_compose_key_after() has been added to the -mm tree. Its filename is bootconfig-fix-off-by-one-in-xbc_node_compose_key_after.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/bootconfig-fix-off-by-one-in-xbc_node_compose_key_after.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/bootconfig-fix-off-by-one-in-xbc_node_compose_key_after.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> Subject: bootconfig: fix off-by-one in xbc_node_compose_key_after() While reviewing some patches for bootconfig, I noticed the following code in xbc_node_compose_key_after(): ret = snprintf(buf, size, "%s%s", xbc_node_get_data(node), depth ? "." : ""); if (ret < 0) return ret; if (ret > size) { size = 0; } else { size -= ret; buf += ret; } But snprintf() returns the number of bytes that would be written, not the number of bytes that are written (ignoring the nul terminator). This means that if the number of non null bytes written were to equal size, then the nul byte, which snprintf() always adds, will overwrite that last byte. ret = snprintf(buf, 5, "hello"); printf("buf = '%s' ", buf); printf("ret = %d ", ret); produces: buf = 'hell' ret = 5 The string was truncated without ret being greater than 5. Test (ret >= size) for overwrite. Link: http://lkml.kernel.org/r/20200813183050.029a6003@xxxxxxxxxxxxxxxx Fixes: 76db5a27a827c ("bootconfig: Add Extra Boot Config support") Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/bootconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/lib/bootconfig.c~bootconfig-fix-off-by-one-in-xbc_node_compose_key_after +++ a/lib/bootconfig.c @@ -248,7 +248,7 @@ int __init xbc_node_compose_key_after(st depth ? "." : ""); if (ret < 0) return ret; - if (ret > size) { + if (ret >= size) { size = 0; } else { size -= ret; _ Patches currently in -mm which might be from rostedt@xxxxxxxxxxx are bootconfig-fix-off-by-one-in-xbc_node_compose_key_after.patch