Commit Graph

833 Commits

Author SHA1 Message Date
Tobias Klauser
6c3a3bfe00 unix: make convertFromDirents11 checkptr safe
Follow CL 202878 which did the same for package syscall.

Updates golang/go#35092

Change-Id: Id53d2cde0333581c98d13b096a48f2a602b2425f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202959
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-25 02:14:31 +00:00
Cuong Manh Le
b4ff53e7a1 unix: remove un-used ptrSize
Same as CL 202881.

Change-Id: Idc85bd23574c437c711b40155b49621e35ef571b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/203237
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-10-24 17:25:28 +00:00
Tobias Klauser
e66fe6eb8e unix: regenerate darwin libc trampolines after CL 202837
CL 202837 forgot to properly re-generate
zsyscall_darwin_{386,amd64,arm64}.s with the correct trampoline name.

Updates golang/go#35103
Updates golang/go#34133
Updates golang/go#35101

Change-Id: I98805988f97c7ff51da858fdc36c436aa680c8c7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202958
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-24 07:30:52 +00:00
Jason A. Donenfeld
f89234f9a2 unix: __sysctl is sysctl on darwin
While the other BSDs use __sysctl as the name, Darwin now uses sysctl,
without the leading underscores, and considers __sysctl to be "private".
Using __sysctl leads to App Store rejections, and Go's syscall package
already uses the proper syscall. So this commit changes Darwin's syscall
to use it too here, while reverting a recent commit that removed it all
together on arm and arm64.

This reverts CL 194097.

Fixes golang/go#35103
Updates golang/go#34133
Updates golang/go#35101

Change-Id: Ic72d5e7a435b99fe62c533b77b2c3790590f4c9e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202837
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-10-23 15:13:26 +00:00
Matt Layher
b69606af41 unix: comply with -d=checkptr in Test_anyToSockaddr
Rather than directly casting between types of different sizes, use an
explicit copy in a helper function.

Fixes golang/go#35106

Change-Id: I2293eb38fa53205ce069e2e5405262294c9ad412
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202820
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-23 14:50:28 +00:00
Jason A. Donenfeld
742c48ecae windows: respect permission bits on file opening
Chmod toggles the FILE_ATTRIBUTES_READONLY flag depending on the
permission bits. That's a bit odd but I guess some compromises were made
at some point and this is what was chosen to map to a Unix concept that
Windows doesn't really have in the same way. That's fine. However, the
logic used in Chmod was forgotten from Open, which then manifested
itself in various places, most recently, go modules' read-only behavior.

This corresonds with the syscall CL 202439.

Updates golang/go#35033

Change-Id: Id8e74c5205057a74a35eda213516780b79a2aed2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202440
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-10-22 10:09:44 +00:00
Tobias Klauser
3e7259c5e7 unix: don't use 32-bit aligned access for cmsgAlignOf on dragonfly after ABI change
Use 32-bit alignment for versions before the September 2019 ABI changes
http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html

Follows CL 201977 which did the same for package syscall.

Updates golang/go#34958

Change-Id: I0e13fccf6563e4d34dd4aa7410be044881f220aa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202179
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-20 21:24:54 +00:00
Tobias Klauser
9984515f05 windows, unix: fix wrong unsafe.Pointer alignment in syscall
Same as CL 201877 did for package syscall.

Updates golang/go#34972

Change-Id: I3929841ab32378516edafb1f02a84b1bdcc77bbd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/202177
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-20 15:20:52 +00:00
Tobias Klauser
727590c500 unix: avoid "just past the end" pointers in UnixRights
Same as CL 201617 did for package syscall.

Caught with -d=checkptr

Updates golang/go#22218

Change-Id: I8208f8e6d9bd62376bf9e0458dc18956daabd785
Reviewed-on: https://go-review.googlesource.com/c/sys/+/201937
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Elias Naur <mail@eliasnaur.com>
2019-10-18 09:52:05 +00:00
Takuto Ikuta
b09406accb windows: add GetDiskFreeSpaceEx function
ref:
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw

Change-Id: If57b0777106a2253e4287818d2c5aee2d6be13d3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/200257
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-10 19:43:22 +00:00
Lehner Florian
06d7bd2c5f unix: update rtnetlink constants
Change-Id: I21551672b5d8dd3e56c49da69f66dc19b07a5299
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199757
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-10-09 17:02:03 +00:00
Paulo Gomes
543471e840 unix: add new func PtraceInterrupt on Linux
Add to the unix package a new func to allow ptrace using PTRACE_INTERRUPT.

