Commit dc54b813 authored by Sabrina Dubroca's avatar Sabrina Dubroca Committed by Jakub Kicinski

selftests: tls: add test with a partially invalid iov

Make sure that we don't return more bytes than we actually received if
the userspace buffer was bogus. We expect to receive at least the rest
of rec1, and possibly some of rec2 (currently, we don't, but that
would be ok).
Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/720e61b3d3eab40af198a58ce2cd1ee019f0ceb1.1711120964.git.sd@queasysnail.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 85eef9a4
......@@ -1615,6 +1615,40 @@ TEST_F(tls, getsockopt)
EXPECT_EQ(errno, EINVAL);
}
TEST_F(tls, recv_efault)
{
char *rec1 = "1111111111";
char *rec2 = "2222222222";
struct msghdr hdr = {};
struct iovec iov[2];
char recv_mem[12];
int ret;
if (self->notls)
SKIP(return, "no TLS support");
EXPECT_EQ(send(self->fd, rec1, 10, 0), 10);
EXPECT_EQ(send(self->fd, rec2, 10, 0), 10);
iov[0].iov_base = recv_mem;
iov[0].iov_len = sizeof(recv_mem);
iov[1].iov_base = NULL; /* broken iov to make process_rx_list fail */
iov[1].iov_len = 1;
hdr.msg_iovlen = 2;
hdr.msg_iov = iov;
EXPECT_EQ(recv(self->cfd, recv_mem, 1, 0), 1);
EXPECT_EQ(recv_mem[0], rec1[0]);
ret = recvmsg(self->cfd, &hdr, 0);
EXPECT_LE(ret, sizeof(recv_mem));
EXPECT_GE(ret, 9);
EXPECT_EQ(memcmp(rec1, recv_mem, 9), 0);
if (ret > 9)
EXPECT_EQ(memcmp(rec2, recv_mem + 9, ret - 9), 0);
}
FIXTURE(tls_err)
{
int fd, cfd;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment