ubeddulla opened a new pull request, #3572: URL: https://github.com/apache/brpc/pull/3572
### What problem does this PR solve? Issue Number: resolve Problem Summary: in `ParseMemcacheMessage` the 24-byte response header comes from `source->fetch(buf, sizeof(buf))`. when those bytes are contiguous in the front block, `fetch` hands back a pointer straight into the iobuf block rather than into the local `buf` (see `IOBuf::fetch` in iobuf.cpp). the function then does `source->pop_front(sizeof(*header))` followed by `source->cutn(&msg->meta, total_body_length)`, and on the sasl-auth path still reads `header->command` and `header->status` afterwards. once the header sits alone in its own front block-ref, `pop_front` drops the block's last reference and the block is freed/recycled, so those two reads are a use-after-free of bytes that came from the (untrusted) memcached/couchbase server. a peer can line this up by pipelining responses so a 24-byte header lands on a block boundary. the function already builds `local_header`, a byte-swapped host-order copy, precisely so values can be read after the pop; the header pointer just shouldn't be touched agai n. ### What is changed and the side effects? Changed: read `local_header.command` / `local_header.status` on the sasl-auth branch instead of dereferencing the now-dangling `header`. behaviour for valid responses is identical (the status check is still "non-zero means auth failure"). Side effects: - Performance effects: none. - Breaking backward compatibility: none. ### Check List: - compiles cleanly. - added a regression test `MemcacheParserTest.SaslAuthDoesNotReadHeaderAfterPop` in test/brpc_memcache_unittest.cpp. it puts the header in a heap block that is freed the instant its bytes are popped, so the stale read is a definite uaf: on the unpatched tree asan reports `heap-use-after-free READ` at memcache_binary_protocol.cpp:135 freed via `pop_front` at :133, and it passes after the fix. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
