Bug#932787: Bus error on sparc64

2019-07-24 Thread Uwe Kleine-König
Control: tag -1 + upstream
Control: forwarded -1 https://github.com/plougher/squashfs-tools/pull/65

Hello,

I created a pull request on github to fix this issue.

Best regards
Uwe


signature.asc
Description: PGP signature


Bug#932787: Bus error on sparc64

2019-07-24 Thread Uwe Kleine-König
Hello,

On 7/23/19 11:39 PM, László Böszörményi (GCS) wrote:
> Control: tags -1 +moreinfo

This is unusual. According to https://www.debian.org/Bugs/Developer#tags
the meaning of this tag is "This bug can't be addressed until more
information is provided by the submitter. The bug will be closed if the
submitter doesn't provide more information in a reasonable (few months)
timeframe."

> On Tue, Jul 23, 2019 at 11:09 PM Uwe Kleine-König  
> wrote:
>> On Tue, Jul 23, 2019 at 09:14:53AM +, Uwe Kleine-König wrote:
>>> the test suite for rauc (currently in NEW) provokes a Bus error in
>>> mksquashfs on sparc64 (tested on kyoto.debian.net in a sid chroot).
>>> Reproduction is as follows:
>>>
>>>   install casync dbus dbus-x11 debhelper e2fsprogs faketime grub-common 
>>> libcurl4-gnutls-dev, libglib2.0-dev, libjson-glib-dev libssl-dev libtool 
>>> squashfs-tools systemd git
>>>
>>>   git clone https://github.com/rauc/rauc.git
>>>   sed -i 's/0x73717368$/GUINT32_FROM_LE(0x73717368)/' src/bundle.c
>>>   sh autogen.sh
>>>   ./configure
>>>   make check
>>>   rm -rf /tmp/rauc-*
>>>   ./test/bundle.test
>>>
>>> The last command fails with
>>> "rauc:ERROR:test/common.c:339:test_create_bundle:
>>> 'create_bundle(bundlename, contentdir, NULL)' should be TRUE" and leaves
>>> behind a directory that allows to reproduce the issue:
>>>
>>>   $ rm -f image; mksquashfs /tmp/rauc-*/content image
>>>   Parallel mksquashfs: Using 32 processors
>>>   Creating 4.0 filesystem on image, block size 131072.
>>>   Bus error
>>
>> The problem is in all_zero from squashfs-tools/mksquashfs.c:
>>
>> int all_zero(struct file_buffer *file_buffer)
>> {
>> int i;
>> long entries = file_buffer->size / sizeof(long);
>> long *p = (long *) file_buffer->data;
>>
>> for(i = 0; i < entries && p[i] == 0; i++);
>>
>> if(i == entries) {
>> for(i = file_buffer->size & ~(sizeof(long) - 1);
>> i < file_buffer->size && file_buffer->data[i] == 0;
>> i++);
>>
>> return i == file_buffer->size;
>> }
>>
>> return 0;
>> }
>>
>> If file_buffer->data isn't a multiple of sizeof(long) the access to p[0]
>> traps on sparc.
>>
>> Replacing that by:
>>
>> int all_zero(struct file_buffer *file_buffer)
>> {
>> int i;
>>
>> for(i = 0; i < file_buffer->size; i++)
>> if (file_buffer->data[i] != 0)
>> return 0;
>>
>> return 1;
>> }
>>
>> should fix it. On architectures that fixup unaligned accesses in the
>> kernel it is probably even faster.

My book about C ("C - A reference manual" by Samuel P. Harbison III and
Guy L. Steele Jr.) has:

If the alignment requirement for a type S is less stringent than
that for type D, then the conversion from a "pointer to type S"
to a "pointer to type D" could result in either of two kinds of
unexpected behaviour. First, an attempt to use the resulting
pointer to fetch or store an object of type D may cause an
error, halting the program. Second, either the hardware or the
implementation may "adjust" the destination pointer to be valid,
usually by forcing it back to the nearest previous valid
address. A subsequent conversion back to the original pointer
type may not recover the original pointer.

So all kind of strange things can happen, it seems sparc64 is the only
Architecture in Debian that traps on unaligned accesses, see also
https://wiki.debian.org/ArchitectureSpecificsMemo#Alignment

Best regards
Uwe



signature.asc
Description: OpenPGP digital signature


Bug#932787: Bus error on sparc64

