smb: smbdirect: don't WARN on an unexpected receive opcode
Subsystems (3)
Stefan Metzmacher
reviewerPATCH 1/1 smb: smbdirect: don't WARN on an unexpected receive opcode
The receive completion handlers smbdirect_connection_recv_io_done(), smbdirect_accept_negotiate_recv_done() and smbdirect_connect_negotiate_recv_done() verify that the completion is a regular receive with WARN_ON_ONCE(wc->opcode != IB_WC_RECV).
But wc->opcode is controlled by the remote peer: a posted receive work request is consumed not only by an incoming SEND, but also by an RDMA Write with Immediate, which completes as IB_WC_RECV_RDMA_WITH_IMM. An unauthenticated peer can transmit such a message, even before the negotiate completes, so it reaches the accept/connect negotiate handlers as well. With panic_on_warn set this is a remote denial of service, and otherwise it still taints the kernel and spams the log for something a peer can trigger at will.
The opcode check itself was inherited from the original client and server recv_done() handlers (fs/smb/client/smbdirect.c and fs/smb/server/transport_rdma.c), where an unexpected opcode was simply logged and the connection was torn down. Only the WARN_ON_ONCE() was added on top during the socketization rework. Drop the WARN_ON_ONCE() and keep the existing graceful error path, which logs the unexpected opcode (unless the status is IB_WC_WR_FLUSH_ERR) and tears the connection down.
--- fs/smb/smbdirect/accept.c | 2 +- fs/smb/smbdirect/connect.c | 2 +- fs/smb/smbdirect/connection.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/smb/smbdirect/accept.c +1 -1
@@ -234,7 +234,7 @@ static void smbdirect_accept_negotiate_recv_done(struct ib_cq *cq, struct ib_wcstruct smbdirect_socket *sc = recv_io->socket;unsigned long flags; -if (unlikely (wc->status !=IB_WC_SUCCESS ||WARN_ON_ONCE (wc->opcode !=IB_WC_RECV ))) { +if (unlikely (wc->status !=IB_WC_SUCCESS || wc->opcode !=IB_WC_RECV )) {if (wc->status !=IB_WC_WR_FLUSH_ERR ) smbdirect_log_rdma_recv(sc, SMBDIRECT_LOG_ERR, "wc->status=%s (%d) wc->opcode=%d\n",
fs/smb/smbdirect/connect.c +1 -1
@@ -581,7 +581,7 @@ static void smbdirect_connect_negotiate_recv_done(struct ib_cq *cq, struct ib_wcstruct smbdirect_socket *sc = recv_io->socket;unsigned long flags; -if (unlikely (wc->status !=IB_WC_SUCCESS ||WARN_ON_ONCE (wc->opcode !=IB_WC_RECV ))) { +if (unlikely (wc->status !=IB_WC_SUCCESS || wc->opcode !=IB_WC_RECV )) {if (wc->status !=IB_WC_WR_FLUSH_ERR ) smbdirect_log_rdma_recv(sc, SMBDIRECT_LOG_ERR, "wc->status=%s (%d) wc->opcode=%d\n",
fs/smb/smbdirect/connection.c +1 -1
@@ -1529,7 +1529,7 @@ void smbdirect_connection_recv_io_done(struct ib_cq *cq, struct ib_wc *wc)u32 data_length;u32 remaining_data_length; -if (unlikely (wc->status !=IB_WC_SUCCESS ||WARN_ON_ONCE (wc->opcode !=IB_WC_RECV ))) { +if (unlikely (wc->status !=IB_WC_SUCCESS || wc->opcode !=IB_WC_RECV )) {if (wc->status !=IB_WC_WR_FLUSH_ERR ) smbdirect_log_rdma_recv(sc, SMBDIRECT_LOG_ERR, "wc->status=%s (%d) wc->opcode=%d\n",
Signature · 1 line
2.43.0
Quoted 24 lines · Stefan Metzmacher
The receive completion handlers
smbdirect_connection_recv_io_done(),smbdirect_accept_negotiate_recv_done()andsmbdirect_connect_negotiate_recv_done()verify that the completion is a regular receive withWARN_ON_ONCE(wc->opcode != IB_WC_RECV).But
wc->opcodeis controlled by the remote peer: a posted receive work request is consumed not only by an incoming SEND, but also by an RDMA Write with Immediate, which completes asIB_WC_RECV_RDMA_WITH_IMM. An unauthenticated peer can transmit such a message, even before the negotiate completes, so it reaches the accept/connect negotiate handlers as well. Withpanic_on_warnset this is a remote denial of service, and otherwise it still taints the kernel and spams the log for something a peer can trigger at will.The opcode check itself was inherited from the original client and server
recv_done()handlers (fs/smb/client/smbdirect.candfs/smb/server/transport_rdma.c), where an unexpected opcode was simply logged and the connection was torn down. Only theWARN_ON_ONCE()was added on top during the socketization rework. Drop theWARN_ON_ONCE()and keep the existing graceful error path, which logs the unexpected opcode (unless the status isIB_WC_WR_FLUSH_ERR) and tears the connection down.
Quoted 12 lines
Fixes ea4151222a93 ("smb: smbdirect: introduce smbdirect_connection_recv_io_done()")Fixes eb3ed1e9048c ("smb: smbdirect: introduce smbdirect_accept_connect_request()")Fixes d1f187656797 ("smb: smbdirect: introduce smbdirect_connect[_sync]()")Reported-by Sashiko <[email protected]>Cc Namjae Jeon <[email protected]>Cc Paulo Alcantara <[email protected]>Cc Tom Talpey <[email protected]>Assisted-by Claude:claude-opus-5-5Signed-off-by Stefan Metzmacher <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!