It looks like memmove() is broken by design for mips. This has come up before in a previous thread, but with no proper resolution: https://mailman.uclibc-ng.org/pipermail/devel/2016-April/000837.html
Per the man pages and posix specification, memmove() must work with overlapping regions: https://linux.die.net/man/3/memmove https://www.unix.com/man-page/POSIX/3posix/memmove/
Unless __ARCH_HAS_BWD_MEMCPY__ is set, the generic memmove() (which is used for mips) will use memcpy() when the destination pointer is lower than the source pointer, whether the regions are overlapping or not.
The author of libc/string/mips/memcpy.S is clear about the fact that the mips implementation for memcpy() cannot deal with overlapping regions. For Android, support for overlapping regions seems to be required for memcpy(), so memcpy() will offload to memmove() when an overlap occurs. How this could work with memmove() again offloading to memcpy() on mips is lost on me.
I am observing the problem on a big-endian mips 34kc with OpenSSL. We are using nginx as an https webserver with openssl as the ssl library. We observed unexpected Message Authentication Code failures when data was received.
After some detective work, we were observing the uClibc memmove() occasionally copying a source buffer cache-line worth of zero's (32 bytes) to the destination buffer instead of the actual source data.
Needless to say, I do not know of a cipher that plays nicely when the input buffer suffers from Alzheimer's. The OpenSSL implementation of the GCM-128 cipher rightfully fails the tag check from it's perspective, returning a Message Authentication Code failure to the client.
I quick solution is to always define __ARCH_HAS_BWD_MEMCPY__ on mips, but I do not consider that a clear expression of the intent.
Can anyone comment on this?
- Pieter Smith
Hi, Pieter Smith wrote,
It looks like memmove() is broken by design for mips. This has come up before in a previous thread, but with no proper resolution: https://mailman.uclibc-ng.org/pipermail/devel/2016-April/000837.html
IIRC, the solution was found later, see: https://mailman.uclibc-ng.org/pipermail/devel/2016-May/000918.html
Disable UCLIBC_USE_MIPS_PREFETCH. Prefetch is broken on some MIPS cores.
best regards Waldemar
On Wed, Mar 28, 2018 at 08:27:26PM +0200, Waldemar Brodkorb wrote:
Hi, Pieter Smith wrote,
It looks like memmove() is broken by design for mips. This has come up before in a previous thread, but with no proper resolution: https://mailman.uclibc-ng.org/pipermail/devel/2016-April/000837.html
IIRC, the solution was found later, see: https://mailman.uclibc-ng.org/pipermail/devel/2016-May/000918.html
Thanks! I missed that one.
Disable UCLIBC_USE_MIPS_PREFETCH. Prefetch is broken on some MIPS cores.
Pity. This was only introduced in v1.0.15. We are still stuck with OpenWRT Chaos Calmer for which the toolchain is based on v1.0.14. We should be switching to OpenWRT DD soon, so I should be able to disable UCLIBC_USE_MIPS_PREFETCH.
I did however notice that this is not done even on the latest OpenWRT. I will go knocking on the OpenWRT communitie's door.
best regards Waldemar
Thanks, Pieter
Hi,
I believe OpenWrt disabled uClibc-ng support later.
good luck Waldemar
Am 28.03.2018 um 20:54 schrieb Pieter Smith pieter@boesman.nl:
On Wed, Mar 28, 2018 at 08:27:26PM +0200, Waldemar Brodkorb wrote: Hi, Pieter Smith wrote,
It looks like memmove() is broken by design for mips. This has come up before in a previous thread, but with no proper resolution: https://mailman.uclibc-ng.org/pipermail/devel/2016-April/000837.html
IIRC, the solution was found later, see: https://mailman.uclibc-ng.org/pipermail/devel/2016-May/000918.html
Thanks! I missed that one.
Disable UCLIBC_USE_MIPS_PREFETCH. Prefetch is broken on some MIPS cores.
Pity. This was only introduced in v1.0.15. We are still stuck with OpenWRT Chaos Calmer for which the toolchain is based on v1.0.14. We should be switching to OpenWRT DD soon, so I should be able to disable UCLIBC_USE_MIPS_PREFETCH.
I did however notice that this is not done even on the latest OpenWRT. I will go knocking on the OpenWRT communitie's door.
best regards Waldemar
Thanks, Pieter
On Wed, Mar 28, 2018 at 09:12:09PM +0200, Waldemar Brodkorb wrote:
Hi,
I believe OpenWrt disabled uClibc-ng support later.
Nope. The default may now be MUSL, but uClibc still is available as a libc option on master, and the version was bumped to v1.0.28 two months ago, so it definitely appears to be in use: https://github.com/openwrt/openwrt/tree/master/toolchain/uClibc
The uClibc-ng config however makes no mention of UCLIBC_USE_MIPS_PREFETCH, so by default it will be enabled: https://github.com/openwrt/openwrt/blob/master/toolchain/uClibc/config/mips
I will log an issue on this so others don't fall victim to this.
good luck Waldemar
Am 28.03.2018 um 20:54 schrieb Pieter Smith pieter@boesman.nl:
On Wed, Mar 28, 2018 at 08:27:26PM +0200, Waldemar Brodkorb wrote: Hi, Pieter Smith wrote,
It looks like memmove() is broken by design for mips. This has come up before in a previous thread, but with no proper resolution: https://mailman.uclibc-ng.org/pipermail/devel/2016-April/000837.html
IIRC, the solution was found later, see: https://mailman.uclibc-ng.org/pipermail/devel/2016-May/000918.html
Thanks! I missed that one.
Disable UCLIBC_USE_MIPS_PREFETCH. Prefetch is broken on some MIPS cores.
Pity. This was only introduced in v1.0.15. We are still stuck with OpenWRT Chaos Calmer for which the toolchain is based on v1.0.14. We should be switching to OpenWRT DD soon, so I should be able to disable UCLIBC_USE_MIPS_PREFETCH.
I did however notice that this is not done even on the latest OpenWRT. I will go knocking on the OpenWRT communitie's door.
best regards Waldemar
Thanks, Pieter
- Pieter
Hi,
but only for ARC architecture: https://github.com/openwrt/openwrt/blob/master/toolchain/Config.in
It is marked broken for others. I couldn't convince them to enable it as a choice for other architectures.
best regards Waldemar
Am 28.03.2018 um 22:51 schrieb Pieter Smith pieter@boesman.nl:
On Wed, Mar 28, 2018 at 09:12:09PM +0200, Waldemar Brodkorb wrote: Hi,
I believe OpenWrt disabled uClibc-ng support later.
Nope. The default may now be MUSL, but uClibc still is available as a libc option on master, and the version was bumped to v1.0.28 two months ago, so it definitely appears to be in use: https://github.com/openwrt/openwrt/tree/master/toolchain/uClibc
The uClibc-ng config however makes no mention of UCLIBC_USE_MIPS_PREFETCH, so by default it will be enabled: https://github.com/openwrt/openwrt/blob/master/toolchain/uClibc/config/mips
I will log an issue on this so others don't fall victim to this.
good luck Waldemar
Am 28.03.2018 um 20:54 schrieb Pieter Smith pieter@boesman.nl:
On Wed, Mar 28, 2018 at 08:27:26PM +0200, Waldemar Brodkorb wrote: Hi, Pieter Smith wrote,
It looks like memmove() is broken by design for mips. This has come up before in a previous thread, but with no proper resolution: https://mailman.uclibc-ng.org/pipermail/devel/2016-April/000837.html
IIRC, the solution was found later, see: https://mailman.uclibc-ng.org/pipermail/devel/2016-May/000918.html
Thanks! I missed that one.
Disable UCLIBC_USE_MIPS_PREFETCH. Prefetch is broken on some MIPS cores.
Pity. This was only introduced in v1.0.15. We are still stuck with OpenWRT Chaos Calmer for which the toolchain is based on v1.0.14. We should be switching to OpenWRT DD soon, so I should be able to disable UCLIBC_USE_MIPS_PREFETCH.
I did however notice that this is not done even on the latest OpenWRT. I will go knocking on the OpenWRT communitie's door.
best regards Waldemar
Thanks, Pieter
- Pieter
On Thu, Mar 29, 2018 at 04:43:58AM +0200, Waldemar Brodkorb wrote:
Hi,
but only for ARC architecture: https://github.com/openwrt/openwrt/blob/master/toolchain/Config.in
It is marked broken for others. I couldn't convince them to enable it as a choice for other architectures.
Pity. Thanks for trying anyway.
best regards Waldemar
- Pieter