Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94FA9C433E1 for ; Fri, 14 Aug 2020 02:39:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EFEB20768 for ; Fri, 14 Aug 2020 02:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597372742; bh=cnAL2vIBTt3uq1JMVQ9UJxEMyeOHJf60jhtlt8AtQ7k=; h=Date:From:To:Subject:In-Reply-To:Reply-To:List-ID:From; b=XVsbBiDx7U9coCvBjsHB2Fq+fihACvhIj1bfd5tGJQUtaTsN3Eq6NIr85I8Eb/5cI bvC7AufWjZEaO2lf9PvQJ9r6I51atoj8G6pzXKv9zHmBm/oNlq2OXSmvheDv4qraNb zeSK9HCk4PHXzQxvGZMocTLzEjQY/kkOIJws7n4c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726576AbgHNCjC (ORCPT ); Thu, 13 Aug 2020 22:39:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:55510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbgHNCjB (ORCPT ); Thu, 13 Aug 2020 22:39:01 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 19E0F20716; Fri, 14 Aug 2020 02:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597372741; bh=cnAL2vIBTt3uq1JMVQ9UJxEMyeOHJf60jhtlt8AtQ7k=; h=Date:From:To:Subject:In-Reply-To:From; b=bx9bEPq4MEH9WmDggsc+eXYZy1/83rgeDPeAFnIb4Nr3aXd4O1J3h+V40kR96jwba hAtNlV3UPvS+7iXxyrIdpfcD8pP16+CMrpDwztceqoVvro32wqHVgFAB7LTM1Lnoti KcR1OYMFy+12YaIi56epd9TMUFWtXNbCbCYaZLQE= Date: Thu, 13 Aug 2020 19:39:00 -0700 From: Andrew Morton To: mhiramat@kernel.org, mm-commits@vger.kernel.org, rostedt@goodmis.org, stable@vger.kernel.org Subject: + bootconfig-fix-off-by-one-in-xbc_node_compose_key_after.patch added to -mm tree Message-ID: <20200814023900.VVivaKSaJ%akpm@linux-foundation.org> In-Reply-To: <20200811182949.e12ae9a472e3b5e27e16ad6c@linux-foundation.org> User-Agent: s-nail v14.8.16 Sender: mm-commits-owner@vger.kernel.org Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org 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) 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@oasis.local.home Fixes: 76db5a27a827c ("bootconfig: Add Extra Boot Config support") Signed-off-by: Steven Rostedt (VMware) Cc: Masami Hiramatsu Cc: Signed-off-by: Andrew Morton --- 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@goodmis.org are bootconfig-fix-off-by-one-in-xbc_node_compose_key_after.patch