From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] syscalls/recvmsg03.c: add new testcase
Date: Mon, 7 Nov 2016 18:52:40 +0800 [thread overview]
Message-ID: <58205CF8.6000206@cn.fujitsu.com> (raw)
In-Reply-To: <20161102130647.GB22840@rei.lan>
On 2016/11/02 21:06, Cyril Hrubis wrote:
> Hi!
>> +static void server(void)
>> +{
>> + int sock_fd, sock_fd2;
>> + static char recv_buf[128];
>> + struct sockaddr_in server_addr;
>> + struct sockaddr_in from_addr;
>> + struct msghdr msg;
>> + struct iovec iov;
>> +
>> + sock_fd2 = SAFE_SOCKET(AF_RDS, SOCK_SEQPACKET, 0);
>> + sock_fd = sock_fd2;
>> +
>> + memset(&server_addr, 0, sizeof(server_addr));
>> + server_addr.sin_family = AF_INET;
>> + server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
>> + server_addr.sin_port = htons(4000);
>> +
>> + SAFE_BIND(sock_fd2, (struct sockaddr *)&server_addr, sizeof(server_addr));
>> +
>> + msg.msg_name =&from_addr;
>> + msg.msg_namelen = sizeof(from_addr) + 16;
>> + msg.msg_iov =&iov;
>> + msg.msg_iovlen = 1;
>> + msg.msg_iov->iov_base = recv_buf;
>> + msg.msg_iov->iov_len = 128;
>> + msg.msg_control = 0;
>> + msg.msg_controllen = 0;
>> + msg.msg_flags = 0;
>> +
>> + TST_CHECKPOINT_WAKE(0);
>> +
>> + TEST(recvmsg(sock_fd2,&msg, 0));
>> + if (TEST_RETURN == -1) {
>> + tst_res(TFAIL | TERRNO,
>> + "recvmsg() failed to recvice data from client");
>> + goto end;
>> + }
>> +
>> + if (msg.msg_namelen != sizeof(from_addr)) {
>> + tst_res(TFAIL, "msg_namelen was set to %u incorrectly, "
>> + "expected %lu", msg.msg_namelen, sizeof(from_addr));
>> + goto end;
>> + }
>> +
>> + if (sock_fd2 != sock_fd) {
>> + tst_res(TFAIL, "sock_fd was destroyed");
>> + goto end;
>> + }
>> +
>> + tst_res(TPASS, "msg_namelen was set to %u correctly and sock_fd was "
>> + "not destroyed", msg.msg_namelen);
>> +
>> +end:
>> + SAFE_CLOSE(sock_fd2);
> I'm a bit confused here, which one of the sock_fd/sock_fd2 is destroyed?
>
> Looking at the original code in the kernel commit the sock_fd there is
> stored on the stack directly after the sockaddr_in from_addr so I guess
> that the kernel will actually write a few bytes after the end of
> from_addr structure in this case, which will rewrite the msghrd msg in
> your code. Does the test actually fail on kernel without the fix?
>
Hi Cyril
I am sorry for the late response. the msghrd msg was rewritten but
sock_fd2 was not destroyed
on v3.5 kernel without the fix patch, so i will remove the code about
checking sock_fd.
Thanks,
Xiao Yang
>> +}
>> +
>> +static void verify_recvmsg(void)
>> +{
>> + pid_t pid;
>> +
>> + pid = SAFE_FORK();
>> + if (pid == 0) {
>> + TST_CHECKPOINT_WAIT(0);
>> + client();
>> + } else {
>> + server();
>> + SAFE_WAIT(NULL);
> We should rather call tst_reap_children() in this case instead of the
> WAIT since otherwise TBROK from the client() function will not get
> propagated.
>
>> + }
>> +}
>> +
>> +static struct tst_test test = {
>> + .tid = "recvmsg03",
>> + .forks_child = 1,
>> + .needs_checkpoints = 1,
>> + .setup = setup,
>> + .test_all = verify_recvmsg
>> +};
>> --
>> 1.8.3.1
>>
>>
>>
prev parent reply other threads:[~2016-11-07 10:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-31 11:23 [LTP] [PATCH] syscalls/recvmsg03.c: add new testcase Xiao Yang
2016-10-31 13:39 ` Cyril Hrubis
2016-11-01 2:24 ` [LTP] [PATCH v2] " Xiao Yang
2016-11-02 5:34 ` Xiao Yang
2016-11-02 5:22 ` Xiao Yang
2016-11-02 13:06 ` Cyril Hrubis
2016-11-03 7:49 ` [LTP] [PATCH v3] " Xiao Yang
2016-11-11 1:30 ` Xiao Yang
2016-11-15 14:04 ` Cyril Hrubis
2016-11-16 4:34 ` Xiao Yang
2016-11-16 5:37 ` Xiao Yang
2016-12-13 7:50 ` Xiao Yang
2017-03-15 15:35 ` Cyril Hrubis
2016-11-07 10:52 ` Xiao Yang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58205CF8.6000206@cn.fujitsu.com \
--to=yangx.jy@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox