Skip to content

Commit cfffa5f

Browse files
author
Mukesh Kacker
committed
rds: return EMSGSIZE for oversize requests before processing/queueing
rds_send_queue_rm() allows for the "current datagram" being queued to exceed SO_SNDBUF thresholds by checking bytes queued without counting in length of current datagram. (Since sk_sndbuf is set to twice requested SO_SNDBUF value as a kernel heuristic this is usually fine!) If this "current datagram" squeezing past the threshold is itself many times the size of the sk_sndbuf threshold itself then even twice the SO_SNDBUF does not save us and it gets queued but cannot be transmitted. Threads block and deadlock and device becomes unusable. The check for this datagram not exceeding SNDBUF thresholds (EMSGSIZE) is not done on this datagram as that check is only done if queueing attempt fails. (Datagrams that follow this datagram fail queueing attempts, go through the check and eventually trip EMSGSIZE error but zero length datagrams silently fail!) This fix moves the check for datagrams exceeding SNDBUF limits before any processing or queueing is attempted and returns EMSGSIZE early in the rds_sndmsg() code. This change also ensures that all datagrams get checked for exceeding SNDBUF/sk_sndbuf size limits and the large datagrams that exceed those limits do not get to rds_send_queue_rm() code for processing. Orabug: 20971222 Signed-off-by: Mukesh Kacker <[email protected]> Reviewed-by: Wengang Wang <[email protected]> Acked-by: Chien Yen <[email protected]>
1 parent 45fd12d commit cfffa5f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/rds/send.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,11 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len)
11991199
goto out;
12001200
}
12011201

1202+
if (payload_len > rds_sk_sndbuf(rs)) {
1203+
ret = -EMSGSIZE;
1204+
goto out;
1205+
}
1206+
12021207
/* size of rm including all sgs */
12031208
ret = rds_rm_size(msg, payload_len);
12041209
if (ret < 0)
@@ -1316,11 +1321,7 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len)
13161321
while (!rds_send_queue_rm(rs, conn, rm, rs->rs_bound_port,
13171322
dport, &queued)) {
13181323
rds_stats_inc(s_send_queue_full);
1319-
/* XXX make sure this is reasonable */
1320-
if (payload_len > rds_sk_sndbuf(rs)) {
1321-
ret = -EMSGSIZE;
1322-
goto out;
1323-
}
1324+
13241325
if (nonblock) {
13251326
ret = -EAGAIN;
13261327
goto out;

0 commit comments

Comments
 (0)