Open ildar opened 5 years ago
this is the regression: rolling back to 1.4.1 fixed the issue.
string=0x40459b8d1e6d15bc <error: Cannot access memory at address 0x40459b8d1e6d15bc>
That sounds like some nasty memory corruption bug. Shit.
Likely same as #525
I have done a rough analysis of this, but not made a fix (and don't intend to do so).
The crash is here, when tgl_message_media_geo
is received:
https://github.com/majn/telegram-purple/blob/44a1349bf4c57e8b648dae113ec7cf3bdbde0789/tgp-msg.c#L749-L750
That caption
field is in a union with geo data:
https://github.com/majn/tgl/blob/bec2e6d537c272ed185e8c41ff81b4b8521a131d/tgl-layout.h#L569-L581
The geo data is written here (which fills the caption fields memory with non-char*
data):
https://github.com/majn/tgl/blob/bec2e6d537c272ed185e8c41ff81b4b8521a131d/structures.c#L803-L806
Similar issues might also affect other package types.
I consider this to be a bug in https://github.com/majn/telegram-purple/blob/44a1349bf4c57e8b648dae113ec7cf3bdbde0789/tgp-msg.c#L749-L750
It implies that the caption field is empty. This is not true. It's a union and it only seems to be valid for these 2 types: https://github.com/majn/tgl/blob/bec2e6d537c272ed185e8c41ff81b4b8521a131d/tgl-layout.h#L572-L573
This shows that the union/structure mix is very bad design that's hard to decipher.
The photo and document types each have their own caption
field anyway (which is probably meant to be used; or it's a different feature using a confusing name).
Another instance of the same problem appears to be in this: https://github.com/majn/telegram-purple/blob/44a1349bf4c57e8b648dae113ec7cf3bdbde0789/tgp-msg.c#L527-L535
There might be more locations where this is bad.
The bug was introduced by a couple of people doing stupid things. https://github.com/majn/telegram-purple/commit/9e6a0e850a3640eed5c14259129a62b210218e4d is a prominent one because it moved the check from the photo specific handler to all messages, and it introduced bad assumptions. However, the original implementation of the photo captions is equally horrible (as it introduces features which easily break): https://github.com/majn/tgl/commit/a4588778f998d0f27fb7e342a84b2b4ab56274dc
I think the proper solution is to remove the caption
field as it too easy to break other union members.
Ideally, all of these anonymous structs should be avoided in the union - they don't seem to follow any logical pattern.
Also the code that touches captions should be refactored, so it only ever touches captions of objects.
A temporary workaround that I've applied locally, is to move the caption
out of the union:
[...]
struct tgl_message_media {
enum tgl_message_media_type type;
char *caption; // Added here
union {
struct {
union {
struct tgl_photo *photo;
struct tgl_document *document;
};
// Removed from here
};
[...]
I don't feel confident in this workaround though - the code is so bad, that there might still be uninitialized accesses somehow. Also the same issue could still happen for other members of the union.
I had already intended to migrate away from purple due to frustration with pidgins lack of modern features and the quality of protocol plugins in recent years (also particularly telegram-purple). Reviewing the code and how poorly this situation was dealt with shows how critical it should be to move away from telegram-purple ("This looks a lot like memory corruption. In other words I won't be able to fix it" - in a security relevant piece of code!). Maintainers of a protocol plugin should be able to debug these sort of issues; it only takes a matter of seconds: reproduce it, find erroneous access, add watchpoint, analyze.
Dude, this is free software. The original maintainer of the library @vysheng has been inactive for very long. I'm only a user who tries to keep it in a "good enough" state for myself. You're barking up the wrong tree.
Come down from your high horse, and implement it better. We nowhere claimed that telegram-purple is good. In fact, I already recommend that people use something else, or implement something better: #480
Finally, telegram-purple is a plugin, and not part of pidgin.
it only takes a matter of seconds: reproduce it, find erroneous access, add watchpoint, analyze.
Then do it? PRs are extremely welcome, and you'll get write access immediately.
Dude, this is free software. [...] You're barking up the wrong tree.
Maintaining free software still comes with responsibilities. While I'm grateful for the existence of projects like this, it doesn't excuse the state of the project.
We nowhere claimed that telegram-purple is good. In fact, I already recommend that people use something else, or implement something better: #480
That is a technical discussion about switching the backend, not a recommendation [to users] to "use something else" [other than telegram-purple].
I think this bug could be a security relevant issue in this software. All functions using these buffers that I have seen seem to be safe (g_strdup
); however, it's really hard to know for sure. The way the code reads wrong fields from a union could still potentially allow an attacker to control values maliciously somewhere.
This could possibly allow gadgets for a more powerful attack (such as Remote-Code-Execution).
So until this is analyzed, the code should be rolled back to a safe revision. If code can't be easily reverted, the proper response would be to shut this project down (at least temporarily) and explain in the README that it is potentially unsafe to use. If maintainers can't fix it, then they should be clear about this, and advise users to stay away.
I'm only a user who tries to keep it in a "good enough" state for myself
Fair enough. But this should be documented prominently. Packagers should be advised to not package it anymore.
If you make it available publicly, then it should be safe, and potential security risks should be avoided (and reports taken seriously).
Come down from your high horse, [...]
No need for personal attacks.
[...] and implement it better.
I don't think that pointing out problems comes with responsibility to "do it better". I have also already spent some of my time to investigate the bug. I also took additional time to document the issue. I have also pointed out what changes could be made to make it safer.
I have also clarified that I have no interest in fixing it myself, as I had planned to migrate away anyway (from pidgin / purple based clients; and by extension: telegram-purple). So I don't have any motivation to fix this plugin: I likely won't be using it. However, everyone who keeps using it should worry about these things.
This is off-topic. Let's stick to @ildar's issue, and nothing else.
Have run into the same issue. Traced it with gdb and found this thread.
Thanks for the hint that 1.4.1 is still working. I reverted for now to 1.4.1 for my setup.
In case JayFoxRox is right, this is fixed in 1.4.3 due to #522.