Fixes golang/go#34755

Change-Id: Ie50ae14c6eb5b3005dda2f8eefee57dd5bd6f360
GitHub-Last-Rev: 7e93ff4d87
GitHub-Pull-Request: golang/sys#45
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199504
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-10-08 10:56:21 +00:00
Jason A. Donenfeld
0b153f535c windows: fix ShellExecute return condition
ShellExecute is an ancient API with an unusual return signature. It
pretends to return an HINSTANCE for backwards compatibility with Windows
3, but it's actualy a fake HINSTANCE. What's really happening here,
according to MSDN, is that it returns either an Windows error less
than or equal to 32, or it succeeds. So we adjust the return value
accordingly.

Prior to this commit, it was impossible to tell whether this command had
succeeded. For example, when using the "runas" verb, ShellExecute did
not correctly indicate whether or not permission was granted.

Change-Id: Ie60554d6465798bacb9a225c4ead7e8dd62bce14
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199521
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nenad Kozul <knenad@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-10-08 10:27:50 +00:00
Jason A. Donenfeld
ef33b2fb2c windows: use go:linkname instead of assembly
This is a bit cleaner and makes it more explicit what's happening, along
with a documenting comment.

Change-Id: I30c92f8576c72b05ebdb4634c68023237bde3cbf
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199519
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-07 15:44:56 +00:00
Jason A. Donenfeld
5f54ce5427 windows: add module handle functions
These are in internal/syscall/windows, but not here, and they're quite
handy to have.

Change-Id: I79fe78d3c6bc2c001f994b03ce575287908d2c59
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199518
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-10-07 09:26:33 +00:00
Paulo Gomes
4ac5d0cebf unix: add new func PtraceSeize on Linux
Add to the unix package a new func to allow ptrace using PTRACE_SEIZE.

Fixes golang/go#34717

Change-Id: I6518868b99311a4608f21d249fe670990bfec555
GitHub-Last-Rev: 8a694c4f23
GitHub-Pull-Request: golang/sys#44
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199497
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-07 08:45:22 +00:00
Srinidhi Kaushik
aed5e4c7ec unix: add Klogset and related SYSLOG_ACTION_ constants
Adds a new function: Klogset which wraps sys_syslog for
cases where the `bufp` argument is not required and the
argument that follows needs to be passed to the function.

Fixes golang/go#34672

Change-Id: Idf026791ea9265aaca33e78a34fcd490edb8d326
Reviewed-on: https://go-review.googlesource.com/c/sys/+/199278
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-05 20:08:04 +00:00
Jason A. Donenfeld
c178f38b41 windows/mkwinsyscall: import mksyscall_windows.go from go repo
This allows us to modify this file and fix it more fluidly. Users can
invoke it from go generate via:

   go run golang.org/x/sys/windows/mkwinsyscall

This was taken from Go repo commit 6b85fa80.

Updates golang/go#34388

Change-Id: I8dc39eed96b2499ccbde53554b3e16e6c1f6aa98
Reviewed-on: https://go-review.googlesource.com/c/sys/+/198637
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-10-03 21:23:58 +00:00
Jason A. Donenfeld
b397fe3ad8 windows/svc: use CloseServiceHandle for service handles
From MSDN on CreateServiceW:

  The returned handle is only valid for the process that called
  CreateService. It can be closed by calling the CloseServiceHandle
  function.

This isn't an actual kernel object to be closed with CloseHandle.

Change-Id: Iee225a666576d57a6c4864abef20206d54cbbce2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/198298
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-10-02 09:15:54 +00:00
Tobias Klauser
3421d5a6bb unix: avoid __getdirentries64 on darwin
Getdirentries is implemented with the __getdirentries64 function
in libSystem.dylib on darwin/{386,amd64}. That function can't be used in
an app store application.

Implement Getdirentries using the underlying
fdopendir/readdir_r/closedir for Go 1.13. The simulation isn't faithful,
and could be slow, but it should handle common cases.

For Go 1.12, fall back to raw syscalls since syscall.syscallPtr needed
to use fdopendir from libSystem.dylib is not available.

Follow CL 168479 and CL 170892 which did the same for syscall in the
stdlib.

Tested on darwin/amd64 with Go 1.11, Go 1.12 and Go 1.13

