]> git.itanic.dy.fi Git - linux-stable/commitdiff
net/tls: use sg_next() to walk sg entries
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 27 Nov 2019 20:16:44 +0000 (12:16 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Dec 2019 21:31:02 +0000 (22:31 +0100)
[ Upstream commit c5daa6cccdc2f94aca2c9b3fa5f94e4469997293 ]

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>
include/net/tls.h
net/tls/tls_main.c
net/tls/tls_sw.c

index b3d57c4d091688d55368bde729ca923ff5d167dc..093abb5a3dff75f7adf789c4a3d6b1b857148e34 100644 (file)
@@ -395,7 +395,7 @@ int tls_push_sg(struct sock *sk, struct tls_context *ctx,
                int flags);
 int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
                            int flags);
-bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx);
+void tls_free_partial_record(struct sock *sk, struct tls_context *ctx);
 
 static inline struct tls_msg *tls_msg(struct sk_buff *skb)
 {
index f874cc0da45df2f0269190c68ec2dfc3978fb833..eff444293594f9a47247e541a8fd5bdc68c904e7 100644 (file)
@@ -209,24 +209,15 @@ int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
        return tls_push_sg(sk, ctx, sg, offset, flags);
 }
 
-bool tls_free_partial_record(struct sock *sk, struct tls_context *ctx)
+void tls_free_partial_record(struct sock *sk, struct tls_context *ctx)
 {
        struct scatterlist *sg;
 
-       sg = ctx->partially_sent_record;
-       if (!sg)
-               return false;
-
-       while (1) {
+       for (sg = ctx->partially_sent_record; sg; sg = sg_next(sg)) {
                put_page(sg_page(sg));
                sk_mem_uncharge(sk, sg->length);
-
-               if (sg_is_last(sg))
-                       break;
-               sg++;
        }
        ctx->partially_sent_record = NULL;
-       return true;
 }
 
 static void tls_write_space(struct sock *sk)
index 8343f30bb96d6a2cc5ca12d7c2079abd06ee984c..5dd0f01913c012f9bc91a5070db971a47647480a 100644 (file)
@@ -2084,7 +2084,8 @@ void tls_sw_release_resources_tx(struct sock *sk)
        /* Free up un-sent records in tx_list. First, free
         * the partially sent record if any at head of tx_list.
         */
-       if (tls_free_partial_record(sk, tls_ctx)) {
+       if (tls_ctx->partially_sent_record) {
+               tls_free_partial_record(sk, tls_ctx);
                rec = list_first_entry(&ctx->tx_list,
                                       struct tls_rec, list);
                list_del(&rec->list);