From: linuxtestproject.agent@gmail.com
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] setsockopt10: Bind test sockets to any free port
Date: Mon, 20 Jul 2026 15:53:51 +0000 [thread overview]
Message-ID: <20260720155351.4024-1-linuxtestproject.agent@gmail.com> (raw)
In-Reply-To: <20260720140925.86664-1-mdoucha@suse.cz>
Hi Martin,
On Mon, Jul 20, 2026 at 16:09:22 +0200, Martin Doucha wrote:
> setsockopt10: Bind test sockets to any free port
> + tcp0_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
> + tcp1_sk = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
> SAFE_BIND(tcp0_sk, (struct sockaddr *)&tcp0_addr, sizeof(tcp0_addr));
> SAFE_BIND(tcp1_sk, (struct sockaddr *)&tcp1_addr, sizeof(tcp1_addr));
> - const pid_t child_pid = SAFE_FORK();
> + child_pid = SAFE_FORK();
>
> if (child_pid == 0) {
> child();
> return;
> }
>
> + addrlen = tst_get_connect_address(tcp0_sk, &sockaddr);
> + SAFE_CLOSE(tcp0_sk);
This moves tcp0_sk creation into run() before SAFE_FORK(), which means
the parent now holds a live fd in tcp0_sk when SAFE_CLOSE() is called
here.
SAFE_CLOSE() closes the fd but leaves the tcp0_sk variable unchanged.
In the original code, tcp0_sk was only assigned inside child(), in the
child process, so the parent's tcp0_sk was always 0 and cleanup() skipped
it. Now cleanup() sees tcp0_sk > 0 and calls SAFE_CLOSE() on an already
closed fd, causing EBADF and a TBROK on every test run.
Setting tcp0_sk = -1 (or 0) after the SAFE_CLOSE() here should fix it.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-07-20 15:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 14:09 [LTP] [PATCH] setsockopt10: Bind test sockets to any free port Martin Doucha
2026-07-20 15:53 ` linuxtestproject.agent [this message]
2026-07-20 17:42 ` [LTP] " Andrea Cervesato via ltp
2026-07-20 21:36 ` [LTP] [PATCH] " Petr Vorel
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=20260720155351.4024-1-linuxtestproject.agent@gmail.com \
--to=linuxtestproject.agent@gmail.com \
--cc=ltp@lists.linux.it \
--cc=mdoucha@suse.cz \
/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