qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gdbstub: Correct misparsing of vCont C/S requests
@ 2020-11-21 21:03 Peter Maydell
  2020-11-23 10:39 ` Philippe Mathieu-Daudé
  2020-11-23 13:41 ` Alex Bennée
  0 siblings, 2 replies; 5+ messages in thread
From: Peter Maydell @ 2020-11-21 21:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Alex Bennée

In the vCont packet, two of the command actions (C and S) take an
argument specifying the signal to be sent to the process/thread, which is
sent as an ASCII string of two hex digits which immediately follow the
'C' or 'S' character.

Our code for parsing this packet accidentally skipped the first of the
two bytes of the signal value, because it started parsing the hex string
at 'p + 1' when the preceding code had already moved past the 'C' or
'S' with "cur_action = *p++".

This meant that we would only do the right thing for signals below
10, and would misinterpret the rest.  For instance, when the debugger
wants to send the process a SIGPROF (27 on x86-64) we mangle this into
a SIGSEGV (11).

Remove the accidental double increment.

Fixes: https://bugs.launchpad.net/qemu/+bug/1773743
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Haven't really given this enough testing to want to put it into 5.2,
I think (though it does fix the repro in the bug report).
The bug has been present since commit 544177ad1cfd78 from 2017.

 gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdbstub.c b/gdbstub.c
