Skip to content

Commit 630700e

Browse files
bors[bot]ritzk
andauthored
Merge #1317
1317: test_af_alg_aead waits indefinitely r=asomers a=ritzk Starting with linux kernel 4.9, the crypto interface changed slightly such that the authentication tag memory is only needed in the output buffer for encryption and in the input buffer for decryption. Thus, we have fewer bytes to read than the buffer size. Do not block on read. alternatively, we can adjust the decrypted buffer size based on kernel version ( ">= 4.9") to not include auth_size . ``` if kernel_version >= "4.9": let mut decrypted = vec![0u8; payload_len + (assoc_size as usize) ]; ``` before ``` test sys::test_socket::test_af_alg_aead ... test sys::test_socket::test_af_alg_aead has been running for over 60 seconds ``` after ``` test sys::test_socket::test_af_alg_aead ... ok ``` Co-authored-by: Ritesh Khadgaray <khadgaray@gmail.com>
2 parents 2142ec3 + e03e400 commit 630700e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/sys/test_socket.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ pub fn test_af_alg_cipher() {
712712
#[test]
713713
pub fn test_af_alg_aead() {
714714
use libc::{ALG_OP_DECRYPT, ALG_OP_ENCRYPT};
715+
use nix::fcntl::{fcntl, FcntlArg, OFlag};
715716
use nix::sys::uio::IoVec;
716717
use nix::unistd::{read, close};
717718
use nix::sys::socket::{socket, sendmsg, bind, accept, setsockopt,
@@ -790,6 +791,11 @@ pub fn test_af_alg_aead() {
790791

791792
// allocate buffer for decrypted data
792793
let mut decrypted = vec![0u8; payload_len + (assoc_size as usize) + auth_size];
794+
// Starting with kernel 4.9, the interface changed slightly such that the
795+
// authentication tag memory is only needed in the output buffer for encryption
796+
// and in the input buffer for decryption.
797+
// Do not block on read, as we may have fewer bytes than buffer size
798+
fcntl(session_socket,FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).expect("fcntl non_blocking");
793799
let num_bytes = read(session_socket, &mut decrypted).expect("read decrypt");
794800

795801
assert!(num_bytes >= payload_len + (assoc_size as usize));

0 commit comments

Comments
 (0)