2019-07-24 Thread Uwe Kleine-König
Control: affects -1 + rauc

(Note that rauc is still in NEW, I hope that this affects works anyhow.
This bug will make rauc FTBFS on sparc64.)

On Tue, Jul 23, 2019 at 09:14:53AM +, Uwe Kleine-König wrote:
> the test suite for rauc (currently in NEW) provokes a Bus error in
> mksquashfs on sparc64 (tested on kyoto.debian.net in a sid chroot).
> Reproduction is as follows:
> 
>   install casync dbus dbus-x11 debhelper e2fsprogs faketime grub-common 
> libcurl4-gnutls-dev, libglib2.0-dev, libjson-glib-dev libssl-dev libtool 
> squashfs-tools systemd git
> 
>   git clone https://github.com/rauc/rauc.git
>   sed -i 's/0x73717368$/GUINT32_FROM_LE(0x73717368)/' src/bundle.c
>   sh autogen.sh
>   ./configure
>   make check
>   rm -rf /tmp/rauc-*
>   ./test/bundle.test

An easier trigger is to have a file that is at least 1 block (i.e.
131072 bytes) big.

So:

$ mkdir tmp

$ rm -f image

$ dd if=/dev/zero of=tmp/file bs=131072 count=1
1+0 records in
1+0 records out
131072 bytes (131 kB, 128 KiB) copied, 0.00163719 s, 80.1 MB/s

$ mksquashfs tmp image
Parallel mksquashfs: Using 32 processors
Creating 4.0 filesystem on image, block size 131072.
Bus error

Best regards
Uwe


signature.asc
Description: PGP signature


Bug#932787: Bus error on sparc64

2019-07-23 Thread GCS
Control: tags -1 +moreinfo

Hi Phillip,

On Tue, Jul 23, 2019 at 11:09 PM Uwe Kleine-König  
wrote:
> On Tue, Jul 23, 2019 at 09:14:53AM +, Uwe Kleine-König wrote:
> > the test suite for rauc (currently in NEW) provokes a Bus error in
> > mksquashfs on sparc64 (tested on kyoto.debian.net in a sid chroot).
> > Reproduction is as follows:
> >
> >   install casync dbus dbus-x11 debhelper e2fsprogs faketime grub-common 
> > libcurl4-gnutls-dev, libglib2.0-dev, libjson-glib-dev libssl-dev libtool 
> > squashfs-tools systemd git
> >
> >   git clone https://github.com/rauc/rauc.git
> >   sed -i 's/0x73717368$/GUINT32_FROM_LE(0x73717368)/' src/bundle.c
> >   sh autogen.sh
> >   ./configure
> >   make check
> >   rm -rf /tmp/rauc-*
> >   ./test/bundle.test
> >
> > The last command fails with
> > "rauc:ERROR:test/common.c:339:test_create_bundle:
> > 'create_bundle(bundlename, contentdir, NULL)' should be TRUE" and leaves
> > behind a directory that allows to reproduce the issue:
> >
> >   $ rm -f image; mksquashfs /tmp/rauc-*/content image
> >   Parallel mksquashfs: Using 32 processors
> >   Creating 4.0 filesystem on image, block size 131072.
> >   Bus error
>
> The problem is in all_zero from squashfs-tools/mksquashfs.c:
>
> int all_zero(struct file_buffer *file_buffer)
> {
> int i;
> long entries = file_buffer->size / sizeof(long);
> long *p = (long *) file_buffer->data;
>
> for(i = 0; i < entries && p[i] == 0; i++);
>
> if(i == entries) {
> for(i = file_buffer->size & ~(sizeof(long) - 1);
> i < file_buffer->size && file_buffer->data[i] == 0;
> i++);
>
> return i == file_buffer->size;
> }
>
> return 0;
> }
>
> If file_buffer->data isn't a multiple of sizeof(long) the access to p[0]
> traps on sparc.
>
> Replacing that by:
>
> int all_zero(struct file_buffer *file_buffer)
> {
> int i;
>
> for(i = 0; i < file_buffer->size; i++)
> if (file_buffer->data[i] != 0)
> return 0;
>
> return 1;
> }
>
> should fix it. On architectures that fixup unaligned accesses in the
> kernel it is probably even faster.
 May you comment on this change from Uwe?

Thanks,
Laszlo/GCS



Bug#932787: Bus error on sparc64

2019-07-23 Thread Uwe Kleine-König
Control: tag -1 + patch