index f19f98ab1ab..d99bc0bf2ea 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1243,7 +1243,7 @@ static int gdb_handle_vcont(const char *p)
         cur_action = *p++;
         if (cur_action == 'C' || cur_action == 'S') {
             cur_action = qemu_tolower(cur_action);
-            res = qemu_strtoul(p + 1, &p, 16, &tmp);
+            res = qemu_strtoul(p, &p, 16, &tmp);
             if (res) {
                 goto out;
             }
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdbstub: Correct misparsing of vCont C/S requests
  2020-11-21 21:03 [PATCH] gdbstub: Correct misparsing of vCont C/S requests Peter Maydell
@ 2020-11-23 10:39 ` Philippe Mathieu-Daudé
  2020-11-23 13:41 ` Alex Bennée
  1 sibling, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-11-23 10:39 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Alex Bennée

On 11/21/20 10:03 PM, Peter Maydell wrote:
> In the vCont packet, two of the command actions (C and S) take an
> argument specifying the signal to be sent to the process/thread, which is
> sent as an ASCII string of two hex digits which immediately follow the
> 'C' or 'S' character.
> 
> Our code for parsing this packet accidentally skipped the first of the
> two bytes of the signal value, because it started parsing the hex string
> at 'p + 1' when the preceding code had already moved past the 'C' or
> 'S' with "cur_action = *p++".
> 
> This meant that we would only do the right thing for signals below
> 10, and would misinterpret the rest.  For instance, when the debugger
> wants to send the process a SIGPROF (27 on x86-64) we mangle this into
> a SIGSEGV (11).
> 
> Remove the accidental double increment.
> 
> Fixes: https://bugs.launchpad.net/qemu/+bug/1773743

Eventually more precise using:

Fixes: 544177ad1cf ("gdbstub: Fix vCont behaviour")
Buglink: https://bugs.launchpad.net/qemu/+bug/1773743

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Haven't really given this enough testing to want to put it into 5.2,
> I think (though it does fix the repro in the bug report).
> The bug has been present since commit 544177ad1cfd78 from 2017.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

I am not against having it fixed for 5.2 (trivial fix,
reporter can use sigprof again).

Thanks for the fix!

Phil.

> 
>  gdbstub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index f19f98ab1ab..d99bc0bf2ea 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1243,7 +1243,7 @@ static int gdb_handle_vcont(const char *p)
>          cur_action = *p++;
>          if (cur_action == 'C' || cur_action == 'S') {
>              cur_action = qemu_tolower(cur_action);
> -            res = qemu_strtoul(p + 1, &p, 16, &tmp);
> +            res = qemu_strtoul(p, &p, 16, &tmp);
>              if (res) {
>                  goto out;
>              }
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdbstub: Correct misparsing of vCont C/S requests
  2020-11-21 21:03 [PATCH] gdbstub: Correct misparsing of vCont C/S requests Peter Maydell
  2020-11-23 10:39 ` Philippe Mathieu-Daudé
@ 2020-11-23 13:41 ` Alex Bennée
  2020-12-11 14:12   ` Peter Maydell
  1 sibling, 1 reply; 5+ messages in thread
From: Alex Bennée @ 2020-11-23 13:41 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Philippe Mathieu-Daudé, qemu-devel


Peter Maydell <peter.maydell@linaro.org> writes:

> In the vCont packet, two of the command actions (C and S) take an
> argument specifying the signal to be sent to the process/thread, which is
> sent as an ASCII string of two hex digits which immediately follow the
> 'C' or 'S' character.
>
> Our code for parsing this packet accidentally skipped the first of the
> two bytes of the signal value, because it started parsing the hex string
> at 'p + 1' when the preceding code had already moved past the 'C' or
> 'S' with "cur_action = *p++".
>
> This meant that we would only do the right thing for signals below
> 10, and would misinterpret the rest.  For instance, when the debugger
> wants to send the process a SIGPROF (27 on x86-64) we mangle this into
> a SIGSEGV (11).
>
> Remove the accidental double increment.
>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1773743
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

LGTM

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
> Haven't really given this enough testing to want to put it into 5.2,
> I think (though it does fix the repro in the bug report).
> The bug has been present since commit 544177ad1cfd78 from 2017.

I'd be happy including it. I don't have any gdbstub patches queued at
the moment but I could put together one if you want or you could just
include it directly if you are now happy to.

>
>  gdbstub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index f19f98ab1ab..d99bc0bf2ea 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1243,7 +1243,7 @@ static int gdb_handle_vcont(const char *p)
>          cur_action = *p++;
>          if (cur_action == 'C' || cur_action == 'S') {
>              cur_action = qemu_tolower(cur_action);
> -            res = qemu_strtoul(p + 1, &p, 16, &tmp);
> +            res = qemu_strtoul(p, &p, 16, &tmp);
>              if (res) {
>                  goto out;
>              }


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdbstub: Correct misparsing of vCont C/S requests
  2020-11-23 13:41 ` Alex Bennée
@ 2020-12-11 14:12   ` Peter Maydell
  2020-12-11 15:48     ` Alex Bennée
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2020-12-11 14:12 UTC (permalink / raw)
  To: Alex Bennée; +Cc: Philippe Mathieu-Daudé, QEMU Developers

On Mon, 23 Nov 2020 at 13:41, Alex Bennée <alex.bennee@linaro.org> wrote:
>
>
> Peter Maydell <peter.maydell@linaro.org> writes:
>
> > In the vCont packet, two of the command actions (C and S) take an
> > argument specifying the signal to be sent to the process/thread, which is
> > sent as an ASCII string of two hex digits which immediately follow the
> > 'C' or 'S' character.
> >
> > Our code for parsing this packet accidentally skipped the first of the
> > two bytes of the signal value, because it started parsing the hex string
> > at 'p + 1' when the preceding code had already moved past the 'C' or
> > 'S' with "cur_action = *p++".
> >
> > This meant that we would only do the right thing for signals below
> > 10, and would misinterpret the rest.  For instance, when the debugger
> > wants to send the process a SIGPROF (27 on x86-64) we mangle this into
> > a SIGSEGV (11).
> >
> > Remove the accidental double increment.
> >
> > Fixes: https://bugs.launchpad.net/qemu/+bug/1773743
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>
> LGTM
>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>
> > ---
> > Haven't really given this enough testing to want to put it into 5.2,
> > I think (though it does fix the repro in the bug report).
> > The bug has been present since commit 544177ad1cfd78 from 2017.
>
> I'd be happy including it. I don't have any gdbstub patches queued at
> the moment but I could put together one if you want or you could just
> include it directly if you are now happy to.

Now that 6.0 has opened up, I'll put this in via target-arm.next
unless you'd prefer to take it.

-- PMM


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdbstub: Correct misparsing of vCont C/S requests
  2020-12-11 14:12   ` Peter Maydell
@ 2020-12-11 15:48     ` Alex Bennée
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2020-12-11 15:48 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Philippe Mathieu-Daudé, QEMU Developers


Peter Maydell <peter.maydell@linaro.org> writes:

> On Mon, 23 Nov 2020 at 13:41, Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>>
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>> > In the vCont packet, two of the command actions (C and S) take an
>> > argument specifying the signal to be sent to the process/thread, which is
>> > sent as an ASCII string of two hex digits which immediately follow the
>> > 'C' or 'S' character.
>> >
>> > Our code for parsing this packet accidentally skipped the first of the
>> > two bytes of the signal value, because it started parsing the hex string
>> > at 'p + 1' when the preceding code had already moved past the 'C' or
>> > 'S' with "cur_action = *p++".
>> >
>> > This meant that we would only do the right thing for signals below
>> > 10, and would misinterpret the rest.  For instance, when the debugger
>> > wants to send the process a SIGPROF (27 on x86-64) we mangle this into
>> > a SIGSEGV (11).
>> >
>> > Remove the accidental double increment.
>> >
>> > Fixes: https://bugs.launchpad.net/qemu/+bug/1773743
>> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>>
>> LGTM
>>
>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>
>> > ---
>> > Haven't really given this enough testing to want to put it into 5.2,
>> > I think (though it does fix the repro in the bug report).
>> > The bug has been present since commit 544177ad1cfd78 from 2017.
>>
>> I'd be happy including it. I don't have any gdbstub patches queued at
>> the moment but I could put together one if you want or you could just
>> include it directly if you are now happy to.
>
> Now that 6.0 has opened up, I'll put this in via target-arm.next
> unless you'd prefer to take it.

Go for it, I have nothing else at the moment.

>
> -- PMM


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-11 15:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-21 21:03 [PATCH] gdbstub: Correct misparsing of vCont C/S requests Peter Maydell
2020-11-23 10:39 ` Philippe Mathieu-Daudé
2020-11-23 13:41 ` Alex Bennée
2020-12-11 14:12   ` Peter Maydell
2020-12-11 15:48     ` Alex Bennée

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).