All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yi Zhuang <zhuangyi1@huawei.com>
To: <benh@kernel.crashing.org>, <paulus@samba.org>
Cc: <zhuangyi1@huawei.com>, <hegdevasant@linux.vnet.ibm.com>,
	<mpe@ellerman.id.au>, <linuxppc-dev@lists.ozlabs.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2] powerpc/rtas_flash: fix a potential buffer overflow
Date: Wed, 14 Jul 2021 20:27:53 +0800	[thread overview]
Message-ID: <20210714122753.76021-1-zhuangyi1@huawei.com> (raw)

Since snprintf() returns the possible output size instead of the
actual output size, the available flash_msg length returned by
get_validate_flash_msg may exceed the given buffer limit when
simple_read_from_buffer calls copy_to_user

Reported-by: kernel test robot <lkp@intel.com>
Fixes: a94a14720eaf5 powerpc/rtas_flash: Fix validate_flash buffer overflow issue
Signed-off-by: Yi Zhuang <zhuangyi1@huawei.com>
---
 arch/powerpc/kernel/rtas_flash.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index a99179d83538..062f0724c2ff 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -470,9 +470,14 @@ static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
 	if (args_buf->status >= VALIDATE_TMP_UPDATE) { 
 		n = sprintf(msg, "%d\n", args_buf->update_results);
 		if ((args_buf->update_results >= VALIDATE_CUR_UNKNOWN) ||
-		    (args_buf->update_results == VALIDATE_TMP_UPDATE))
+		    (args_buf->update_results == VALIDATE_TMP_UPDATE)) {
 			n += snprintf(msg + n, msglen - n, "%s\n",
 					args_buf->buf);
+			if (n >= msglen) {
+				n = msglen;
+				printk(KERN_ERR "FLASH: msg too long.\n");
+			}
+		}
 	} else {
 		n = sprintf(msg, "%d\n", args_buf->status);
 	}
-- 
2.26.0.106.g9fadedd


WARNING: multiple messages have this Message-ID (diff)
From: Yi Zhuang <zhuangyi1@huawei.com>
To: <benh@kernel.crashing.org>, <paulus@samba.org>
Cc: hegdevasant@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org,
	linux-kernel@vger.kernel.org, zhuangyi1@huawei.com
Subject: [PATCH v2] powerpc/rtas_flash: fix a potential buffer overflow
Date: Wed, 14 Jul 2021 20:27:53 +0800	[thread overview]
Message-ID: <20210714122753.76021-1-zhuangyi1@huawei.com> (raw)

Since snprintf() returns the possible output size instead of the
actual output size, the available flash_msg length returned by
get_validate_flash_msg may exceed the given buffer limit when
simple_read_from_buffer calls copy_to_user

Reported-by: kernel test robot <lkp@intel.com>
Fixes: a94a14720eaf5 powerpc/rtas_flash: Fix validate_flash buffer overflow issue
Signed-off-by: Yi Zhuang <zhuangyi1@huawei.com>
---
 arch/powerpc/kernel/rtas_flash.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index a99179d83538..062f0724c2ff 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -470,9 +470,14 @@ static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
 	if (args_buf->status >= VALIDATE_TMP_UPDATE) { 
 		n = sprintf(msg, "%d\n", args_buf->update_results);
 		if ((args_buf->update_results >= VALIDATE_CUR_UNKNOWN) ||
-		    (args_buf->update_results == VALIDATE_TMP_UPDATE))
+		    (args_buf->update_results == VALIDATE_TMP_UPDATE)) {
 			n += snprintf(msg + n, msglen - n, "%s\n",
 					args_buf->buf);
+			if (n >= msglen) {
+				n = msglen;
+				printk(KERN_ERR "FLASH: msg too long.\n");
+			}
+		}
 	} else {
 		n = sprintf(msg, "%d\n", args_buf->status);
 	}
-- 
2.26.0.106.g9fadedd


             reply	other threads:[~2021-07-14 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 12:27 Yi Zhuang [this message]
2021-07-14 12:27 ` [PATCH v2] powerpc/rtas_flash: fix a potential buffer overflow Yi Zhuang
2021-07-14 16:52 ` Christophe Leroy
2021-07-14 16:52   ` Christophe Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210714122753.76021-1-zhuangyi1@huawei.com \
    --to=zhuangyi1@huawei.com \
    --cc=benh@kernel.crashing.org \
    --cc=hegdevasant@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.