From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796117575; b=DVrEINEqyGlq7KZQWsTLa37EOnOYByvNIJPlop3ud68suatbtVZDT15PSaXa7/jx+LX0 K1oF20vtqJ155Vur25qahEBo65U3FXryhWWCkQkEmI1ZU8Cg0cMCAMvzmxm/vZgBkbieF e8KT9icVlgbYEaKhUAU7rOu3qXlVjkHoLdewXO6zLiBphJ7Li/3Mso47eqJt653puR3W4 YOgeMuLnUi5h8TQWe1Bly6kIsrtdh6qHe4enjz973oeiXcqSCKZrcU/JSQm49BxsON+MH GjSPRRjw647sD6dxvIvHRcQnpLWOLNyQjGmuLKJEAhZQh0t4uSwJoiqKK+yJsf4BR9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796117575; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-TM-AS-GCONF: X-Proofpoint-Reinject:X-Proofpoint-Spam-Details-Enc: X-Authority-Analysis:X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Info:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=X61AGZ6WdQ3gR8SEdDooBk5rn2TKrsj3IDTFwIR1I60=; b=yonAf4U5/MESFB8f64KUio3aEJdQ0MLPhnb/IyeuWGsBccavqHH6Ne77Ao0eAD+agBm5 Ls9ztR+xnxUifMFHiCDO1Zpe9d7GfKd42YFmvNAWJozep3/ChYteTcwDWLBv2A9fSMwby jdfS+XfifZdS6Lr810CjTRjhHCGTJI0PQiR1fxg4cY/BcvCVWPyZRBdr5VPaMLgjZCfDe 6EXp0wArv+5enG2UdUuIZ89/+5NcpsJPkba9B5syzQ24H6MICTMU0uhWoWPCF8Kol3t+A 53jk9CQ5/ckiQ1BKxK9xmbE3g1K4z2gkfWuv47kJ7FlAtHMipHiXoDKMMitw//LKYbg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=PbhI153Q; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65928606A320; Tue, 1 Dec 2026 09:32:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65928606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=PbhI153Q Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B12Z2l23573150; Tue, 1 Dec 2026 09:32:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=X61AGZ 6WdQ3gR8SEdDooBk5rn2TKrsj3IDTFwIR1I60=; b=PbhI153Qx6uY/HFikjnNXj VmVzrZOZH6+3mHltevyMavedOO2r9R0trloAR/fR6RVsXPZCzp/PQYcTPg2OTZhG /LsSrY6Yt2Mb0QAmpmKhrhqlR6CrpvlaXbyh5l3UyrubkFoDdXUNhvZ3JJ8Yy3vl HFovO20huxrIYpMsONPLecf0FQFeJjyffPso8FYFOz8iUJCTrM2R8DNwDsLJTK/+ I1xqDNUZ9NcWX7hg5VnAhkc4EYGM1cBnlBW7vNI0Ff9yiWXT7WzngUwNDryXsduX 4g87yRZ8bTK5Qz+1S34oPfYijw4R9ua5vqWVGXK/FsiIcpaQWN349jazx758Z/7A == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7nchkh3f-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 09:32:33 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B17oaYL939050; Tue, 1 Dec 2026 09:32:32 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j8byy0b65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 09:32:32 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B19WR3P51053012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 09:32:27 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46EB72004B; Tue, 1 Dec 2026 09:32:27 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D7F1D20043; Tue, 1 Dec 2026 09:32:23 +0000 (GMT) Received: from [9.123.13.84] (unknown [9.123.13.84]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Dec 2026 09:32:23 +0000 (GMT) Message-ID: Date: Tue, 1 Dec 2026 15:02:23 +0530 X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v2 6/6] net/smc: update the urgent state under the socket spinlock To: hexlabsecurity@proton.me, Mahanta Jambigi , "D. Wythe" , Eric Dumazet , "David S. Miller" , Paolo Abeni , Jakub Kicinski , Dust Li Cc: Stefan Raspl , Simon Horman , Guangguan Wang , Wen Gu , linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Lu , Ursula Braun , Hidayath Khan , Wenjia Zhang References: <20261128-b4-disp-360e65c5-v2-0-d9c05004d430@proton.me> <20261128-b4-disp-360e65c5-v2-6-d9c05004d430@proton.me> Content-Language: en-US From: Sidraya Jayagond In-Reply-To: <20261128-b4-disp-360e65c5-v2-6-d9c05004d430@proton.me> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAzNiBTYWx0ZWRfX7cA80leFhro7 XWE7Mdh8ENFM3k0jKo3LZG7aTMbJnFHcU8mkOUavm7Fd1RkQIQD+aMGolXhkqCqWBIRxDp/K8Sh nP07lW/2e/dMcclwT5P1V6uJeZoh0+0nRLvxfw9fYCJWVkOIrzGnnOq5G7NgvhJKtYEan7Ts2G+ 2ZOe6ctXPHMjzxmP2GtlM00+ua6Tdo8NHBk4jPPsPLMPrdl7/0VMhvWsz5eUN28l9G6zOmx12KU 6YekZsHllcGds4MGIVEtb4iYQtvTUSxR0/5H3yNr34pWztF/IuyUFqXCxWXgOd55YsUNyNqheKC D6ijuUOf2TSVdz8UQ1HTqeRUFkn7Z67xm8civ5EAihQAo4vzjgo72McAix1qXoyymxc5VXGpv+I CoV5jMf5RfAR4Cd6BX+F9W9woljyRQ7pvjDbhtNlKe9W1rFcNmt+yq6G/zeS8y/KxwyESPT9zMK xgdxOr/jdmjfAKkLNhQ== X-Authority-Analysis: v=2.4 cv=Tt5zFzXh c=1 sm=1 tr=0 ts=6b0e9432 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=mzhWIDl2xS_pjuvghnAA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: _T-ldI7-NlxpHc6nZVe_qCQRnf0MxdML X-Proofpoint-GUID: aPXAH3mqryJj8r4yGQqrqh-eidou0lB9 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAzNiBTYWx0ZWRfX8DWPOPZL4tSC A0g6JPfWWzqGIQLSjLEsR9jAogWK07nXAw2Q+FVUo0pNOWaO39fAAdjCDl9vrWLFP9lwGequ7ex x0PesYRYcAbLou6Hb7LiXr1L9OnxdJ8= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_01,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 clxscore=1015 adultscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010036 On 28/11/26 7:53 pm, Bryam Vargas via B4 Relay wrote: > From: Bryam Vargas > > smc_cdc_msg_recv_action() sets a new urgent mark, byte and state under > the socket spinlock, even while a reader owns the socket, and the > reader tests and changes urg_state under the socket lock only. In > smc_rx_recv_urg() a second urgent byte that arrives after the state was > set to SMC_URG_READ is returned in place of the first, and the next > recv(MSG_OOB) returns it again. In smc_rx_update_consumer() a mark set > after the test is overwritten with SMC_URG_READ: its byte is neither > returned nor skipped, and the sender, which waits for its urgent data > to be consumed, stalls. > > Take the socket spinlock around both test-and-set sequences. > smc_rx_update_consumer() takes it only after a test without the lock > finds a mark or a pending skip, so a read with no urgent data is > unchanged. The lines of smc_rx_recv_urg() after its SMC_URG_VALID block > could only be reached through this race; drop them. > > Fixes: de8474eb9d50 ("net/smc: urgent data support") > Reported-by: Sashiko > Closes: https://lore.kernel.org/all/sashiko-outbox-215220@kernel.org/ > Cc: stable@vger.kernel.org > Signed-off-by: Bryam Vargas > --- > net/smc/smc_rx.c | 102 +++++++++++++++++++++++++++++++++---------------------- > 1 file changed, 62 insertions(+), 40 deletions(-) > > diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c > index 564b976426ca..2680b91e882b 100644 > --- a/net/smc/smc_rx.c > +++ b/net/smc/smc_rx.c > @@ -67,26 +67,38 @@ static int smc_rx_update_consumer(struct smc_sock *smc, > > smc_curs_add(conn->rmb_desc->len, &cons, len); > > - /* did we process urgent data? */ > + /* did we process urgent data? smc_cdc_msg_recv_action() sets a new > + * mark under the socket spinlock, even while we own the socket: > + * test again under it. A mark set after the first test is left to > + * the next call, like one set after the unlock. > + */ > if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) { > - diff = smc_curs_sdiff(conn->rmb_desc->len, &cons, > - &conn->urg_curs); > - if (sock_flag(sk, SOCK_URGINLINE)) { > - if (diff == 0) { > - force = true; > - rc = 1; > - conn->urg_state = SMC_URG_READ; > + local_bh_disable(); > + bh_lock_sock(sk); > + if (conn->urg_state == SMC_URG_VALID || > + conn->urg_rx_skip_pend) { > + diff = smc_curs_sdiff(conn->rmb_desc->len, &cons, > + &conn->urg_curs); > + if (sock_flag(sk, SOCK_URGINLINE)) { > + if (diff == 0) { > + force = true; > + rc = 1; > + conn->urg_state = SMC_URG_READ; > + } > + } else { > + if (diff == 1) { > + /* skip urgent byte */ > + force = true; > + smc_curs_add(conn->rmb_desc->len, > + &cons, 1); > + conn->urg_rx_skip_pend = false; > + } else if (diff < -1) > + /* we read past urgent byte */ > + conn->urg_state = SMC_URG_READ; > } > - } else { > - if (diff == 1) { > - /* skip urgent byte */ > - force = true; > - smc_curs_add(conn->rmb_desc->len, &cons, 1); > - conn->urg_rx_skip_pend = false; > - } else if (diff < -1) > - /* we read past urgent byte */ > - conn->urg_state = SMC_URG_READ; > } > + bh_unlock_sock(sk); > + local_bh_enable(); > } > > smc_curs_copy(&conn->local_tx_ctrl.cons, &cons, conn); > @@ -314,42 +326,52 @@ static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len, > struct smc_connection *conn = &smc->conn; > union smc_host_cursor cons; > struct sock *sk = &smc->sk; > + bool valid; > + char byte; > int rc = 0; > > - if (sock_flag(sk, SOCK_URGINLINE) || > - !(conn->urg_state == SMC_URG_VALID) || > - conn->urg_state == SMC_URG_READ) > + if (sock_flag(sk, SOCK_URGINLINE)) > return -EINVAL; > > - SMC_STAT_INC(smc, urg_data_cnt); > - if (conn->urg_state == SMC_URG_VALID) { > - if (!(flags & MSG_PEEK)) > - smc->conn.urg_state = SMC_URG_READ; > - msg->msg_flags |= MSG_OOB; > + /* smc_cdc_msg_recv_action() sets a new mark and byte under the > + * socket spinlock, even while we own the socket: take the byte > + * together with the state it belongs to. > + */ > + local_bh_disable(); > + bh_lock_sock(sk); > + valid = conn->urg_state == SMC_URG_VALID; > + if (valid) { > + byte = conn->urg_rx_byte; > if (len > 0) { > - if (!(flags & MSG_TRUNC)) > - rc = memcpy_to_msg(msg, &conn->urg_rx_byte, 1); > - len = 1; > smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn); > if (smc_curs_sdiff(conn->rmb_desc->len, &cons, > &conn->urg_curs) > 1) > conn->urg_rx_skip_pend = true; > - /* Urgent Byte was already accounted for, but trigger > - * skipping the urgent byte in non-inline case > - */ > - if (!(flags & MSG_PEEK)) > - smc_rx_update_consumer(smc, cons, 0); > - } else { > - msg->msg_flags |= MSG_TRUNC; > } > - > - return rc ? -EFAULT : len; > + if (!(flags & MSG_PEEK)) > + conn->urg_state = SMC_URG_READ; > } > + bh_unlock_sock(sk); > + local_bh_enable(); > + if (!valid) > + return -EINVAL; > > - if (sk->sk_state == SMC_CLOSED || sk->sk_shutdown & RCV_SHUTDOWN) > - return 0; > + SMC_STAT_INC(smc, urg_data_cnt); > + msg->msg_flags |= MSG_OOB; > + if (len > 0) { > + if (!(flags & MSG_TRUNC)) > + rc = memcpy_to_msg(msg, &byte, 1); > + len = 1; > + /* Urgent Byte was already accounted for, but trigger > + * skipping the urgent byte in non-inline case > + */ > + if (!(flags & MSG_PEEK)) > + smc_rx_update_consumer(smc, cons, 0); > + } else { > + msg->msg_flags |= MSG_TRUNC; > + } > > - return -EAGAIN; > + return rc ? -EFAULT : len; > } > > static bool smc_rx_recvmsg_data_available(struct smc_sock *smc, size_t peeked) > The locking looks right to me. One thing, though: since this block is being rewritten anyway, the "> 1" here is the bug in the last item of your "Not fixed here", and it is not hard to hit. If the urgent byte is the only unread byte, e.g. after a one-byte send(MSG_OOB) to a reader that has drained everything, cons is urg_curs - 1 and the distance is 1. skip_pend stays false and urg_state becomes SMC_URG_READ, so the gate in smc_rx_update_consumer() is false and the byte is never skipped. smc_rx_recvmsg_data_available() only skips while the state is SMC_URG_VALID. The sender keeps urg_tx_pend set because peer_rmbe_space never gets back to peer_rmbe_size, and its next send() waits. That is just the normal poll(POLLPRI) + recv(MSG_OOB) pattern, and it matches your own test in the cover letter. No race or wrap is needed. Changing the test to "> 0" fixes that case. smc_rx_update_consumer() then sees skip_pend and takes its diff == 1 branch. A zero-length recv(MSG_OOB) still sets SMC_URG_READ, but it never computes skip_pend or calls smc_rx_update_consumer(), so it leaves the byte behind at any distance. Doing both outside the len > 0 check would cover that as well. Could you add this as a follow-up patch with the same Fixes tag? It's not a reason to hold this one. Reviewed-by: Sidraya Jayagond Thanks, Sidraya