Skip to content

Commit c5daa6c

Browse files
Jakub Kicinskidavem330
authored andcommitted
net/tls: use sg_next() to walk sg entries
Partially sent record cleanup path increments an SG entry directly instead of using sg_next(). This should not be a problem today, as encrypted messages should be always allocated as arrays. But given this is a cleanup path it's easy to miss was this ever to change. Use sg_next(), and simplify the code. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Simon Horman <simon.horman@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9e5ffed commit c5daa6c

3 files changed

Lines changed: 5 additions & 13 deletions

File tree

‎include/net/tls.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ int tls_push_sg(struct sock *sk, struct tls_context *ctx,
376376
int flags);
377377
int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
378378
int flags);
379-
bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx);
379+
void tls_free_partial_record(struct sock *sk, struct tls_context *ctx);
380380

381381
static inline struct tls_msg *tls_msg(struct sk_buff *skb)
382382
{

‎net/tls/tls_main.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,15 @@ int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
209209
return tls_push_sg(sk, ctx, sg, offset, flags);
210210
}
211211

212-
bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx)
212+
void tls_free_partial_record(struct sock *sk, struct tls_context *ctx)
213213
{
214214
struct scatterlist *sg;
215215

216-
sg = ctx->partially_sent_record;
217-
if (!sg)
218-
return false;
219-
220-
while (1) {
216+
for (sg = ctx->partially_sent_record; sg; sg = sg_next(sg)) {
221217
put_page(sg_page(sg));
222218
sk_mem_uncharge(sk, sg->length);
223-
224-
if (sg_is_last(sg))
225-
break;
226-
sg++;
227219
}
228220
ctx->partially_sent_record = NULL;
229-
return true;
230221
}
231222

232223
static void tls_write_space(struct sock *sk)

‎net/tls/tls_sw.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,8 @@ void tls_sw_release_resources_tx(struct sock *sk)
20892089
/* Free up un-sent records in tx_list. First, free
20902090
* the partially sent record if any at head of tx_list.
20912091
*/
2092-
if (tls_free_partial_record(sk, tls_ctx)) {
2092+
if (tls_ctx->partially_sent_record) {
2093+
tls_free_partial_record(sk, tls_ctx);
20932094
rec = list_first_entry(&ctx->tx_list,
20942095
struct tls_rec, list);
20952096
list_del(&rec->list);

0 commit comments

Comments
 (0)