From c9842f21ce4a9308dba983fd712cc688b26237d5 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Fri, 28 Aug 2020 10:33:44 -0700 Subject: fix panic when calling SO_ORIGINAL_DST without initializing iptables Reported-by: syzbot+074ec22c42305725b79f@syzkaller.appspotmail.com PiperOrigin-RevId: 328963899 --- test/syscalls/linux/iptables.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/syscalls/linux/iptables.cc b/test/syscalls/linux/iptables.cc index f1af8f097..83b6a164a 100644 --- a/test/syscalls/linux/iptables.cc +++ b/test/syscalls/linux/iptables.cc @@ -104,6 +104,19 @@ TEST(IPTablesBasic, GetEntriesErrorPrecedence) { SyscallFailsWithErrno(EINVAL)); } +TEST(IPTablesBasic, OriginalDstErrors) { + SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_RAW))); + + int sock; + ASSERT_THAT(sock = socket(AF_INET, SOCK_STREAM, 0), SyscallSucceeds()); + + // Sockets not affected by NAT should fail to find an original destination. + struct sockaddr_in addr = {}; + socklen_t addr_len = sizeof(addr); + EXPECT_THAT(getsockopt(sock, SOL_IP, SO_ORIGINAL_DST, &addr, &addr_len), + SyscallFailsWithErrno(ENOTCONN)); +} + // Fixture for iptables tests. class IPTablesTest : public ::testing::Test { protected: -- cgit v1.2.3