diff mbox series

[22/25] lustre: obdclass: Free t10pi crypto state on error

Message ID 20250130141115.950749-23-jsimmons@infradead.org (mailing list archive)
State New
Headers show
Series lustre: sync to OpenSFS branch April 30, 2023 | expand

Commit Message

James Simmons Jan. 30, 2025, 2:11 p.m. UTC
From: Oleg Drokin <green@whamcloud.com>

Looks like when error happens we forgot to release crypto state that
not only leaks memory directly, but potentially can tie in-memory
pages too.

WC-bug-id: https://jira.whamcloud.com/browse/LU-15615
Lustre-commit: 6a88222bd6a1c0f5b ("LU-15615 target: Free t10pi crypto state on error")
Signed-off-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50539
Reviewed-by: Li Xi <lixi@ddn.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 fs/lustre/obdclass/integrity.c | 35 ++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/fs/lustre/obdclass/integrity.c b/fs/lustre/obdclass/integrity.c
index e6069cb30213..57f52ab829cd 100644
--- a/fs/lustre/obdclass/integrity.c
+++ b/fs/lustre/obdclass/integrity.c
@@ -45,37 +45,40 @@  __be16 obd_dif_ip_fn(void *data, unsigned int len)
 EXPORT_SYMBOL(obd_dif_ip_fn);
 
 int obd_page_dif_generate_buffer(const char *obd_name, struct page *page,
-				 u32 offset, u32 length,
+				 u32 start, u32 length,
 				 __be16 *guard_start, int guard_number,
 				 int *used_number, int sector_size,
 				 obd_dif_csum_fn *fn)
 {
-	unsigned int i = offset;
-	unsigned int end = offset + length;
+	unsigned int off = start;
+	unsigned int end = start + length;
 	char *data_buf;
 	__be16 *guard_buf = guard_start;
 	unsigned int data_size;
-	int used = 0;
+	int guard_used = 0;
+	int rc = 0;
 
-	data_buf = kmap(page) + offset;
-	while (i < end) {
-		if (used >= guard_number) {
-			CERROR("%s: unexpected used guard number of DIF %u/%u, data length %u, sector size %u: rc = %d\n",
-			       obd_name, used, guard_number, length,
-			       sector_size, -E2BIG);
-			return -E2BIG;
+	data_buf = kmap(page) + start;
+	while (off < end) {
+		if (guard_used >= guard_number) {
+			rc = -E2BIG;
+			CERROR("%s: used %u >= guard %u, data %u+%u, sector_size %u: rc = %d\n",
+			       obd_name, guard_used, guard_number, start,
+			       length, sector_size, rc);
+			goto out;
 		}
-		data_size = min(round_up(i + 1, sector_size), end) - i;
+		data_size = min(round_up(off + 1, sector_size), end) - off;
 		*guard_buf = fn(data_buf, data_size);
 		guard_buf++;
+		guard_used++;
 		data_buf += data_size;
-		i += data_size;
-		used++;
+		off += data_size;
 	}
+	*used_number = guard_used;
+out:
 	kunmap(page);
-	*used_number = used;
 
-	return 0;
+	return rc;
 }
 EXPORT_SYMBOL(obd_page_dif_generate_buffer);