Fixes golang/go#34400

Change-Id: I631382aaea9ee7e0c4ed09e06ad5427efc620769
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196478
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-10-02 06:39:06 +00:00
Tobias Klauser
34b0ac8f0d unix: update openbsd/{386,amd64.arm} MAP_* consts
Update the MAP_* consts for openbsd/{386,amd64.arm} on OpenBSD 6.5.
openbsd/arm64 was already generated on OpenBSD 6.5 for CL 173678.

Fixes golang/go#34589

Change-Id: Ie06bdc28ddd39a8c8e4f61137cb060f74c59e1eb
Reviewed-on: https://go-review.googlesource.com/c/sys/+/198157
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-10-02 06:38:49 +00:00
Jay Conrod
bb3f8db39f windows: add LockFileEx, UnlockFileEx system calls
Changes in syscall_windows.go were copied from
internal/syscall/syscall_windows.go.

zsyscall_windows.go was regenerated by running
'go generate -tags=generate golang.org/x/sys/windows'
using a toolchain built from tip (after CL 196122).

These functions are called by cmd/go/internal/lockedfile via
internal/syscall/windows. I'd like to copy lockedfile into another
project (CL 197299), but these functions need to be exposed here in
order to do so. We may need these in x/mod eventually, too.

Change-Id: I2033106d2ba65009e764591bfe5702f4d41dffdd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/198060
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-10-01 15:17:50 +00:00
John Papandriopoulos
c990c680b6 cpu: support ARM feature detection on Linux
Updates golang/go#33508

Change-Id: I9ea01090f5b4ac95c1a14881c305461bd4a7b5dd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/190525
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2019-09-27 07:32:44 +00:00
Brad Fitzpatrick
855e68c859 windows: revert breaking API changes from CL 196798, add new accessor funcs
CL 196798 changed API and broke a number of projects.

Revert the signature changes but add new convenience functions instead.

