Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miss a check on length in Babel #10487

Closed
whichbug opened this issue Feb 3, 2022 · 3 comments · Fixed by #10494
Closed

Miss a check on length in Babel #10487

whichbug opened this issue Feb 3, 2022 · 3 comments · Fixed by #10494

Comments

@whichbug
Copy link

whichbug commented Feb 3, 2022

The code below misses a check on the relationship between packetlen and bodylen before Line 298, which may lead to buffer overflows when accessing the memory at Line 300 and Line 309.

frr/babeld/message.c

Lines 289 to 309 in 3d1ff4b

babel_packet_examin(const unsigned char *packet, int packetlen)
{
unsigned i = 0, bodylen;
const unsigned char *message;
unsigned char type, len;
if(packetlen < 4 || packet[0] != 42 || packet[1] != 2)
return 1;
DO_NTOHS(bodylen, packet + 2);
while (i < bodylen){
message = packet + 4 + i;
type = message[0];
if(type == MESSAGE_PAD1) {
i++;
continue;
}
if(i + 1 > bodylen) {
debugf(BABEL_DEBUG_COMMON,"Received truncated message.");
return 1;
}
len = message[1];

To fix, we may put the code below before the while loop:

if (packetlen < bodylen + 4) {
    debugf(BABEL_DEBUG_COMMON,"Received truncated message."); 
    return 1; 
}

The output of the address sanitizer:

==271648==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000000114 at pc 0x00000059301a bp 0x7fff3f7301f0 sp 0x7fff3f7301e8
READ of size 1 at 0x603000000114 thread T0
    #0 0x593019 in babel_packet_examin /home/parallels/myfrr/babeld/message.c:300:16
    #1 0x593019 in parse_packet /home/parallels/myfrr/babeld/message.c:354:9
whichbug pushed a commit to whichbug/frr that referenced this issue Feb 3, 2022
@qlyoung
Copy link
Member

qlyoung commented Feb 3, 2022

Awesome! Since you already have a fix, would you be willing to submit the patch as a PR? That would be super helpful.

whichbug pushed a commit to whichbug/frr that referenced this issue Feb 3, 2022
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.

Signed-off-by: whichbug <whichbug@github.com>
@whichbug
Copy link
Author

whichbug commented Feb 3, 2022

Awesome! Since you already have a fix, would you be willing to submit the patch as a PR? That would be super helpful.

Thanks for your reply. I have created the pull request.

whichbug pushed a commit to whichbug/frr that referenced this issue Feb 4, 2022
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.

Signed-off-by: whichbug <whichbug@github.com>
whichbug pushed a commit to whichbug/frr that referenced this issue Feb 4, 2022
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.

Signed-off-by: whichbug <whichbug@github.com>
plsaranya pushed a commit to plsaranya/frr that referenced this issue Feb 28, 2022
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.

Signed-off-by: whichbug <whichbug@github.com>
@qlyoung
Copy link
Member

qlyoung commented Mar 28, 2022

This has been assigned CVE-2022-26127 with a severity score of 7.8.

No assessment of exploitability has been made.

Please see my comment here

patrasar pushed a commit to patrasar/frr that referenced this issue Apr 28, 2022
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.

Signed-off-by: whichbug <whichbug@github.com>
gpnaveen pushed a commit to gpnaveen/frr that referenced this issue Jun 7, 2022
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.

Signed-off-by: whichbug <whichbug@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants