{"action":"created","issue":{"url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c/issues/14","repository_url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c","labels_url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c/issues/14/comments","events_url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c/issues/14/events","html_url":"https://github.com/WhisperSystems/libsignal-protocol-c/issues/14","id":153561873,"number":14,"title":"Potential integer overflow in Axolotl","user":{"login":"Smattr","id":203893,"avatar_url":"https://avatars.githubusercontent.com/u/203893?v=3","gravatar_id":"","url":"https://api.github.com/users/Smattr","html_url":"https://github.com/Smattr","followers_url":"https://api.github.com/users/Smattr/followers","following_url":"https://api.github.com/users/Smattr/following{/other_user}","gists_url":"https://api.github.com/users/Smattr/gists{/gist_id}","starred_url":"https://api.github.com/users/Smattr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Smattr/subscriptions","organizations_url":"https://api.github.com/users/Smattr/orgs","repos_url":"https://api.github.com/users/Smattr/repos","events_url":"https://api.github.com/users/Smattr/events{/privacy}","received_events_url":"https://api.github.com/users/Smattr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-07T00:23:24Z","updated_at":"2016-06-06T16:11:35Z","closed_at":null,"body":"This issue refers to the Axolotl allocation functions in https://github.com/WhisperSystems/libsignal-protocol-c/blob/master/src/axolotl.c.\r\n\r\nIIUC `axolotl_buffer_alloc` checks for integer overflow before `malloc` ([axolotl.c:80-82](https://github.com/WhisperSystems/libsignal-protocol-c/blob/master/src/axolotl.c#L80-L82)):\r\n\r\n```c\r\nif(len > (SIZE_MAX - sizeof(struct axolotl_buffer)) / sizeof(uint8_t)) {\r\n    return 0;\r\n}\r\n```\r\n\r\nThen in `axolotl_buffer_append` we have a calculation of the currently allocated size that should never overflow ([axolotl.c:10](https://github.com/WhisperSystems/libsignal-protocol-c/blob/master/src/axolotl.c#L110)):\r\n\r\n```c\r\nsize_t previous_alloc = sizeof(struct axolotl_buffer) + (sizeof(uint8_t) * previous_size);\r\n```\r\n\r\nHowever, it seems to me the immediately following calculation of the length to pass to `realloc` *can* overflow ([axolotl.c:111](https://github.com/WhisperSystems/libsignal-protocol-c/blob/master/src/axolotl.c#L111)):\r\n\r\n```c\r\naxolotl_buffer *tmp_buffer = realloc(buffer, previous_alloc + (sizeof(uint8_t) * len));\r\n```\r\n\r\nThe effect of this would be that the `memcpy` that follows this does an out-of-bounds write.\r\n\r\nI haven't checked yet whether this issue is exploitable as I just wanted to double check I was understanding things correctly. However, it looks like the [call in protocol.c](https://github.com/WhisperSystems/libsignal-protocol-c/blob/177cc5b4b378d29232b731282661a70d98da6b7a/src/protocol.c#L500-L503) could trigger this with a long enough cipher text. Is there an external reason for why this execution flow is not possible?"},"comment":{"url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c/issues/comments/224007205","html_url":"https://github.com/WhisperSystems/libsignal-protocol-c/issues/14#issuecomment-224007205","issue_url":"https://api.github.com/repos/WhisperSystems/libsignal-protocol-c/issues/14","id":224007205,"user":{"login":"dkonigsberg","id":1144556,"avatar_url":"https://avatars.githubusercontent.com/u/1144556?v=3","gravatar_id":"","url":"https://api.github.com/users/dkonigsberg","html_url":"https://github.com/dkonigsberg","followers_url":"https://api.github.com/users/dkonigsberg/followers","following_url":"https://api.github.com/users/dkonigsberg/following{/other_user}","gists_url":"https://api.github.com/users/dkonigsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/dkonigsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkonigsberg/subscriptions","organizations_url":"https://api.github.com/users/dkonigsberg/orgs","repos_url":"https://api.github.com/users/dkonigsberg/repos","events_url":"https://api.github.com/users/dkonigsberg/events{/privacy}","received_events_url":"https://api.github.com/users/dkonigsberg/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T16:11:35Z","updated_at":"2016-06-06T16:11:35Z","body":"I want to apologize for not posting any updates about this issue in so long. It has been investigated, and a fix will be pushed as soon as some CLA issues are ironed out."}}
{"actor":{"display_login":"dkonigsberg"}}