sst-linux/net
Guangguan Wang f08f0d0392 net/smc: fix data error when recvmsg with MSG_PEEK flag
[ Upstream commit a4b6539038c1aa1ae871aacf6e41b566c3613993 ]

When recvmsg with MSG_PEEK flag, the data will be copied to
user's buffer without advancing consume cursor and without
reducing the length of rx available data. Once the expected
peek length is larger than the value of bytes_to_rcv, in the
loop of do while in smc_rx_recvmsg, the first loop will copy
bytes_to_rcv bytes of data from the position local_tx_ctrl.cons,
the second loop will copy the min(bytes_to_rcv, read_remaining)
bytes from the position local_tx_ctrl.cons again because of the
lacking of process with advancing consume cursor and reducing
the length of available data. So do the subsequent loops. The
data copied in the second loop and the subsequent loops will
result in data error, as it should not be copied if no more data
arrives and it should be copied from the position advancing
bytes_to_rcv bytes from the local_tx_ctrl.cons if more data arrives.

This issue can be reproduce by the following python script:
server.py:
import socket
import time
server_ip = '0.0.0.0'
server_port = 12346
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((server_ip, server_port))
server_socket.listen(1)
print('Server is running and listening for connections...')
conn, addr = server_socket.accept()
print('Connected by', addr)
while True:
    data = conn.recv(1024)
    if not data:
        break
    print('Received request:', data.decode())
    conn.sendall(b'Hello, client!\n')
    time.sleep(5)
    conn.sendall(b'Hello, again!\n')
conn.close()

client.py:
import socket
server_ip = '<server ip>'
server_port = 12346
resp=b'Hello, client!\nHello, again!\n'
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((server_ip, server_port))
request = 'Hello, server!'
client_socket.sendall(request.encode())
peek_data = client_socket.recv(len(resp),
    socket.MSG_PEEK | socket.MSG_WAITALL)
print('Peeked data:', peek_data.decode())
client_socket.close()

Fixes: 952310ccf2 ("smc: receive data from RMBE")
Reported-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: Guangguan Wang <guangguan.wang@linux.alibaba.com>
Link: https://patch.msgid.link/20250104143201.35529-1-guangguan.wang@linux.alibaba.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-02-21 13:49:03 +01:00
..
6lowpan
9p
802 net: 802: LLC+SNAP OID:PID lookup on start of skb data 2025-01-17 13:34:38 +01:00
8021q
appletalk
atm
ax25 ax25: rcu protect dev->ax25_ptr 2025-02-21 13:49:02 +01:00
batman-adv batman-adv: Do not let TT changes list grows indefinitely 2024-12-19 18:08:52 +01:00
bluetooth Bluetooth: hci_sync: Fix not setting Random Address when required 2025-01-17 13:34:39 +01:00
bpf
bpfilter
bridge
caif
can net: af_can: do not leave a dangling sk pointer in can_create() 2024-12-14 19:54:41 +01:00
ceph
core net: add exit_batch_rtnl() method 2025-01-23 17:17:09 +01:00
dcb
dccp net: fix data-races around sk->sk_forward_alloc 2025-01-23 17:17:17 +01:00
devlink
dns_resolver
dsa
ethernet
ethtool ethtool: Fix wrong mod state in case of verbose and no_mask bitset 2024-12-14 19:54:23 +01:00
hsr net: hsr: avoid potential out-of-bound access in fill_frame_info() 2024-12-14 19:54:21 +01:00
ieee802154 net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() 2024-12-14 19:54:41 +01:00
ife
ipv4 inetpeer: do not get a refcount in inet_getpeer() 2025-02-21 13:49:01 +01:00
ipv6 inetpeer: do not get a refcount in inet_getpeer() 2025-02-21 13:49:01 +01:00
iucv
kcm
key
l2tp
l3mdev
lapb
llc net: llc: reset skb->transport_header 2025-01-09 13:30:01 +01:00
mac80211 wifi: mac80211: prohibit deactivating all links 2025-02-21 13:49:03 +01:00
mac802154 mac802154: check local interfaces before deleting sdata list 2025-01-23 17:17:11 +01:00
mctp net: mctp: handle skb cleanup on sock_queue failures 2025-01-09 13:29:57 +01:00
mpls
mptcp mptcp: be sure to send ack when mptcp-level window re-opens 2025-01-23 17:17:13 +01:00
ncsi
netfilter netfilter: conntrack: clamp maximum hashtable size to INT_MAX 2025-01-17 13:34:39 +01:00
netlabel
netlink
netrom netrom: check buffer length before accessing it 2025-01-09 13:30:01 +01:00
nfc
nsh
openvswitch openvswitch: fix lockup on tx to unregistering netdev with carrier 2025-01-23 17:17:09 +01:00
packet af_packet: fix vlan_get_protocol_dgram() vs MSG_PEEK 2025-01-09 13:30:02 +01:00
phonet
psample
qrtr
rds
rfkill
rose
rxrpc
sched net_sched: sch_sfq: don't allow 1 packet limit 2025-02-21 13:48:58 +01:00
sctp sctp: sysctl: plpmtud_probe_interval: avoid using current->nsproxy 2025-01-17 13:34:42 +01:00
smc net/smc: fix data error when recvmsg with MSG_PEEK flag 2025-02-21 13:49:03 +01:00
strparser
sunrpc
switchdev
tipc tipc: fix NULL deref in cleanup_bearer() 2024-12-19 18:08:52 +01:00
tls tls: Fix tls_sw_sendmsg error handling 2025-01-17 13:34:39 +01:00
unix
vmw_vsock vsock: prevent null-ptr-deref in vsock_*[has_data|has_space] 2025-01-23 17:17:14 +01:00
wireless wifi: nl80211: fix NL80211_ATTR_MLO_LINK_ID off-by-one 2024-12-19 18:08:51 +01:00
x25
xdp xsk: fix OOB map writes when deleting elements 2024-12-14 19:54:36 +01:00
xfrm
compat.c
devres.c
Kconfig
Kconfig.debug
Makefile
socket.c
sysctl_net.c