Change-Id: I49e389204f4756ec054ba8fd7555e235ef6370e8
Reviewed-on: https://go-review.googlesource.com/c/sys/+/197597
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-09-26 18:03:25 +00:00
Tobias Klauser
2837fb4f24 unix: add NFDBITS const on Linux, update TestSelect
Adjust TestSelect on Linux to match the Darwin/*BSD changes in CL
196802.

Updates golang/go#34458

Change-Id: Ia17fdadf7091001ea785391da23aaf9d3ec4ac5e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196806
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-24 15:45:21 +00:00
Tobias Klauser
e2fefa8ec2 unix: fix Select to return number of ready fds on Solaris
Make Select's signature on Solaris match the one on Linux and return the number
of ready file descriptors.

Updates golang/go#34458

Change-Id: I118c4c35cbc83dba015ef357ce9bef44c9165ec1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196807
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-24 15:45:09 +00:00
Tobias Klauser
2f72d4f062 unix: re-generate Select on dragonfly
CL 196802 did not properly re-generate the definition of Select after
changing the //sys comment.

Updates golang/go#34458

Change-Id: I035468487163f48393fc777dde691737fce41aa8
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196805
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-24 13:54:25 +00:00
Jason A. Donenfeld
98129a5cf4 windows: use pseudo handle constants to implement GetCurrentProcess
There's no point in adding a function call to retrieve a constant, or
worse, a syscall to retrieve a constant. These are fixed and baked so
deep into NT they'll never change. So let's benefit from the obvious
optimization and make these constants. Go easily inlines the function
calls as well. We also take the opportunity to sunset
OpenCurrentProcessToken and restore its original behavior, since users
should be invoking this deliberately with the correct access mask.

Change-Id: I92f7de56c0fcf5b69b59f5a79d2828c7ddf3c8f6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196800
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-09-24 09:22:10 +00:00
Tobias Klauser
2aa67d56cd unix: fix Select to return number of ready fds on Darwin and *BSD
Make Select's signature on Darwin and the BSDs match the one on Linux
and return the number of ready file descriptors.

Fixes golang/go#34458

Change-Id: Ia618ce34ff754f2b731d7f913cab840d7948579c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196802
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-24 06:27:00 +00:00
Jason A. Donenfeld
0a153f010e windows: make SID.String() conform to the String interface
This function shouldn't return an error. Like other String() functions
everywhere in Golang, this should instead return empty or a token value
during an error, so that it can be passed to %v and similar. Also, allow
for SID strings of maximum size.

Change-Id: Ib6d8407f8ad0bdabcb22c31b8f387594f2ea7672
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196799
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-09-22 10:00:55 +00:00
Jason A. Donenfeld
2dccfee4fd windows: do not return invalid error for psuedo-handle functions
GetCurrentProcess and GetCurrentThread return -1 and -2 respectively. We
could arguably hard code those values, but MSDN cautions not to; I'm
sure this advice is old now, given that the psuedo handles for tokens
(not processes/threads) are now implemented with inline functions in the
headers for Windows 8, but anyway, we'll follow Microsoft's advice.
However, regardless of that, these functions never ever return an error.
MSDN doesn't indicate that they do, reverse engineering the functions
doesn't indicate that they do, and checking against 0 is just plain
wrong, considering 0!=INVALID_HANDLE_VALUE; however
INVALID_HANDLE_VALUE==-1, so that's not correct either. In fact,
checking any value and returning any error does not make sense.
Incidently having to check code for the pseudo handle is more verbose
too.

In order to make this function do the correct thing and meet the spec,
remove the error value from the return.

Change-Id: If03c9dab001be3bf5a04999aef20dbfcf8a4f405
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196798
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-09-21 20:48:32 +00:00
Jason A. Donenfeld
5c00192e8c windows: use correct type for security attributes' descriptor member
The SECURITY_ATTRIBUTES struct always takes a SECURITY_DESCRIPTOR
pointer. Now that we've defined SECURITY_DESCRIPTOR, make
SECURITY_ATTRIBUTES properly specify the type. This eliminates the need
for terrible uintptr(unsafe.Pointer(...)) casts everywhere.

Change-Id: Ibbc85524cfe33589d43f963e10aa19d7f47686f2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196797
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-09-21 20:48:12 +00:00
Jason A. Donenfeld
14da1ac737 windows: support SECURITY_DESCRIPTOR and ACL for secured objects
This adds the basic foundation for dealing with security descriptors and
access control lists. The basic creators and getters are included in
this patch. These are some of the most fundamental security objects on NT,
and any work with the security API is fairly limited without it. These
are "core" NT structures.

Change-Id: I9a6399cb6ee41a825de30d5364ab69102d5f6d57
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195498
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-09-21 19:09:40 +00:00
Eric Chiang
ef0ce17483 unix: add KEYCTL_RESTRICT_KEYRING capabilities
Asymmetric keyrings can require key payloads to be X.509 certificates
signed by a key in a different keyring. This can be helpful for rotating
keys on a live machines for subsystems like IMA while preventing local
tampering.

Tested locally by applying the "key_or_keyring:<id>" restriction to a
keyring.

Change-Id: Ia8dcb343abc5f405d374c357d5cac3d5181d7159
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178400
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-09-20 19:08:10 +00:00
Jason A. Donenfeld
0c1ff786ef windows: do not corrupt stack with larger boolean return value
Windows type PBOOL is a pointer to a 4 byte value, where 0 means false
and not-0 means true. That means we should use uint32 here, not bool,
since Go bools can be 1 byte. This commit was re-generated using
mksyscall_windows.go from CL 196122.

Updates: golang/go#34364
Change-Id: I8e83b9a09c0b58d14ac9a7dee316553940ac6ee3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/196123
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-09-19 04:47:23 +00:00
Matt Layher
b4ddaad3f8 unix: redefine TIPC_WAIT_FOREVER as a uint32 value
The code generator produces -0x1 for (~0) from the tipc.h C header, but this
value is unusable in Go as a uint32. Undefine and replace this value with
the appropriate constant for TIPC_WAIT_FOREVER.

Fixes golang/go#34310

Change-Id: Ic6ab0ddd14394e15868085e2123a9a97a841bc6d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195757
Run-TryBot: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-16 20:23:48 +00:00
Jason A. Donenfeld
8a69140bde windows: add various functions for shutting down and logging out
There are a few functions to control the behavior of shutdown and
logout, both for what the current process does during shutdown, and also
whether or not the current process is running in an interactive session.
The below code is a port of the MSDN example code to Go using one of the
added new functions:

https://docs.microsoft.com/en-us/windows/win32/shutdown/how-to-shut-down-the-system

func shutdownLikeMSDNDoes() error {
  seShutdownName, err := windows.UTF16PtrFromString("SeShutdownPrivilege")
  if err != nil {
    return err
  }

  var shutdownPriv windows.Tokenprivileges
  err = windows.LookupPrivilegeValue(nil, seShutdownName, &shutdownPriv.Privileges[0].Luid)
  if err != nil {
    return err
  }
  shutdownPriv.Privileges[0].Attributes = windows.SE_PRIVILEGE_ENABLED
  shutdownPriv.PrivilegeCount = 1

  process, err := windows.GetCurrentProcess()
  if err != nil {
    return err
  }
  var token windows.Token
  err = windows.OpenProcessToken(process, windows.TOKEN_ADJUST_PRIVILEGES | windows.TOKEN_QUERY, &token)
  if err != nil {
    return err
  }
  defer token.Close()

  err = windows.AdjustTokenPrivileges(token, false, &shutdownPriv, 0, nil, nil)
  if err != nil {
    return err
  }

  err = windows.ExitWindowsEx(windows.EWX_SHUTDOWN | windows.EWX_FORCE,
    windows.SHTDN_REASON_MAJOR_OPERATINGSYSTEM | windows.SHTDN_REASON_MINOR_UPGRADE | windows.SHTDN_REASON_FLAG_PLANNED)
  if err != nil {
    return err
  }

  return nil
}

Note, though, that this function doesn't set the token privs back to how
they were before, which isn't good. A more robust method than the MSDN
one above would be to duplicate&impersonate.

Fixes: golang/go#34271
Change-Id: Ibe55ddd35b709d9ab793cb9af47c39901c5e5c69
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195497
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bruce Downs <bruceadowns@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-09-16 16:59:10 +00:00
Tobias Klauser
1a3b71a79e unix: update Dockerfile to Linux 5.3 and use ubuntu 19.04 base image
rsync needs to be explicitly installed for 'make headers_install' to
work.

Change-Id: Icd3d6b3f004a7684b5ae32b4b7cab8d50631900d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195258
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-16 14:18:54 +00:00
Tobias Klauser
c3b328c6e5 unix: add IfaCacheinfo on linux
Change-Id: Ifda2eed10f75eeddff7720676fd0a5feee78a7a5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195257
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-13 12:16:21 +00:00
Tobias Klauser
bc967efca4 unix: sort Linux-specific includes in linux/types.go and mkerrors.sh
Keep the list of includes sorted, so that it's clear where to add new
entries and to avoid duplicates being added.

Change-Id: I67bd8b5a4e4b40affcad636dccfceef2460158b1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/195017
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2019-09-12 14:19:32 +00:00
Brad Fitzpatrick
7ad0cfa0b7 cpu: remove encoding/binary dependency
It's unnecessarily heavy, bringing in reflect, etc.

I'd like for this package to become a leaf package with no
dependencies so we can use it from the Go runtime directly and remove
internal/cpu.

Change-Id: I1794854add9ad87cc13b685bae4a039e1449c22d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/194646
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2019-09-11 20:15:28 +00:00
Tobias Klauser
bbd175535a unix: add Msghdr.SetIovlen for solaris/amd64
Follow-up for CL 194077

Updates golang/go#34164

Change-Id: I4bf670dc3e13c483e9087dc3f04973278a09b2f4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/194099
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-10 06:45:55 +00:00
andig
f460065e89 unix: add Msghdr.SetIovlen
Fixes golang/go#34164

Change-Id: I77e634fafe8e573d5d2c65ddae9b0771c9f3e88f
GitHub-Last-Rev: dd25f06f86
GitHub-Pull-Request: golang/sys#42
Reviewed-on: https://go-review.googlesource.com/c/sys/+/194077
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-09-09 08:27:30 +00:00
Elias Naur
d223b2b6db unix: disable sysctl on iOS
Running the regenerating scripts also brought in ClockGettime.

Updates golang/go#34133

Change-Id: I0eb9ed6dbbc2bdd7e3d2a7f5d88492e9dfed0ada
Reviewed-on: https://go-review.googlesource.com/c/sys/+/194097
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-09-07 18:44:12 +00:00
Tobias Klauser
749cb33bea cpu: add a space before build tag comment
Add a space before build tag comments so it corresponds to the format
documented at https://golang.org/pkg/go/build/.

Change-Id: Ia7c724daf70d419dec52a652188799441053a867
Reviewed-on: https://go-review.googlesource.com/c/sys/+/193198
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-04 15:47:56 +00:00
Matt Layher
43c01164e9 unix: implement AF_TIPC sockets on Linux
Adds initial constants and types to use with SockaddrTIPC. For more
information on TIPC, see: http://tipc.sourceforge.net/.

Because the C struct sockaddr_tipc makes use of a union for its addr
field, I have created a wrapping layer in SockaddrTIPC that uses
an interface to determine which variant is in use.

Tests accompany this change due to the complexity of this code. There
is currently little test coverage in the Sockaddr-related code, but
perhaps this is something that could be picked up as a relatively
straightforward task for a new contributor.

Change-Id: I5033a0685cb7128d4b1a23d18aca71c202d0c0aa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/187960
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-09-04 00:50:37 +00:00
Matt Layher
1f305c863d unix/linux: upgrade Docker build container to Go 1.13
Change-Id: I1f47efb573ff3fa77afd9d1433726a908008c27d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/193119
Run-TryBot: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-03 21:38:30 +00:00
Kir Kolyshkin
9109b7679e unix: add IoctlRetInt for Linux
Add IoctlRetInt() for ioctls that use syscall's return value
as an output parameter. Add a unit test for Linux, and the
NS_GET_ defines that it requires (see ioctl_ns(2)).

Motivation:

Currently, x/sys/unix provides a few functions to deal with ioctls.
In particular, IoctlGetInt(), which "performs an ioctl operation
which gets an integer value". It does that by passing a pointer
to an integer to a syscall and returning that integer. The value
returned from syscall is treated as success/failure flag
(0 means success, -1 means failure, and in such case errno
is used to figure out the underlying error).

It appears that there are a few ioctls in Linux and at least one
in Solaris, which do not use the above way to return an int, instead
they use the syscall's return value (in case it's not negative).

As Linux ioctl(2) man page says,

> RETURN VALUE
> Usually, on success zero is returned. A few ioctl() requests
> use the return value as an output parameter and return
> a nonnegative value on success. On error, -1 is returned,
> and errno is set appropriately.

Currently I am aware of at least 6 Linux ioctls that do that
(return the value directly):

* LOOP_CTL_* ioctls on /dev/loop-control (all 3 of them). Source: loop(4)
* NS_* ioctls (3 out of 4) on /proc/PID/ns/*. Source: ioctl_ns(2)

And one in Solaris:

* I_FIND ioctl, source: streamio(7i).

There might be some more ioctls like the ones above, but since
ioctls are scarcely documented, it is hard to say how many more.

Obviously, using IoctlGetInt() for such ioctls would be a big
mistake, as 0 will always be returned. For example, there was
a bug in Docker's pkg/loopback (moby/moby#39801).

[v6: make it linux-specific for now]

Fixes golang/go#33966

Change-Id: Ie64f72fd84101b955ba14519a357e06a66d685d0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/192780
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-09-02 13:37:55 +00:00
Clément Chigot
1e83adbbeb unix: fix coredump bit on aix/ppc64
Change-Id: Id7a299f240bf1d6394c7d2acb6fd93b9f8f6ca27
Reviewed-on: https://go-review.googlesource.com/c/sys/+/192359
Run-TryBot: Clément Chigot <clement.chigot@atos.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-08-30 14:29:57 +00:00
Jason A. Donenfeld
acfa387b8d windows: open process tokens with duplicate access
A usual thing to ask is, "Is my current token in group X?" The right way
of doing such a thing is:

	processToken, err := windows.OpenCurrentProcessToken()
	if err != nil {
		return false, err
	}
	defer processToken.Close()
	var checkableToken windows.Token
	err = windows.DuplicateTokenEx(token, windows.TOKEN_QUERY | windows.TOKEN_IMPERSONATE, nil, windows.SecurityIdentification, windows.TokenImpersonation, &checkableToken)
	if err != nil {
		return false, err
	}
	defer checkableToken.Close()
	isMember, err := checkableToken.IsMember(someSID)
	return isMember && err == nil, nil

This is the same flow that's used by, for example, shell32's internal
_LUAIsTokenAdmin function.

However, this all fails unless the original token is opened with
duplicate access. So this commit adjusts OpenCurrentProcessToken to do
the right thing.

Change-Id: I18efdfde43097ea9d10758018b0df132fba819f5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/192337
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Simon Rozman <simon@rozman.si>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-08-30 14:18:01 +00:00