<div dir="ltr"><div dir="ltr">On Fri, Oct 27, 2023 at 1:12 PM HAGIO KAZUHITO(萩尾 一仁) <<a href="mailto:k-hagio-ab@nec.com">k-hagio-ab@nec.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2023/10/27 12:44, lijiang wrote:<br>
> On Wed, Oct 25, 2023 at 4:09 PM HAGIO KAZUHITO(萩尾 一仁) <<a href="mailto:k-hagio-ab@nec.com" target="_blank">k-hagio-ab@nec.com</a>><br>
> wrote:<br>
> <br>
>> On 2023/10/24 18:10, Lianbo Jiang wrote:<br>
>>> This is a backport patch from gdb commit 58abdf887821 ("Verify COFF<br>
>>> symbol stringtab offset").<br>
>>><br>
>>> The AddressSanitizer reports a heap-use-after-free error as below:<br>
>>>     gdb/coff-pe-read.c:137:27<br>
>>><br>
>>> Add a COFF offset check to fix this issue.<br>
>>><br>
>>> Link: <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=30640" rel="noreferrer" target="_blank">https://sourceware.org/bugzilla/show_bug.cgi?id=30640</a><br>
>>> Signed-off-by: Lianbo Jiang <<a href="mailto:lijiang@redhat.com" target="_blank">lijiang@redhat.com</a>><br>
>><br>
>> Thank you for working on this issue.<br>
>><br>
>>> ---<br>
>>> Please see the CVE-2023-39129.<br>
>>><br>
>>>    gdb-10.2.patch | 31 +++++++++++++++++++++++++++++++<br>
>>>    1 file changed, 31 insertions(+)<br>
>>><br>
>>> diff --git a/gdb-10.2.patch b/gdb-10.2.patch<br>
>>> index 7f4b86350bde..98538dc1138b 100644<br>
>>> --- a/gdb-10.2.patch<br>
>>> +++ b/gdb-10.2.patch<br>
>>> @@ -3156,4 +3156,35 @@ exit 0<br>
>>>    +      else if (i >= 0 && encoded[i] == '$')<br>
>>>             len0 = i;<br>
>>>         }<br>
>>> +<br>
>><br>
>> No actual problem, but this empty '+' line is some strange... my working<br>
> <br>
> <br>
> Thank you for the comment, Kazu.<br>
> <br>
> After removing the empty "+" line, I got the following information during<br>
> compiling process.<br>
> ...<br>
> patching file gdb-10.2/gdb/coffread.c<br>
> Hunk #3 succeeded at 1318 with fuzz 1.<br>
<br>
yes, because there is need to shift a line like this:<br>
<br></blockquote><div>Good to me, thanks.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
--- a/gdb-10.2.patch<br>
+++ b/gdb-10.2.patch<br>
@@ -3157,3 +3157,33 @@ exit 0<br>
           len0 = i;<br>
       }<br>