Hello,

On Tue, Jul 23, 2019 at 09:14:53AM +, Uwe Kleine-König wrote:
> Package: squashfs-tools
> Version: 1:4.3-12
> Severity: normal
> 
> Hello,
> 
> the test suite for rauc (currently in NEW) provokes a Bus error in
> mksquashfs on sparc64 (tested on kyoto.debian.net in a sid chroot).
> Reproduction is as follows:
> 
>   install casync dbus dbus-x11 debhelper e2fsprogs faketime grub-common 
> libcurl4-gnutls-dev, libglib2.0-dev, libjson-glib-dev libssl-dev libtool 
> squashfs-tools systemd git
> 
>   git clone https://github.com/rauc/rauc.git
>   sed -i 's/0x73717368$/GUINT32_FROM_LE(0x73717368)/' src/bundle.c
>   sh autogen.sh
>   ./configure
>   make check
>   rm -rf /tmp/rauc-*
>   ./test/bundle.test
> 
> The last command fails with
> "rauc:ERROR:test/common.c:339:test_create_bundle:
> 'create_bundle(bundlename, contentdir, NULL)' should be TRUE" and leaves
> behind a directory that allows to reproduce the issue:
> 
>   $ rm -f image; mksquashfs /tmp/rauc-*/content image
>   Parallel mksquashfs: Using 32 processors
>   Creating 4.0 filesystem on image, block size 131072.
>   Bus error

The problem is in all_zero from squashfs-tools/mksquashfs.c:

int all_zero(struct file_buffer *file_buffer)
{
int i;
long entries = file_buffer->size / sizeof(long);
long *p = (long *) file_buffer->data;

for(i = 0; i < entries && p[i] == 0; i++);

if(i == entries) {
for(i = file_buffer->size & ~(sizeof(long) - 1);
i < file_buffer->size && file_buffer->data[i] == 0;
i++);

return i == file_buffer->size;
}

return 0;
}

If file_buffer->data isn't a multiple of sizeof(long) the access to p[0]
traps on sparc.

Replacing that by:

int all_zero(struct file_buffer *file_buffer)
{
int i;

for(i = 0; i < file_buffer->size; i++)
if (file_buffer->data[i] != 0)
return 0;

return 1;
}

should fix it. On architectures that fixup unaligned accesses in the
kernel it is probably even faster.

Best regards
Uwe


signature.asc
Description: PGP signature


Bug#932787: Bus error on sparc64

2019-07-23 Thread Uwe Kleine-König
Package: squashfs-tools
Version: 1:4.3-12
Severity: normal

Hello,

the test suite for rauc (currently in NEW) provokes a Bus error in
mksquashfs on sparc64 (tested on kyoto.debian.net in a sid chroot).
Reproduction is as follows:

install casync dbus dbus-x11 debhelper e2fsprogs faketime grub-common 
libcurl4-gnutls-dev, libglib2.0-dev, libjson-glib-dev libssl-dev libtool 
squashfs-tools systemd git

git clone https://github.com/rauc/rauc.git
sed -i 's/0x73717368$/GUINT32_FROM_LE(0x73717368)/' src/bundle.c
sh autogen.sh
./configure
make check
rm -rf /tmp/rauc-*
./test/bundle.test

The last command fails with
"rauc:ERROR:test/common.c:339:test_create_bundle:
'create_bundle(bundlename, contentdir, NULL)' should be TRUE" and leaves
behind a directory that allows to reproduce the issue:

$ rm -f image; mksquashfs /tmp/rauc-*/content image
Parallel mksquashfs: Using 32 processors
Creating 4.0 filesystem on image, block size 131072.
Bus error

Best regards
Uwe

-- System Information:
Debian Release: 10.0
  APT prefers unreleased
  APT policy: (500, 'unreleased'), (500, 'unstable')
Architecture: sparc64

Kernel: Linux 4.19.0-5-sparc64-smp (SMP w/32 CPU cores)
Locale: LANG=C, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=C (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: unable to detect

Versions of packages squashfs-tools depends on:
ii  libc6  2.28-10
ii  liblz4-1   1.8.3-1
ii  liblzma5   5.2.4-1
ii  liblzo2-2  2.10-0.1
ii  libzstd1   1.3.8+dfsg-3
ii  zlib1g 1:1.2.11.dfsg-1

squashfs-tools recommends no packages.

squashfs-tools suggests no packages.

-- no debconf information