Skip to contentSkip to conversation

af_alg08: Don't check recv() errno

PATCH In review Martin Doucha 3 participants 3 messages May 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 af_alg08: Don't check recv() errno

Recent kernels return EBADMSG from recv() when the crypto operation fails. However, older kernels return EINVAL instead. Remove check for specific errno and only check that recv() failed.

---
 testcases/kernel/crypto/af_alg08.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
testcases/kernel/crypto/af_alg08.c +8 -1
index 5e04b579c..4cc3e5c4e 100644
@@ -100,7 +100,14 @@ static void try_corrupt(void)
 	SAFE_SPLICE(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0);
 
 	/* Expected to fail (invalid ciphertext); triggers the scratch write */
-	TST_EXP_FAIL_SILENT(recv(reqfd, recvbuf, sizeof(recvbuf), 0), EBADMSG);
+	TEST(recv(reqfd, recvbuf, sizeof(recvbuf), 0));
+
+	if (TST_RET >= 0) {
+		tst_res(TFAIL, "Decryption succeeded unexpectedly");
+	} else if (TST_RET != -1) {
+		tst_res(TFAIL | TTERRNO, "Invalid recv() return value %ld",
+			TST_RET);
+	}
 
 	SAFE_CLOSE(pipefd[0]);
 	SAFE_CLOSE(pipefd[1]);
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 16 lines

Recent kernels return EBADMSG from recv() when the crypto operation fails. However, older kernels return EINVAL instead. Remove check for specific errno and only check that recv() failed.

---
 testcases/kernel/crypto/af_alg08.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
testcases/kernel/crypto/af_alg08.c +0 -0
index 5e04b579c..4cc3e5c4e 100644
@@ -100,7 +100,14 @@ static void try_corrupt(void)
 	SAFE_SPLICE(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0);
 

testcases/kernel/crypto/af_alg08.c static void try_corrupt(void) · line 110

Quoted 10 lines
testcases/kernel/crypto/af_alg08.c +8 -1
 	/* Expected to fail (invalid ciphertext); triggers the scratch write */
-	TST_EXP_FAIL_SILENT(recv(reqfd, recvbuf, sizeof(recvbuf), 0), EBADMSG);
+	TEST(recv(reqfd, recvbuf, sizeof(recvbuf), 0));
+
+	if (TST_RET >= 0) {
+		tst_res(TFAIL, "Decryption succeeded unexpectedly");
+	} else if (TST_RET != -1) {
+		tst_res(TFAIL | TTERRNO, "Invalid recv() return value %ld",
+			TST_RET);
+	}

Maybe allowing all errnos is bit to broad.

I wonder why we haven't added TST_EXP_FAIL_ARR_SILENT() since that should be as simple as:

#define TST_EXP_FAIL_ARR_SILENT(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...) \
	TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__)
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp