[PATCH wayland v2 1/3] tests: Demarshalling of very long array/string lengths.

2018-08-21 Thread Michal Srb
Attempting to demarshal message with array or string longer than its body should return failure. Handling the length correctly is tricky when it gets to near-UINT32_MAX values. Unexpected overflows can cause crashes and other security issues. These tests verify that demarshalling such message give

Re: [PATCH 1/3] tests: Demarshalling of very long array/string lengths.

2018-08-17 Thread Michal Srb
On pátek 17. srpna 2018 15:15:55 CEST Pekka Paalanen wrote: > Hi Michal, Hi, Thank you for the reviews. I will work on the changes. Some answers below. > > + 0x, 0xfffe, 0xfffd, 0xfffc, > > + 0xf000, 0xd000, 0xc000, 0xb000 > > What is the

[PATCH 2/3] connection: Prevent integer overflow in DIV_ROUNDUP.

2018-08-14 Thread Michal Srb
The DIV_ROUNDUP macro would overflow when trying to round values higher than MAX_UINT32 - (a - 1). The result is 0 after the division. This is potential security issue when demarshalling an array because the length check is performed with the overflowed value, but then the original huge value is st

[PATCH 1/3] tests: Demarshalling of very long array/string lengths.

2018-08-14 Thread Michal Srb
Attempting to demarshal message with array or string longer than its body should return failure. Handling the length correctly is tricky when it gets to near-UINT32_MAX values. Unexpected overflows can cause crashes and other security issues. These tests verify that demarshalling such message give

[PATCH 0/3] Fix crashes caused by near-MAX_UINT32 lengths.

2018-08-14 Thread Michal Srb
Hi, Sorry for the long delay. I rewrote it using different method. IMO it is cleaner now too. There were two kinds of overflows - integer overflow when rounding the length and pointer/integer overflow when adding the length to the `p`. So I split it into two patches + one with tests. Michal Srb

[PATCH 3/3] connection: Prevent pointer overflow from large lengths.

2018-08-14 Thread Michal Srb
If the remote side sends sufficiently large `length` field, it will overflow the `p` pointer. Technically it is undefined behavior, in practice it makes `p < end`, so the length check passes. Attempts to access the data later causes crashes. This issue manifests only on 32bit systems, but the beha

[PATCH] connection: Detect overflows in length field.

2018-07-30 Thread Michal Srb
-by: Michal Srb --- Note that the problem happens only on 32bit systems. src/connection.c| 19 +-- tests/connection-test.c | 46 ++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/connection.c b/src/connectio