Skip to content

Commit 52ea992

Browse files
nxa22042davem330
authored andcommitted
net/tls: Set count of SG entries if sk_alloc_sg returns -ENOSPC
tls_sw_sendmsg() allocates plaintext and encrypted SG entries using function sk_alloc_sg(). In case the number of SG entries hit MAX_SKB_FRAGS, sk_alloc_sg() returns -ENOSPC and sets the variable for current SG index to '0'. This leads to calling of function tls_push_record() with 'sg_encrypted_num_elem = 0' and later causes kernel crash. To fix this, set the number of SG elements to the number of elements in plaintext/encrypted SG arrays in case sk_alloc_sg() returns -ENOSPC. Fixes: 3c4d755 ("tls: kernel TLS support") Signed-off-by: Vakul Garg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0e1f4c7 commit 52ea992

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/tls/tls_sw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ static int alloc_encrypted_sg(struct sock *sk, int len)
125125
&ctx->sg_encrypted_num_elem,
126126
&ctx->sg_encrypted_size, 0);
127127

128+
if (rc == -ENOSPC)
129+
ctx->sg_encrypted_num_elem = ARRAY_SIZE(ctx->sg_encrypted_data);
130+
128131
return rc;
129132
}
130133

@@ -138,6 +141,9 @@ static int alloc_plaintext_sg(struct sock *sk, int len)
138141
&ctx->sg_plaintext_num_elem, &ctx->sg_plaintext_size,
139142
tls_ctx->pending_open_record_frags);
140143

144+
if (rc == -ENOSPC)
145+
ctx->sg_plaintext_num_elem = ARRAY_SIZE(ctx->sg_plaintext_data);
146+
141147
return rc;
142148
}
143149

0 commit comments

Comments
 (0)