After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 737591 - rtpgstdepay: buffer overread
rtpgstdepay: buffer overread
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other Linux
: Normal normal
: NONE
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-09-29 13:56 UTC by Vincent Penquerc'h
Modified: 2018-01-23 00:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix buffer overread (1.38 KB, patch)
2014-09-29 13:56 UTC, Vincent Penquerc'h
reviewed Details | Review
add gst_structure_from_string_n (3.19 KB, patch)
2014-10-02 09:36 UTC, Vincent Penquerc'h
none Details | Review
fix buffer overead (1.34 KB, patch)
2014-10-02 09:37 UTC, Vincent Penquerc'h
none Details | Review

Description Vincent Penquerc'h 2014-09-29 13:56:16 UTC
Created attachment 287354 [details] [review]
fix buffer overread

This ensures we don't read a string past the end of the buffer.
One could make an argument that the terminating NUL should be included in the data instead. This seems safer (and would have to be done anyway since the data might be corrupt).
Comment 1 Tim-Philipp Müller 2014-10-01 22:44:38 UTC
Comment on attachment 287354 [details] [review]
fix buffer overread

Makes sense and should be fixed IMHO, but would be nice to avoid the dup if not required (these strings can be really huge).
Comment 2 Edward Hervey 2014-10-02 07:09:53 UTC
Shouldn't we have a gst_structure_from_string_n(gchar *str, gint size) ? Having a function that deals with strings without checking them seems dangerous to start with.
Comment 3 Vincent Penquerc'h 2014-10-02 09:36:50 UTC
Created attachment 287569 [details] [review]
add gst_structure_from_string_n

Like this ?
Comment 4 Vincent Penquerc'h 2014-10-02 09:37:30 UTC
Created attachment 287570 [details] [review]
fix buffer overead
Comment 5 Tim-Philipp Müller 2014-10-02 12:40:24 UTC
Well, if it's not 0-terminated it's by definition not a valid string, so arguably in the 0.0000001% of the cases where we process untrusted data we might just as well go through the trouble of checking. It would also be ok to just ignore the input then in such code, arguably. So not sure if we really need to add new API for this one use case.

If we do, do we want to keep the end out argument? (Which is only used internally by gstreamer when deserializing caps I think) (And which shouldn't have been in the from_string() API in the first place).
Comment 6 Wim Taymans 2014-11-20 11:48:00 UTC
I think this is the best patch, check if the delimiter is where it is expected and refuse all other input. For the caps caps with the 0-terminator, this is ok but I'm unsure if it's possible to escape the ; somewhere in a valid event..

commit 9d2902d978905acf3ecc88dd331b20072dc9eab0
Author: Wim Taymans <wtaymans@redhat.com>
Date:   Thu Nov 20 12:40:28 2014 +0100

    rtpgstdepay: avoid buffer overread.
    
    Check that a caps event string is 0 terminated and the event string is
    terminated with a ; to avoid buffer overreads.
Comment 7 Wim Taymans 2014-11-20 12:18:12 UTC
A little better but still dangerous because core will read past the 0-byte when \ is the last char of the string.

commit 3d7b0f30d748ad1c8e2c5d3528bfbdfe21cfde60
Author: Wim Taymans <wtaymans@redhat.com>
Date:   Thu Nov 20 13:14:14 2014 +0100

    rtpgstpay: put 0-byte at the end of events
    
    Put a 0-byte at the end of the event string. Does not break ABI because
    old depayloaders will skip the 0 byte (which is included in the length).
    Expect a 0-byte at the end of the event string or a ; for old
    payloaders.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=737591
Comment 8 Sebastian Dröge (slomo) 2014-11-20 20:52:04 UTC
Is this complete with this commit? Also should we backport the rtgst* changes to 1.4 too? Seems relatively safe, I'm just a little bit worried that we missed a backwards incompatible change in here.


commit 5cf630697c55c49c60862494712c9f32f55fcf0f
Author: Wim Taymans <wtaymans@redhat.com>
Date:   Thu Nov 20 13:34:32 2014 +0100

    structure: don't overread input when searching for "
    
    When searching for the string terminator don't read past the ending
    0-byte when escaping characters.
    Add unit test for various escaping cases.
Comment 9 Wim Taymans 2014-11-21 15:53:48 UTC
(In reply to comment #8)
> Is this complete with this commit? Also should we backport the rtgst* changes
> to 1.4 too? Seems relatively safe, I'm just a little bit worried that we missed
> a backwards incompatible change in here.

I think it's safe to backport. I can't see a scenario that would cause failure.

the compatibility matrix is like:

* old pay -> old depay: 

     no change, with upgraded core it would not crash on certain malformed input.

* old pay -> new depay: 

    new depay finds ; at end and parses the message. core change doesn't matter.

* new pay -> old depay:

    new depay puts extra 0 after string. old depay just parses and skips the extra 0 byte (because it is included in the length). With new core, certain malformed payloads are not crashing.

* new pay -> new depay:

   new pay adds extra 0 after string, new depay checks for 0 and decodes. new core will avoid certain buffer overreads.
Comment 10 Sebastian Dröge (slomo) 2014-11-24 10:52:24 UTC
Backported :) Can we close this bug now or does anybody think the other things should be merged too?