From: Chen Gang <gang.chen@asianux.com>
To: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Cc: "sfr@canb.auug.org.au" <sfr@canb.auug.org.au>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"paulus@samba.org" <paulus@samba.org>,
Al Viro <viro@zeniv.linux.org.uk>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH] PowerPC: kernel: memory access violation when rtas_data_buf contents are more than 1026
Date: Wed, 24 Apr 2013 15:03:52 +0800 [thread overview]
Message-ID: <517783D8.6010701@asianux.com> (raw)
In-Reply-To: <51777B74.8040204@linux.vnet.ibm.com>
On 2013年04月24日 14:28, Vasant Hegde wrote:
> On 04/23/2013 08:42 AM, Chen Gang wrote:
>>
>> need set '\0' for 'local_buffer'.
>>
>> SPLPAR_MAXLENGTH is 1026, RTAS_DATA_BUF_SIZE is 4096. so the contents of
>> rtas_data_buf may truncated in memcpy.
>>
>> if contents are really truncated.
>> the splpar_strlen is more than 1026. the next while loop checking will
>> not find the end of buffer. that will cause memory access violation.
>>
>
> Per parameter length in ibm,get-system-parameter RTAS call is limited to
> 1026 bytes (1024 bytes of data + 2 bytes length). And 'rtas_data_buf'
> was set to 0 (first 1026 bytes) before call RTAS call. At the worst if
> we get junk in RTAS output length field helps to exit from the while
> loop. So I don't think we need this patch.
Is get-system-parameter return the NUL terminated string ? if so, it
will no issue (just like your discription).
If it will not return NUL terminated string, please see line 326:
"while ((*local_buffer) && (idx < splpar_strlen))"
(when idx == 1024, *local_buffer is memory access violation).
Since we use the first 2 bytes as length, and also be sure of the real
length will never more than 1024, I suggest to:
---------------------------patch begin--------------------------------
diff --git a/arch/powerpc/kernel/lparcfg.c b/arch/powerpc/kernel/lparcfg.c
index 801a757..f8bd7cf 100644
--- a/arch/powerpc/kernel/lparcfg.c
+++ b/arch/powerpc/kernel/lparcfg.c
@@ -323,7 +323,7 @@ static void parse_system_parameter_string(struct seq_file *m)
w_idx = 0;
idx = 0;
- while ((*local_buffer) && (idx < splpar_strlen)) {
+ while (idx < splpar_strlen) {
workbuffer[w_idx++] = local_buffer[idx++];
if ((local_buffer[idx] == ',')
|| (local_buffer[idx] == '\0')) {
---------------------------patch end----------------------------------
Thanks.
--
Chen Gang
Asianux Corporation
WARNING: multiple messages have this Message-ID (diff)
From: Chen Gang <gang.chen@asianux.com>
To: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
"sfr@canb.auug.org.au" <sfr@canb.auug.org.au>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"paulus@samba.org" <paulus@samba.org>,
Al Viro <viro@zeniv.linux.org.uk>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH] PowerPC: kernel: memory access violation when rtas_data_buf contents are more than 1026
Date: Wed, 24 Apr 2013 15:03:52 +0800 [thread overview]
Message-ID: <517783D8.6010701@asianux.com> (raw)
In-Reply-To: <51777B74.8040204@linux.vnet.ibm.com>
On 2013年04月24日 14:28, Vasant Hegde wrote:
> On 04/23/2013 08:42 AM, Chen Gang wrote:
>>
>> need set '\0' for 'local_buffer'.
>>
>> SPLPAR_MAXLENGTH is 1026, RTAS_DATA_BUF_SIZE is 4096. so the contents of
>> rtas_data_buf may truncated in memcpy.
>>
>> if contents are really truncated.
>> the splpar_strlen is more than 1026. the next while loop checking will
>> not find the end of buffer. that will cause memory access violation.
>>
>
> Per parameter length in ibm,get-system-parameter RTAS call is limited to
> 1026 bytes (1024 bytes of data + 2 bytes length). And 'rtas_data_buf'
> was set to 0 (first 1026 bytes) before call RTAS call. At the worst if
> we get junk in RTAS output length field helps to exit from the while
> loop. So I don't think we need this patch.
Is get-system-parameter return the NUL terminated string ? if so, it
will no issue (just like your discription).
If it will not return NUL terminated string, please see line 326:
"while ((*local_buffer) && (idx < splpar_strlen))"
(when idx == 1024, *local_buffer is memory access violation).
Since we use the first 2 bytes as length, and also be sure of the real
length will never more than 1024, I suggest to:
---------------------------patch begin--------------------------------
diff --git a/arch/powerpc/kernel/lparcfg.c b/arch/powerpc/kernel/lparcfg.c
index 801a757..f8bd7cf 100644
--- a/arch/powerpc/kernel/lparcfg.c
+++ b/arch/powerpc/kernel/lparcfg.c
@@ -323,7 +323,7 @@ static void parse_system_parameter_string(struct seq_file *m)
w_idx = 0;
idx = 0;
- while ((*local_buffer) && (idx < splpar_strlen)) {
+ while (idx < splpar_strlen) {
workbuffer[w_idx++] = local_buffer[idx++];
if ((local_buffer[idx] == ',')
|| (local_buffer[idx] == '\0')) {
---------------------------patch end----------------------------------
Thanks.
--
Chen Gang
Asianux Corporation
next prev parent reply other threads:[~2013-04-24 7:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-18 4:45 [Suggestion] PowerPC: kernel: memory access violation when rtas_data_buf contents are more than 1026 Chen Gang
2013-04-18 4:45 ` Chen Gang
2013-04-23 0:31 ` Benjamin Herrenschmidt
2013-04-23 0:31 ` Benjamin Herrenschmidt
2013-04-23 1:48 ` Chen Gang
2013-04-23 1:48 ` Chen Gang
2013-04-23 3:12 ` [PATCH] " Chen Gang
2013-04-23 3:12 ` Chen Gang
2013-04-24 6:28 ` Vasant Hegde
2013-04-24 6:28 ` Vasant Hegde
2013-04-24 7:03 ` Chen Gang [this message]
2013-04-24 7:03 ` Chen Gang
2013-04-24 7:23 ` Vasant Hegde
2013-04-24 7:23 ` Vasant Hegde
2013-04-24 7:40 ` Chen Gang
2013-04-24 7:40 ` Chen Gang
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=517783D8.6010701@asianux.com \
--to=gang.chen@asianux.com \
--cc=hegdevasant@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.org \
--cc=sfr@canb.auug.org.au \
--cc=viro@zeniv.linux.org.uk \
/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.