-
Notifications
You must be signed in to change notification settings - Fork 29
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
Memory corruption security flaws in version 4.0 #5
Comments
Invalid free (CWE-763) in int forth_run(forth_t *o) libforth/libforth.c, line 2750 when attempting to execute 'w = (forth_cell_t)realloc((char*)(*S--), f);':File for replication: forth_run_line_2750.fthSource Code:Line 2750 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2730 when attempting to execute 'f = memcmp((char*)(S--), (char)w, f);':File for replication: forth_run_line_2730.fthSource Code:Line 2730 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2362 when attempting to execute 'error("'%s' is not a word (line %zu)", o->s, o->line);':File for replication: forth_run_line_2362.fthSource Code:Line 2362 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2665 when attempting to execute '++S = fwrite(((char)m)+offset, 1, count, file);':File for replication: forth_run_line_2665.fthSource Code:Line 2665 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2716 when attempting to execute 'memmove((char*)(S--), (char)w, f);':File for replication: forth_run_line_2716.fthSource Code:Line 2716 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2721 when attempting to execute 'f = (forth_cell_t)memchr((char*)(*S--), w, f);':File for replication: forth_run_line_2721.fthSource Code:Line 2721 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds write (CWE-787) in int forth_run(forth_t *o) libforth/libforth.c, line 2725 when attempting to execute 'memset((char*)(*S--), w, f);':File for replication: forth_run_line_2725.fthSource Code:Line 2725 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2623 when attempting to execute 'f = fflush((FILE*)f) ? ferrno() : 0;':File for replication: forth_run_line_2623.fthSource Code:Line 2623 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in int forth_run(forth_t *o) at libforth/libforth.c, line 2666 when attempting to execute 'f = ferror(file);':File for replication: forth_run_line_2666.fthSource Code:Line 2666 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Null pointer dereference (CWE-476) in int forth_run(forth_t *o) at libforth/libforth.c, line 2615 when attempting to execute 'f = fclose((FILE*)f) ? ferrno() : 0;':File for replicaiton: forth_run_line_2615.fthSource Code:Line 2615 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
|
Nice work! I'm not sure when I'll get around to fixing these though as I have a baby and little time, but the detailed report is appreciated. |
Hello, |
She is, and crawling! I haven't much time to give to this project unfortunately, I will get around to it eventually. |
Hello, it's me again. |
Hi everyone, Sorry for the delay, but here are some example fixes in the meantime to mitigate each of the discovered vulnerabilities: 1. Out of Bounds Read in
|
I'll try to get around to fixing some of these issues, but bear in mind that Forth is a memory unsafe language. A lot of the problems are caused by |
No worries, and I appreciate your perspective. I understand that Forth, by its nature, allows direct memory manipulation, which can indeed introduce risks if not used carefully. My intention isn't to complain but to help identify potential issues, especially since applications utilizing libforth might process input from external and possibly untrusted sources. Ensuring robust input handling and memory operations can greatly benefit users of the library who might not be aware of these intricacies. Thanks for considering these points, and I look forward to seeing the library evolve. |
Hi!
While I was running my fuzz tests in the background I discovered multiple memory corruption security flaws in libforth Version 4.0 at various locations. I have attached a zip archive named crash.zip for replication. The easiest way to reproduce is to compile the project and execute forth against the crash files that call specific library functions:
Zip archive with reproduction files:
crash.zip
After triaging all of the crashes, I can verify that there are 17 separate and unique issues at the following locations:
Out of bounds read (CWE-125) in static int match(forth_cell_t *m, forth_cell_t pwd, const char *s) at libforth.c, line 1306 when attempting to execute 'forth_cell_t len = WORD_LENGTH(m[pwd + 1]);':
File for replication: match_line_1306.fth
Source Code:
libforth/libforth.c
Line 1306 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Invalid free (CWE-763) in int forth_run(forth_t *o) at libforth.c, line 2745 when attempting to execute 'free((char*)f);':
File for replication: forth_run_line_2745.fth
Source Code:
libforth/libforth.c
Line 2745 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in static void check_is_asciiz(jmp_buf *on_error, char *s, forth_cell_t end) libforth/libforth.c, line 1436 when attempting to execute 'if (*(s + end) != '\0')':
File for replication: check_is_asciiz_line_1436.fth
Source Code:
libforth/libforth.c
Line 1436 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Stack-based buffer overflow (CWE-121) in static int print_cell(forth_t *o, FILE *out, forth_cell_t u) at libforth.c, line 1367 when attempting to execute 's[i++] = conv[u % base];':
File for replication: print_cell_line_1367.fth
Source Code:
libforth/libforth.c
Line 1367 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds write (CWE-787) in static forth_cell_t compile(forth_t *o, forth_cell_t code, const char *str, forth_cell_t compiling, forth_cell_t hide) at libforth.c, line 1241 when attempting to execute 'strcpy((char *)(o->m + head), str);':
File for replication: compile_line_1241.fth
Source Code:
libforth/libforth.c
Line 1241 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in static int forth_get_char(forth_t *o) at libforth.c, line 1091 when attempting to execute 'r = fgetc((FILE*)(o->m[FIN]));':
File for replication: forth_get_char_line_1091.fth
Source Code:
libforth/libforth.c
Line 1091 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
Out of bounds read (CWE-125) in static void print_stack(forth_t *o, FILE *out, forth_cell_t *S, forth_cell_t f) at libforth.c, line 1481 when attempting to execute 'print_cell(o, out, *(o->S + i + 1));':
File for replication: print_stack_line_1481.fth
Source Code:
libforth/libforth.c
Line 1481 in b851c6a
GDB Backtrace:
Address Sanitizer Output:
The text was updated successfully, but these errors were encountered: