From 6815ccdf68d995acd9a93842753e48448696d2da Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 24 Sep 2019 21:43:18 -0700 Subject: [PATCH] mitm: fix long-standing C descriptor issue. --- include/stratosphere/mitm/mitm_session.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/stratosphere/mitm/mitm_session.hpp b/include/stratosphere/mitm/mitm_session.hpp index 71c45cbb..13110ce8 100644 --- a/include/stratosphere/mitm/mitm_session.hpp +++ b/include/stratosphere/mitm/mitm_session.hpp @@ -80,6 +80,23 @@ class MitmSession final : public ServiceSession { } Result ForwardRequest(IpcResponseContext *ctx) { + /* Mitm forward specific preprocessing. */ + if (ctx->request.NumStaticsOut) { + u32 *cmdbuf = (u32 *)armGetTls(); + /* Overwrite the number of C descriptors to only use a single buffer. */ + cmdbuf[1] = (cmdbuf[1] & (~u32(0xF << 10))) | (0x2 << 10); + + IpcStaticRecvDescriptor *c_desc = (IpcStaticRecvDescriptor *)(reinterpret_cast(ctx->request.RawWithoutPadding) + ctx->request.RawSize); + /* Don't write out of bounds, though this should never happen. */ + if (reinterpret_cast(c_desc) + sizeof(*c_desc) <= reinterpret_cast(cmdbuf) + 0x100) { + uintptr_t ptr = reinterpret_cast(this->pointer_buffer.data()); + c_desc->Addr = ptr; + c_desc->Packed = (ptr >> 32) | (this->pointer_buffer.size() << 16); + } else { + std::abort(); + } + } + /* Dispatch forwards. */ R_TRY(serviceIpcDispatch(this->forward_service.get()));