Gavin Smith <gavinsmith0...@gmail.com> writes:

> On Sun, Nov 12, 2023 at 12:41:58PM +0100, John Paul Adrian Glaubitz wrote:
>
>> > diff tree.c.old tree.c -u
>> > --- tree.c.old  2023-11-04 16:15:13.632755680 +0000
>> > +++ tree.c      2023-11-04 16:16:36.211072521 +0000
>> > @@ -43,7 +43,10 @@
>> >    if (obs_element_first)
>> >      obstack_free (&obs_element, obs_element_first);
>> >    else
>> > -    obstack_init (&obs_element);
>> > +    {
>> > +      obstack_alignment_mask (&obs_element) = 7; /* 8-byte alignment */
>> > +      obstack_init (&obs_element);
>> > +    }
>> >  
>> >    obs_element_first = obstack_alloc (&obs_element, sizeof (int));
>> > 
>> > 
>> > Can you check if that works?
>> 
>> Yes, I can confirm that this patch fixes the crash for me.
>> 
>> Would be great if this fix could be included for the next release!
>
> I've added it to the release branch so if there is ever a Texinfo 7.1.1
> release, it will be included.  In the current development code, there
> are significant changes and obstacks don't appear to be used at all,
> making it a moot point.
>
> The problem should probably to be reported to the gnulib developers to
> investigate why incorrectly aligned memory was being returned.

Thanks. I'll add bug-gnulib@ and summarise below.

When building Texinfo 7.1 on sparc64, texi2any crashes with SIGBUS like:

/bin/bash: line 16: 753042 Bus error               TEXINFO_DEV_SOURCE=1 
top_srcdir=".." top_builddir=".." /usr/bin/perl ../tp/texi2any -c 
INFO_SPECIAL_CHARS_WARNING=0 -I . -o texi2any_api.info `test -
f 'texi2any_api.texi' || echo './'`texi2any_api.texi
/bin/bash: line 16: 753044 Bus error               TEXINFO_DEV_SOURCE=1 
top_srcdir=".." top_builddir=".." /usr/bin/perl ../tp/texi2any -c 
INFO_SPECIAL_CHARS_WARNING=0 -I . -o info-stnd.info `test -f
'info-stnd.texi' || echo './'`info-stnd.texi

We found this was introduced to texinfo by
83259a78038068caf3f3d8d669796ea003a63735 ('Run 'gnulib-tool --add-import
obstack' under tp/Texinfo/XS.')

When building Texinfo and running its test suite with ubsan on sparc64,
we get:


export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
./autogen.sh;  ./configure PERL_EXT_CFLAGS="-O2 -ggdb3
-fsanitize=undefined" CFLAGS="-O2 -ggdb3 -fsanitize=undefined"   ; make
-j$(nproc) ; make check -j$(nproc)

parsetexi/tree.c:77:11: runtime error: member access within misaligned address 
0x0100010e9744 for type 'struct ELEMENT', which requires 8 byte alignment
0x0100010e9744: note: pointer points here
  00 00 01 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 
00 00 00 00 00 00 00
              ^
    #0 0xfff8000102fc12ec in new_element parsetexi/tree.c:77
    #1 0xfff8000102fc12ec in new_element parsetexi/tree.c:77
    #2 0xfff8000102fabee4 in setup_document_root_and_before_node_section 
parsetexi/parser.c:521
    #3 0xfff8000102fbc584 in parse_texi_document parsetexi/parser.c:532
    #4 0xfff8000102f84338 in parse_file parsetexi/api.c:231
    #5 0xfff8000102f73f28 in XS_Texinfo__Parser_parse_file 
parsetexi/Parsetexi.c:239
    #6 0xfff80001004563bc  (/usr/lib64/libperl.so.5.38+0x1563bc)
    #7 0xfff800010044ae64 in Perl_runops_standard 
(/usr/lib64/libperl.so.5.38+0x14ae64)
    #8 0xfff800010037a2b4 in perl_run (/usr/lib64/libperl.so.5.38+0x7a2b4)
    #9 0x10000000d10 in main (/usr/bin/perl+0xd10)
    #10 0xfff800010092a894 in __libc_start_call_main 
../sysdeps/nptl/libc_start_call_main.h:58
    #11 0xfff800010092a99c in __libc_start_main_impl 
/usr/src/debug/sys-libs/glibc-2.37-r3/glibc-2.37/csu/libc-start.c:360
    #12 0x10000000d74 in _start (/usr/bin/perl+0xd74)

It appears that the obstack gnulib module is the culprit. The workaround
patch Gavin has applied to release/7.1 is at
https://git.savannah.gnu.org/cgit/texinfo.git/commit/?h=release/7.1&id=81a854e22ca2449f2351436a863e5262935f5dc0.

thanks,
sam

Reply via email to