Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: add Send on Linux #47288

Closed
dandare100 opened this issue Jul 19, 2021 · 8 comments
Closed

x/sys/unix: add Send on Linux #47288

dandare100 opened this issue Jul 19, 2021 · 8 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dandare100
Copy link

go version go1.16.5 linux/amd64

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

Hello

https://man7.org/linux/man-pages/man2/sendto.2.html refers.

I cannot find a syscall func in the sys/unix package for

ssize_t send(int sockfd, const void *buf, size_t len, int flags);

The good news is that there is one for

ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);

It looks like the sendto syscall in linux allows the sockaddr to be NULL and its accompanying length to be 0 for connections in a connected state. (because the destination is known)

The above documentation mentions that the following call
send(sockfd, buf, len, flags);
is equivalent to
sendto(sockfd, buf, len, flags, NULL, 0);

The current implementation of
func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error)
in
syscall_unix.go
has code that relies on "to Sockaddr" not being nil and a "nil pointer dereference" occurs if a nil is passed.
There could be cases where "to Sockaddr" can be nil to achieve a "send"

Would it be worthwhile modifying this function to allow for a nil "to" (leaving the current non nil behaviour intact) and letting the call reach the kernel (like the equivalent example above) ?

I have done a quick test and it works as predicted.

@gopherbot gopherbot added this to the Unreleased milestone Jul 19, 2021
@thanm
Copy link
Contributor

thanm commented Jul 19, 2021

per owners: @ianlancetaylor @bradfitz @tklauser

@ianlancetaylor
Copy link
Contributor

Note that this issue is about the x/sys/unix package.

I don't see a problem with adding Send to x/sys/unix. I don't see a reason to add special treatment for SendTo.

@thanm
Copy link
Contributor

thanm commented Jul 19, 2021

Note that this issue is about the x/sys/unix package.

Right, sorry for the confusion. I'll edit my comment.

@dandare100 dandare100 changed the title x/sys/unix: allow nil for "to Sockaddr" parameter in func Sendto on Linux x/sys/unix: add Send on Linux Jul 20, 2021
@dandare100
Copy link
Author

I understand and agree. Send will work perfectly and no need to change SendTo

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 20, 2021
@dandare100
Copy link
Author

I just want to check in with some observations and request some advice before submitting to gerrit please :

It seems like "send" is not included because the implementation of makeZSysnumFile() in mkall.go only parses asm/unistd.h for linux.

This does not have "send", it only has

#define __NR_sendto 44  
#define __NR_sendmsg 46  
#define __NR_sendmmsg 307  

which seems strange(the fact that it has "sendto" and others that are already covered by this go package)

The only place I can find a reference to "send(2)" is in linux/net.h, which has

#define SYS_SEND	9		/* sys_send(2)			*/
#define SYS_SENDTO	11		/* sys_sendto(2)		*/
#define SYS_SENDMSG	16		/* sys_sendmsg(2)		*/
#define SYS_SENDMMSG	20		/* sys_sendmmsg(2)		*/

So in summary what I am asking is :

asm/unistd.h does not contain the send syscall I wish to add but it seems net.h contains all of the send calls.

What is the recommended way forward ?

@ianlancetaylor
Copy link
Contributor

Write a Send function that calls the sendto system call. I assume that that is what the C library does.

@dandare100
Copy link
Author

You are correct, thank you.


SYSCALL_DEFINE4(send, int, fd, void __user *, buff, size_t, len,
		unsigned int, flags)
{
	return __sys_sendto(fd, buff, len, flags, NULL, 0);
}

@gopherbot
Copy link

Change https://golang.org/cl/336569 mentions this issue: unix: add Send on Linux

@golang golang locked and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants