summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-06-03 21:47:09 -0700
committerShentubot <shentubot@google.com>2019-06-03 21:48:19 -0700
commit90a116890fcea9fd39911bae854e4e67608a141d (patch)
treeb187c89a7c3b1188347b2fb7684b84a1bc44630e /test
parent00f8663887cbf9057d93e8848eb9538cf1c0cff4 (diff)
gvisor/sock/unix: pass creds when a message is sent between unconnected sockets
and don't report a sender address if it doesn't have one PiperOrigin-RevId: 251371284
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/accept_bind.cc14
-rw-r--r--test/syscalls/linux/socket_unix_unbound_dgram.cc24
2 files changed, 25 insertions, 13 deletions
diff --git a/test/syscalls/linux/accept_bind.cc b/test/syscalls/linux/accept_bind.cc
index 56377feab..1122ea240 100644
--- a/test/syscalls/linux/accept_bind.cc
+++ b/test/syscalls/linux/accept_bind.cc
@@ -448,19 +448,7 @@ TEST_P(AllSocketPairTest, UnboundSenderAddr) {
RetryEINTR(recvfrom)(accepted_fd.get(), &i, sizeof(i), 0,
reinterpret_cast<sockaddr*>(&addr), &addr_len),
SyscallSucceedsWithValue(sizeof(i)));
- if (!IsRunningOnGvisor()) {
- // Linux returns a zero length for addresses from recvfrom(2) and
- // recvmsg(2). This differs from the behavior of getpeername(2) and
- // getsockname(2). For simplicity, we use the getpeername(2) and
- // getsockname(2) behavior for recvfrom(2) and recvmsg(2).
- EXPECT_EQ(addr_len, 0);
- return;
- }
- EXPECT_EQ(addr_len, 2);
- EXPECT_EQ(
- memcmp(&addr, sockets->second_addr(),
- std::min((size_t)addr_len, (size_t)sockets->second_addr_len())),
- 0);
+ EXPECT_EQ(addr_len, 0);
}
TEST_P(AllSocketPairTest, BoundSenderAddr) {
diff --git a/test/syscalls/linux/socket_unix_unbound_dgram.cc b/test/syscalls/linux/socket_unix_unbound_dgram.cc
index 2ddc5c11f..52aef891f 100644
--- a/test/syscalls/linux/socket_unix_unbound_dgram.cc
+++ b/test/syscalls/linux/socket_unix_unbound_dgram.cc
@@ -13,7 +13,9 @@
// limitations under the License.
#include <stdio.h>
+#include <sys/socket.h>
#include <sys/un.h>
+
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "test/syscalls/linux/socket_test_util.h"
@@ -142,6 +144,28 @@ TEST_P(UnboundDgramUnixSocketPairTest, SendtoWithoutConnect) {
SyscallSucceedsWithValue(sizeof(data)));
}
+TEST_P(UnboundDgramUnixSocketPairTest, SendtoWithoutConnectPassCreds) {
+ auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
+
+ ASSERT_THAT(bind(sockets->first_fd(), sockets->first_addr(),
+ sockets->first_addr_size()),
+ SyscallSucceeds());
+
+ SetSoPassCred(sockets->first_fd());
+ char data = 'a';
+ ASSERT_THAT(
+ RetryEINTR(sendto)(sockets->second_fd(), &data, sizeof(data), 0,
+ sockets->first_addr(), sockets->first_addr_size()),
+ SyscallSucceedsWithValue(sizeof(data)));
+ ucred creds;
+ creds.pid = -1;
+ char buf[sizeof(data) + 1];
+ ASSERT_NO_FATAL_FAILURE(
+ RecvCreds(sockets->first_fd(), &creds, buf, sizeof(buf), sizeof(data)));
+ EXPECT_EQ(0, memcmp(&data, buf, sizeof(data)));
+ EXPECT_THAT(getpid(), SyscallSucceedsWithValue(creds.pid));
+}
+
INSTANTIATE_TEST_SUITE_P(
AllUnixDomainSockets, UnboundDgramUnixSocketPairTest,
::testing::ValuesIn(VecCat<SocketPairKind>(