Skip to content

Commit 33627d9

Browse files
Jakub Kicinskigregkh
authored andcommitted
net/tls: use sg_next() to walk sg entries
[ Upstream commit c5daa6c ] 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7d9da04 commit 33627d9

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
@@ -407,7 +407,7 @@ int tls_push_sg(struct sock *sk, struct tls_context *ctx,
407407
int flags);
408408
int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
409409
int flags);
410-
bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx);
410+
void tls_free_partial_record(struct sock *sk, struct tls_context *ctx);
411411

412412
static inline struct tls_msg *tls_msg(struct sk_buff *skb)
413413
{

‎net/tls/tls_main.c‎

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

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

215-
sg = ctx->partially_sent_record;
216-
if (!sg)
217-
return false;
218-
219-
while (1) {
215+
for (sg = ctx->partially_sent_record; sg; sg = sg_next(sg)) {
220216
put_page(sg_page(sg));
221217
sk_mem_uncharge(sk, sg->length);
222-
223-
if (sg_is_last(sg))
224-
break;
225-
sg++;
226218
}
227219
ctx->partially_sent_record = NULL;
228-
return true;
229220
}
230221

231222
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
@@ -2086,7 +2086,8 @@ void tls_sw_release_resources_tx(struct sock *sk)
20862086
/* Free up un-sent records in tx_list. First, free
20872087
* the partially sent record if any at head of tx_list.
20882088
*/
2089-
if (tls_free_partial_record(sk, tls_ctx)) {
2089+
if (tls_ctx->partially_sent_record) {
2090+
tls_free_partial_record(sk, tls_ctx);
20902091
rec = list_first_entry(&ctx->tx_list,
20912092
struct tls_rec, list);
20922093
list_del(&rec->list);

0 commit comments

Comments
 (0)