From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795897499; b=TmYtC5aLODm9RhVzIVhnJcGQGqBHw3yRIMcaLtEgQPDhcRzx5soYgGhlvQVmYaKaiPj+ eyazARw0IR0t42mEyHSNA4NE3a9fJxxtDHW/1IiouYiB6S7fv8ZwaZZr99PI7ugxZEPIe Cn+ssSodC8G4RVfZy8Gu4NY5KQXYgYS1EnvSmCNJdOTF/n7cEnZJOmc0+dPt/DaLgnWgR OTVKEvy2R0qY6GsjWyLHRYJukdQIx6qZrNL4KZ3YIu/p3PXMm+KvSsGsSUSLlOuYsc3So DwAtBxpupa3+F5CJ+Xa9QYDbUBzW2ig4nYRI9li9TIa7FlsEaWMT1Hl4kR3hOIFQbBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795897499; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=ZDOMv7Iw6ayBhrKfYWvXMf0FuUN4Dnzjt6kzJxDfbJg=; b=ioPTnwwdvkE5olz0A0892q24Pna7rLmqQD6Jf+0jkGgXveAZa9p0sGexHi+CuvJUsIjG 5ej35WWp23x2vNggNRNfUbzFOHWzbgSNyVVNGa2sdX2l7rDuMW9onNSbNcHgPa43aWlZc q/0RTtvAuMBGx8CD0gnnfuHhelUrMBBDLB/ZISJ2PZ3p3xWIwqAMf963LegzIgj3k3v7h QIUEOFrrGOH/OrQQl5eKFIoGxI7+FXlXuB1WYPBymYUwk/YiN31YCKtuR6nCKC3Cp7U/Q 7Eg6/aXUFBfO6RjkW6fldagJ7CByB6f3O6drVtrYk0XYQ3y6hHQvgZJ7FDUfqEQ9AmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=stellman-greene.com; spf=none smtp.mailfrom=stellman-greene.com; dkim=pass header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=DrR2+4YK; arc=none smtp.remote-ip=209.85.160.182 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C897D606A31C for ; Sat, 28 Nov 2026 20:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C897D606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=DrR2+4YK Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-5363316fa0cso96026111cf.3 for ; Sat, 28 Nov 2026 12:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stellman-greene-com.20260707.gappssmtp.com; s=20260707; t=1795897497; x=1796502297; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZDOMv7Iw6ayBhrKfYWvXMf0FuUN4Dnzjt6kzJxDfbJg=; b=DrR2+4YKdKSAZtAEFm1Ttv7ipWyEm5P9ESp0eh/A850oHeENpvOUkVgS5PYbC2vnEM 8MZinCBHYcyW9vCwViFlic1eFrm5yx7RqS+NigEt8a1iFPdKJjf7RaYxGrki9Nfz4FL8 hV69uWMMUbXgx0WWGkvT9BlFzHGm37PwGsnBZXpcQYMnifZL6RSmdYt3dXvAi5FAHj2I y3Z2YexdiG/NQgykhoorLazJbkQecgGgpakMN1C+IXW9u7YD9Htum9/00o7e4RKhYOpJ vIQY9WEJlh+suQUift7YmWZTJbIhibWyIJPIc6eOo8um3tPzD1cMAIIHiTEZVmvyJbGh j8bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795897497; x=1796502297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZDOMv7Iw6ayBhrKfYWvXMf0FuUN4Dnzjt6kzJxDfbJg=; b=rSjUGSMuKNgyp9Jol3EZcKkL6eKhDFtxWOmF76IUegCkOLUqONz+maHOWrbeZtq6hC hDQdlcG4N9kOe1/hLzD4mmoQHwwX/iUzWWx21O5QXV9rsggqQxzhnHY2MuWXrHD8qdFr 0I8YN95+aC/q5pNsF3QgoA3hMNViUH8NTsWZnHV3efUdR8FQqKkEOzq4JEh8bobSrQNV Pz4Nv94zN2ZWHhRi4K76LsgpnPyxJCw+xoVRWquJLE2SF+QJa0PtGtjhYA918N+GPrvS POvrW8lmJ1mvbF+t8NbXzfJzEUEN+/2Vyu2iPjDhwrMzYlEASqHfstslvLKDZ1ikzr0K QrvQ== X-Forwarded-Encrypted: i=1; AL+hErEPWTxY1GPugcR7GKpugCJhEbCDbz+2812a5wBYANOkw2RxIvlnMDYT8k18e01p5xsqqx7L2OfrGcoi@vger.kernel.org X-Gm-Message-State: APuU4Z9rFvirDJuKnf0HQCjHU/T4Hc+mqDhIVLqVyHCu6fvBtddMTgD1 wDhhMT6w2hSHm2hkI0Sl+6eX5uv8h1IBPfhQuuAjkMsAwyWP7jSeA/BxudALWgLU6EA= X-Gm-Gg: AZFdTZey/CFLYJnNGk6gcxRor35MnI16GPFJ/O5LitJZ2CnACssK101jR5VVtV/QI86 SlVNagl6MgE8nEsEEY8FX8Qcb8aem3Nbo83xOoiolg18N2k+kxpMtY/Tj5wp6B6n+e3pZfAW0X7 qtrApD1mRg9CGP8d9UJ65a+EPDfpxKhwXbBnbvNrvk0gdf8J9BXAcHeVRlL0CyDkeuRmGBc8gwe XA0YIppBWPw7RPrijTEprKeLh11rgaw3p5dWVA2SZMWYiTCoQqyAq3a/s9AzYjZJttv6IAOGkZH /Hhl756leM13VUME9csj9CSqVL2c/YPTtaEHbikju2mpXy4d7+Ypdhx6LtT4ooyHjWmc0UTzZNn wwul0PyvnE5NxdEGZ1gWia2VO5UQ6M7JDK0nK12tLhsscrnyj1Ehe5XYnc/btVDCJJ/mgeMKkcx yZAbx7s3JvcjH2BvIIbuJ1xctu/xcTL5QcFlGvAafION0ciC93+z+f65rcMsTbPtnx0PeNL/fXH dkAL78bvnrueg1+jicGXws7/RQ7RIDPuKCL+ahFwc3+f0jaXzQeY+5cVQuUzLrFrxouJsdU1jRo dv/rMfesGDRJzg31VqYc5KZ1XRVndm0t//efEy4jsB8JiAwF2ZeUTaVlz6TpgYEm5MP/2PM/ZHx U6qskEkDi1EguEHSkqOcm5R4= X-Received: by 2002:ac8:5e0e:0:b0:55d:32a4:dbff with SMTP id d75a77b69052e-55d76a1fd20mr518924601cf.36.1795897497285; Sat, 28 Nov 2026 12:24:57 -0800 (PST) Received: from Mac.mynetworksettings.com ([2600:4041:5c28:200:a4e3:fb15:aef5:60c7]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55d78880604sm241560061cf.24.2026.11.28.12.24.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 28 Nov 2026 12:24:56 -0800 (PST) From: Andrew Stellman To: Bernard Metzler Cc: Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 rdma-rc] RDMA/siw: Fix NULL dereference when disconnect races the RTR callback Date: Sat, 28 Nov 2026 15:24:52 -0500 Message-ID: <20261128202452.45307-1-bugs@stellman-greene.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261128140843.59029-1-bugs@stellman-greene.com> References: <20261128140843.59029-1-bugs@stellman-greene.com> X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrew Stellman siw_rtr_data_ready() releases sk_callback_lock and then calls siw_qp_socket_assoc(), which reads cep->sock->sk before it takes the write lock. A concurrent disconnect can disassociate the socket and clear cep->sock in that gap. In QEMU (arm64) on mainline as of 2026-11-28 with KASAN, a test server accepted an MPA v2 connection that waits for the peer's RTR frame. The server calls rdma_disconnect() when it gets the ESTABLISHED event. The peer sent an incomplete RTR header. With a test-only one second delay added after the callback unlock, this oopsed: Unable to handle kernel paging request at virtual address dfff800000000003 KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f] Internal error: Oops: 0000000096000005 [#1] SMP pc : siw_rtr_data_ready+0x218/0x2c0 lr : siw_rtr_data_ready+0x1ec/0x2c0 Call trace: siw_rtr_data_ready+0x218/0x2c0 (P) tcp_data_ready+0xd0/0x3f8 tcp_data_queue+0x1898/0x506c tcp_rcv_established+0x94c/0x2e80 Take the callback's socket write lock and check that the socket still belongs to the same CEP and QP before installing the QP callbacks. If it doesn't, do nothing. That check relies on the socket being disassociated before the QP is released. siw_cm_work_handler() closes and puts the QP before it calls siw_socket_disassoc(), so move siw_socket_disassoc() first, as siw_qp_cm_drop() already does. The worker now restores the socket's original callbacks before closing the QP. The ordering problem was found by code review; I have not reproduced a fault on that path. With the patch and the same one-second test-only delay, the incomplete RTR header and rdma_disconnect() test ran without a KASAN report. Without the delay, a valid RTR frame connected and disconnected the same way as on mainline. The issue was found by Claude Opus 5.5 running Quality Playbook, an LLM-driven code review tool: https://github.com/andrewstellman/quality-playbook The fix and this changelog were drafted with OpenAI GPT-6 (Codex) and Claude Opus 5.5, and both were reviewed by me. Fixes: 6c52fdc244b5 ("rdma/siw: connection management") Signed-off-by: Andrew Stellman --- v2: Disassociate the socket before the release worker closes the QP, as asked in v1 and following Sashiko's review of it: https://lore.kernel.org/linux-rdma/20261128140843.59029-1-bugs@stellman-greene.com/ The RTR callback hunk is unchanged. A reproducer is available on request. drivers/infiniband/sw/siw/siw_cm.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c index ed49818793ddeb..9fa25c287dc1d8 100644 --- a/drivers/infiniband/sw/siw/siw_cm.c +++ b/drivers/infiniband/sw/siw/siw_cm.c @@ -181,8 +181,15 @@ static void siw_rtr_data_ready(struct sock *sk) siw_cm_upcall(cep, IW_CM_EVENT_ESTABLISHED, 0); out: read_unlock(&sk->sk_callback_lock); - if (qp) - siw_qp_socket_assoc(cep, qp); + if (qp) { + write_lock_bh(&sk->sk_callback_lock); + if (sk_to_cep(sk) == cep && cep->qp == qp) { + qp->attrs.sk = cep->sock; + sk->sk_data_ready = siw_qp_llp_data_ready; + sk->sk_write_space = siw_qp_llp_write_space; + } + write_unlock_bh(&sk->sk_callback_lock); + } } static void siw_sk_assign_rtr_upcalls(struct siw_cep *cep) @@ -1214,6 +1221,9 @@ static void siw_cm_work_handler(struct work_struct *w) cep->state = SIW_EPSTATE_CLOSED; + if (s) + siw_socket_disassoc(s); + if (cep->qp) { struct siw_qp *qp = cep->qp; /* @@ -1230,10 +1240,8 @@ static void siw_cm_work_handler(struct work_struct *w) cep->qp = NULL; siw_qp_put(qp); } - if (s) { - siw_socket_disassoc(s); + if (s) sock_release(s); - } if (cep->cm_id) { siw_free_cm_id(cep); siw_cep_put(cep); -- 2.53.0