Skip to content

Commit 153c66a

Browse files
lxinSomasundaram Krishnasamy
authored andcommitted
sctp: implement memory accounting on tx path
Now when sending packets, sk_mem_charge() and sk_mem_uncharge() have been used to set sk_forward_alloc. We just need to call sk_wmem_schedule() to check if the allocated should be raised, and call sk_mem_reclaim() to check if the allocated should be reduced when it's under memory pressure. If sk_wmem_schedule() returns false, which means no memory is allowed to allocate, it will block and wait for memory to become available. Note different from tcp, sctp wait_for_buf happens before allocating any skb, so memory accounting check is done with the whole msg_len before it too. Reported-by: Matteo Croce <[email protected]> Tested-by: Matteo Croce <[email protected]> Acked-by: Neil Horman <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 1033990) Orabug: 31753070 CVE: CVE-2019-3874 Signed-off-by: Saeed Mirzamohammadi <[email protected]> Reviewed-by: John Donnelly <[email protected]> Conflicts: net/sctp/socket.c - modified to match the UEK code base. Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent b58e9b5 commit 153c66a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/sctp/socket.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,9 +1981,11 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
19811981
if (sctp_wspace(asoc) < msg_len)
19821982
sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc));
19831983

1984-
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
1985-
if (!sctp_wspace(asoc)) {
1986-
/* sk can be changed by peel off when waiting for buf. */
1984+
if (sk_under_memory_pressure(sk))
1985+
sk_mem_reclaim(sk);
1986+
1987+
if (sctp_wspace(asoc) <= 0 || !sk_wmem_schedule(sk, msg_len)) {
1988+
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
19871989
err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
19881990
if (err) {
19891991
if (err == -ESRCH) {
@@ -7894,7 +7896,10 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
78947896
goto do_error;
78957897
if (signal_pending(current))
78967898
goto do_interrupted;
7897-
if (msg_len <= sctp_wspace(asoc))
7899+
if (sk_under_memory_pressure(sk))
7900+
sk_mem_reclaim(sk);
7901+
if ((int)msg_len <= sctp_wspace(asoc) &&
7902+
sk_wmem_schedule(sk, msg_len))
78987903
break;
78997904

79007905
/* Let another process have a go. Since we are going

0 commit comments

Comments
 (0)