Skip to content

Commit fedf201

Browse files
Dave Watsondavem330
authored andcommitted
net: tls: Refactor control message handling on recv
For TLS 1.3, the control message is encrypted. Handle control message checks after decryption. Signed-off-by: Dave Watson <davejwatson@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a2ef9b6 commit fedf201

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

net/tls/tls_sw.c

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,16 +1421,15 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,
14211421

14221422
return err;
14231423
}
1424+
rxm->offset += tls_ctx->rx.prepend_size;
1425+
rxm->full_len -= tls_ctx->rx.overhead_size;
1426+
tls_advance_record_sn(sk, &tls_ctx->rx);
1427+
ctx->decrypted = true;
1428+
ctx->saved_data_ready(sk);
14241429
} else {
14251430
*zc = false;
14261431
}
14271432

1428-
rxm->offset += tls_ctx->rx.prepend_size;
1429-
rxm->full_len -= tls_ctx->rx.overhead_size;
1430-
tls_advance_record_sn(sk, &tls_ctx->rx);
1431-
ctx->decrypted = true;
1432-
ctx->saved_data_ready(sk);
1433-
14341433
return err;
14351434
}
14361435

@@ -1609,6 +1608,25 @@ int tls_sw_recvmsg(struct sock *sk,
16091608

16101609
rxm = strp_msg(skb);
16111610

1611+
to_decrypt = rxm->full_len - tls_ctx->rx.overhead_size;
1612+
1613+
if (to_decrypt <= len && !is_kvec && !is_peek &&
1614+
ctx->control == TLS_RECORD_TYPE_DATA)
1615+
zc = true;
1616+
1617+
err = decrypt_skb_update(sk, skb, &msg->msg_iter,
1618+
&chunk, &zc, ctx->async_capable);
1619+
if (err < 0 && err != -EINPROGRESS) {
1620+
tls_err_abort(sk, EBADMSG);
1621+
goto recv_end;
1622+
}
1623+
1624+
if (err == -EINPROGRESS) {
1625+
async = true;
1626+
num_async++;
1627+
goto pick_next_record;
1628+
}
1629+
16121630
if (!cmsg) {
16131631
int cerr;
16141632

@@ -1626,40 +1644,22 @@ int tls_sw_recvmsg(struct sock *sk,
16261644
goto recv_end;
16271645
}
16281646

1629-
to_decrypt = rxm->full_len - tls_ctx->rx.overhead_size;
1630-
1631-
if (to_decrypt <= len && !is_kvec && !is_peek)
1632-
zc = true;
1633-
1634-
err = decrypt_skb_update(sk, skb, &msg->msg_iter,
1635-
&chunk, &zc, ctx->async_capable);
1636-
if (err < 0 && err != -EINPROGRESS) {
1637-
tls_err_abort(sk, EBADMSG);
1638-
goto recv_end;
1639-
}
1640-
1641-
if (err == -EINPROGRESS) {
1642-
async = true;
1643-
num_async++;
1644-
goto pick_next_record;
1645-
} else {
1646-
if (!zc) {
1647-
if (rxm->full_len > len) {
1648-
retain_skb = true;
1649-
chunk = len;
1650-
} else {
1651-
chunk = rxm->full_len;
1652-
}
1647+
if (!zc) {
1648+
if (rxm->full_len > len) {
1649+
retain_skb = true;
1650+
chunk = len;
1651+
} else {
1652+
chunk = rxm->full_len;
1653+
}
16531654

1654-
err = skb_copy_datagram_msg(skb, rxm->offset,
1655-
msg, chunk);
1656-
if (err < 0)
1657-
goto recv_end;
1655+
err = skb_copy_datagram_msg(skb, rxm->offset,
1656+
msg, chunk);
1657+
if (err < 0)
1658+
goto recv_end;
16581659

1659-
if (!is_peek) {
1660-
rxm->offset = rxm->offset + chunk;
1661-
rxm->full_len = rxm->full_len - chunk;
1662-
}
1660+
if (!is_peek) {
1661+
rxm->offset = rxm->offset + chunk;
1662+
rxm->full_len = rxm->full_len - chunk;
16631663
}
16641664
}
16651665

@@ -1759,15 +1759,15 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
17591759
if (!skb)
17601760
goto splice_read_end;
17611761

1762-
/* splice does not support reading control messages */
1763-
if (ctx->control != TLS_RECORD_TYPE_DATA) {
1764-
err = -ENOTSUPP;
1765-
goto splice_read_end;
1766-
}
1767-
17681762
if (!ctx->decrypted) {
17691763
err = decrypt_skb_update(sk, skb, NULL, &chunk, &zc, false);
17701764

1765+
/* splice does not support reading control messages */
1766+
if (ctx->control != TLS_RECORD_TYPE_DATA) {
1767+
err = -ENOTSUPP;
1768+
goto splice_read_end;
1769+
}
1770+
17711771
if (err < 0) {
17721772
tls_err_abort(sk, EBADMSG);
17731773
goto splice_read_end;

0 commit comments

Comments
 (0)