git: 36f4f90efb02 - releng/14.0 - zfs: cherry-pick commit from master

From: Gordon Tetlow <gordon_at_FreeBSD.org>
Date: Fri, 01 Dec 2023 00:38:37 UTC
The branch releng/14.0 has been updated by gordon:

URL: https://cgit.FreeBSD.org/src/commit/?id=36f4f90efb027847d6e4b7a940afbee2ad7b3b7e

commit 36f4f90efb027847d6e4b7a940afbee2ad7b3b7e
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2023-11-19 01:01:03 +0000
Commit:     Gordon Tetlow <gordon@FreeBSD.org>
CommitDate: 2023-11-30 21:32:41 +0000

    zfs: cherry-pick commit from master
    
     #15543 27d8c23c5 ZIL: Do not encrypt block pointers in lr_clone_range_t
    
    Obtained from:  OpenZFS
    Approved by:    so
    Security:       FreeBSD-EN-23:16.openzfs
    
    (cherry picked from commit 27d8c23c582056a23509a7b80844a1b6435750b0)
    (cherry picked from commit 1b910e43b0216b284bddc83dbdb1322f8d76062c)
---
 sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c | 13 +++++++++++++
 sys/contrib/openzfs/module/os/linux/zfs/zio_crypt.c   | 15 +++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c
index fdbe13dbb5e9..024a931d7816 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zio_crypt.c
@@ -1364,6 +1364,19 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf,
 				vec++;
 				total_len += crypt_len;
 			}
+		} else if (txtype == TX_CLONE_RANGE) {
+			const size_t o = offsetof(lr_clone_range_t, lr_nbps);
+			crypt_len = o - sizeof (lr_t);
+			dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t);
+			dst_iovecs[vec].iov_len = crypt_len;
+
+			/* copy the bps now since they will not be encrypted */
+			memcpy(dlrp + o, slrp + o, lr_len - o);
+			memcpy(aadp, slrp + o, lr_len - o);
+			aadp += lr_len - o;
+			aad_len += lr_len - o;
+			vec++;
+			total_len += crypt_len;
 		} else {
 			crypt_len = lr_len - sizeof (lr_t);
 			dst_iovecs[vec].iov_base = (char *)dlrp +
diff --git a/sys/contrib/openzfs/module/os/linux/zfs/zio_crypt.c b/sys/contrib/openzfs/module/os/linux/zfs/zio_crypt.c
index 55554d09ee43..775ab8efbcdf 100644
--- a/sys/contrib/openzfs/module/os/linux/zfs/zio_crypt.c
+++ b/sys/contrib/openzfs/module/os/linux/zfs/zio_crypt.c
@@ -1543,6 +1543,21 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf,
 				nr_iovecs++;
 				total_len += crypt_len;
 			}
+		} else if (txtype == TX_CLONE_RANGE) {
+			const size_t o = offsetof(lr_clone_range_t, lr_nbps);
+			crypt_len = o - sizeof (lr_t);
+			src_iovecs[nr_iovecs].iov_base = slrp + sizeof (lr_t);
+			src_iovecs[nr_iovecs].iov_len = crypt_len;
+			dst_iovecs[nr_iovecs].iov_base = dlrp + sizeof (lr_t);
+			dst_iovecs[nr_iovecs].iov_len = crypt_len;
+
+			/* copy the bps now since they will not be encrypted */
+			memcpy(dlrp + o, slrp + o, lr_len - o);
+			memcpy(aadp, slrp + o, lr_len - o);
+			aadp += lr_len - o;
+			aad_len += lr_len - o;
+			nr_iovecs++;
+			total_len += crypt_len;
 		} else {
 			crypt_len = lr_len - sizeof (lr_t);
 			src_iovecs[nr_iovecs].iov_base = slrp + sizeof (lr_t);