Re: [PATCHv5 4/5] Allow setting O_NONBLOCK flag for new sockets

Eric Dumazet
2007-11-24T08:30:12Z

[-- Attachment #1: Type: text/plain, Size: 883 bytes --]

Ulrich Drepper a écrit :
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Eric Dumazet wrote:
>> 1) Can the fd passing with recvmsg() on AF_UNIX also gets O_CLOEXEC
>> support ?
>
> Already there, see MSG_CMSG_CLOEXEC.

OK, but maybe for consistency, we might accept the two mechanisms.

The one added in 2.6.23, and the more general indirect() way.

(See attached untested patch for the general idea, you'll have to also add
#if INDSYSCALL(recvmsg)
case INDSYSCALL(recvmsg):
#endif
)

>> 2) Why this O_NONBLOCK ability is needed for sockets ? Is it a security
>> issue, and if yes could you remind it to me ?
>
> No security issue. But look at any correct network program, all need to
> set the mode to non-blocking. Adding this support to the syscall comes
> at almost no cost and it cuts the cost for every program down by one or
> two syscalls.
>

OK, thank you.

[-- Attachment #2: scm.patch --]
[-- Type: text/plain, Size: 531 bytes --]

diff --git a/net/core/scm.c b/net/core/scm.c
index 100ba6d..38a0b77 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -230,11 +230,12 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
i++, cmfptr++)
{
int new_fd;
+ int flags = INDIRECT_PARAM(file_flags, flags) & O_CLOEXEC;
err = security_file_receive(fp[i]);
if (err)
break;
err = get_unused_fd_flags(MSG_CMSG_CLOEXEC & msg->msg_flags
- ? O_CLOEXEC : 0);
+ ? O_CLOEXEC : flags);
if (err < 0)
break;
new_fd = err;