<br>
+--- gdb-10.2/gdb/coffread.c.orig<br>
++++ gdb-10.2/gdb/coffread.c<br>
<br>
> ...<br>
> <br>
> But, maybe we can ignore the above output.<br>
> <br>
> <br>
>><br>
>> tree at a8e5e4cbae54 already has a space line at the end of file:<br>
>><br>
>> $ tail -n 5 gdb-10.2.patch | tr ' ' '-'<br>
>> -------else-if-(encoded[i]-==-'$')<br>
>> +------else-if-(i->=-0-&&-encoded[i]-==-'$')<br>
>> ---------len0-=-i;<br>
>> -----}<br>
>> -<br>
>><br>
>> but anyway, I can fix this while merging.<br>
>><br>
>> Ok.<br>
> <br>
> <br>
>>> +--- gdb-10.2/gdb/coffread.c.orig<br>
>>> ++++ gdb-10.2/gdb/coffread.c<br>
>>> +@@ -159,6 +159,7 @@ static long linetab_offset;<br>
>>> + static unsigned long linetab_size;<br>
>>> +<br>
>>> + static char *stringtab = NULL;<br>
>>> ++static long stringtab_length = 0;<br>
>>> +<br>
>>> + extern void stabsread_clear_cache (void);<br>
>>> +<br>
>>> +@@ -1297,6 +1298,7 @@ init_stringtab (bfd *abfd, long offset,<br>
>> gdb::unique_xmalloc_ptr<char> *storage)<br>
>>> +   /* This is in target format (probably not very useful, and not<br>
>>> +      currently used), not host format.  */<br>
>>> +   memcpy (stringtab, lengthbuf, sizeof lengthbuf);<br>
>>> ++  stringtab_length = length;<br>
>>> +   if (length == sizeof length)      /* Empty table -- just the count.<br>
>> */<br>
>>> +     return 0;<br>
>>> +<br>
>>> +@@ -1316,8 +1318,9 @@ getsymname (struct internal_syment *symbol_entry)<br>
>>> +<br>
>>> +   if (symbol_entry->_n._n_n._n_zeroes == 0)<br>
>>> +     {<br>
>>> +-      /* FIXME: Probably should be detecting corrupt symbol files by<br>
>>> +-         seeing whether offset points to within the stringtab.  */<br>
>>> ++      if (symbol_entry->_n._n_n._n_offset > stringtab_length)<br>
>>> ++        error (_("COFF Error: string table offset (%ld) outside string<br>
>> table (length %ld)"),<br>
>>> ++               symbol_entry->_n._n_n._n_offset, stringtab_length);<br>
>>> +       result = stringtab + symbol_entry->_n._n_n._n_offset;<br>
>>> +     }<br>
>>> +   else<br>
>>><br>
>><br>
>> Just out of curiosity, do you have any information that crash can be<br>
> <br>
> <br>
> I did not reproduce it in crash-utility, and got the bug from the reporter.<br>
<br>
OK, thanks.<br>
<br>
> <br>
> <br>
>><br>
>> affected by this issue?  I don't know about the COFF, I wonder if the<br>
> <br>
> <br>
> Me too.<br>
> <br>
> embedded gdb does not use this, aside from an independent gdb..<br>
>><br>
>><br>
> I just saw that the coff format was removed from gcc 8, so probably the gdb<br>
> does not use the coff format.<br>
> <br>
> I copied the following text from the link:<br>
> ---<br>
> Caveats<br>
> Support for the obsolete SDB/coff debug info format has been removed. The<br>
> option -gcoff no longer does anything.<br>
> ...<br>
> ---<br>
> Here is the link: <a href="https://gcc.gnu.org/gcc-8/changes.html" rel="noreferrer" target="_blank">https://gcc.gnu.org/gcc-8/changes.html</a><br>
> <br>
> But I'm not sure if there are people who might compile crash-utility with<br>
> the old gcc( eg. < gcc 8), if no, we can drop this patch, and no need to<br>
> fix it. Any thoughts?<br>
<br>
I think that what compiles crash doesn't matter.  Apparently the issue <br>
was reproduced by a crafted debuginfo.<br>
<br>
<a href="https://inbox.sourceware.org/gdb-patches/20230822152335.231921-1-keiths@redhat.com/T/#u" rel="noreferrer" target="_blank">https://inbox.sourceware.org/gdb-patches/20230822152335.231921-1-keiths@redhat.com/T/#u</a><br>
<br>
Crash may not be affected with crash-specific checks, but it will be <br>
very hard to prove it.  GDB maintainers decided to fix this, let's have <br>
it in the same way..  Hopefully it's removed in future :)<br>
<br>
So applied.<br>
<a href="https://github.com/crash-utility/crash/commit/fc6ed525407ffc6a181ab9b902f2fb23936309d2" rel="noreferrer" target="_blank">https://github.com/crash-utility/crash/commit/fc6ed525407ffc6a181ab9b902f2fb23936309d2</a><br>
<br></blockquote><div> </div><div>Ok, thanks.</div><div><br></div><div>Lianbo</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks,<br>
Kazu<br>
</blockquote></div></div>