Skip to contentSkip to conversation

smb: smbdirect: don't WARN on an unexpected receive opcode

PATCH Applied Stefan Metzmacher 2 participants 2 messages Oct 9

Subsystems (3)
lore
Share & tools
lore

Stefan Metzmacher

author reviewer
#0 lore raw

PATCH 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.

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]()")
Cc Namjae Jeon <[email protected]>
Cc Paulo Alcantara <[email protected]>
Cc Tom Talpey <[email protected]>
Assisted-by Claude:claude-opus-5-5
---
 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
index e7e5eb75a5ae..85e37d11f43d 100644
@@ -234,7 +234,7 @@ static void smbdirect_accept_negotiate_recv_done(struct ib_cq *cq, struct ib_wc
 	struct 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
index 34a3e72c38fb..0d02f03063ac 100644
@@ -581,7 +581,7 @@ static void smbdirect_connect_negotiate_recv_done(struct ib_cq *cq, struct ib_wc
 	struct 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
index f48c857bda5a..e6c7b343fe87 100644
@@ -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
maintainer Applied
#1 lore raw
Quoted 24 lines · Stefan Metzmacher

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.

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]()")
Cc Namjae Jeon <[email protected]>
Cc Paulo Alcantara <[email protected]>
Cc Tom Talpey <[email protected]>
Assisted-by Claude:claude-opus-5-5

Applied it to #ksmbd-for-next.
Thanks!