Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/tls: use the new scatterwalk functions

Replace calls to the deprecated function scatterwalk_copychunks() with
memcpy_from_scatterwalk(), memcpy_to_scatterwalk(), or
scatterwalk_skip() as appropriate. The new functions generally behave
more as expected and eliminate the need to call scatterwalk_done() or
scatterwalk_pagedone().

However, the new functions intentionally do not advance to the next sg
entry right away, which would have broken chain_to_walk() which is
accessing the fields of struct scatter_walk directly. To avoid this,
replace chain_to_walk() with scatterwalk_get_sglist() which supports the
needed functionality.

Cc: Boris Pismenny <borisp@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
6be051ce fd7cbef6

+6 -25
+6 -25
net/tls/tls_device_fallback.c
··· 37 37 38 38 #include "tls.h" 39 39 40 - static void chain_to_walk(struct scatterlist *sg, struct scatter_walk *walk) 41 - { 42 - struct scatterlist *src = walk->sg; 43 - int diff = walk->offset - src->offset; 44 - 45 - sg_set_page(sg, sg_page(src), 46 - src->length - diff, walk->offset); 47 - 48 - scatterwalk_crypto_chain(sg, sg_next(src), 2); 49 - } 50 - 51 40 static int tls_enc_record(struct aead_request *aead_req, 52 41 struct crypto_aead *aead, char *aad, 53 42 char *iv, __be64 rcd_sn, ··· 58 69 buf_size = TLS_HEADER_SIZE + cipher_desc->iv; 59 70 len = min_t(int, *in_len, buf_size); 60 71 61 - scatterwalk_copychunks(buf, in, len, 0); 62 - scatterwalk_copychunks(buf, out, len, 1); 72 + memcpy_from_scatterwalk(buf, in, len); 73 + memcpy_to_scatterwalk(out, buf, len); 63 74 64 75 *in_len -= len; 65 76 if (!*in_len) 66 77 return 0; 67 - 68 - scatterwalk_pagedone(in, 0, 1); 69 - scatterwalk_pagedone(out, 1, 1); 70 78 71 79 len = buf[4] | (buf[3] << 8); 72 80 len -= cipher_desc->iv; ··· 76 90 sg_init_table(sg_out, ARRAY_SIZE(sg_out)); 77 91 sg_set_buf(sg_in, aad, TLS_AAD_SPACE_SIZE); 78 92 sg_set_buf(sg_out, aad, TLS_AAD_SPACE_SIZE); 79 - chain_to_walk(sg_in + 1, in); 80 - chain_to_walk(sg_out + 1, out); 93 + scatterwalk_get_sglist(in, sg_in + 1); 94 + scatterwalk_get_sglist(out, sg_out + 1); 81 95 82 96 *in_len -= len; 83 97 if (*in_len < 0) { ··· 96 110 } 97 111 98 112 if (*in_len) { 99 - scatterwalk_copychunks(NULL, in, len, 2); 100 - scatterwalk_pagedone(in, 0, 1); 101 - scatterwalk_copychunks(NULL, out, len, 2); 102 - scatterwalk_pagedone(out, 1, 1); 113 + scatterwalk_skip(in, len); 114 + scatterwalk_skip(out, len); 103 115 } 104 116 105 117 len -= cipher_desc->tag; ··· 145 161 rcd_sn++; 146 162 147 163 } while (rc == 0 && len); 148 - 149 - scatterwalk_done(&in, 0, 0); 150 - scatterwalk_done(&out, 1, 0); 151 164 152 165 return rc; 153 166 }