Commit Graph

19168 Commits

Author SHA1 Message Date
Michael Kerrisk 71c2db6a65 mmap.2: Further wording tweaks to the discussion of MAP_FIXED hazards
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 09:39:03 +02:00
Michael Kerrisk 2256fc0887 mmap.2: Minor wording fix
Change "extremely hazardous" to "hazardous". The former phrasing
is a little overwrought; on its own "hazardous" is enough to
convey the sense of danger.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:53:06 +02:00
Michael Kerrisk 56a033affa mmap.2: Minor wording fixes to to text describing MAP_FIXED hazards
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:50:38 +02:00
Michael Kerrisk fd859eb599 mmap.2: Simplify mention of MAP_FIXED_NOREPLACE in the discussion of MAP_FIXED
After discussions with Jann Horn and John Hubbard.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:44:24 +02:00
Michael Kerrisk 528cc762d9 mmap.2: wfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:38:50 +02:00
Michael Kerrisk a8fd340325 mmap.2: wfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:23:14 +02:00
Michael Kerrisk a6bf8e7e94 mmap.2: tfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:21:41 +02:00
Michael Kerrisk 08a239f387 mmap.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-13 08:21:41 +02:00
Jann Horn da6ad3cd89 mmap.2: MAP_FIXED is okay if the address range has been reserved
Clarify that MAP_FIXED is appropriate if the specified address
range has been reserved using an existing mapping, but shouldn't
be used otherwise.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 20:25:58 +02:00
Michael Kerrisk 5bc2d858e1 mmap.2: Clarify rationale of MAP_SYNC somewhat
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 20:18:58 +02:00
Michael Kerrisk 79da08c844 mmap.2: Minor tweaks to Jan Kara's patch
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 14:55:43 +02:00
Michael Kerrisk b138773b1e mmap.2: srcfix: rewrap source lines
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 14:50:28 +02:00
Jan Kara d8aeb42ded mmap.2: Add description of MAP_SHARED_VALIDATE and MAP_SYNC
Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 14:37:00 +02:00
Michael Kerrisk 40b7acf14d getcwd.3: Minor tweaks to Carlos O'Donell's patch
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:49:40 +02:00
Michael Kerrisk c26d16c8de getcwd.3: srcfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:47:03 +02:00
Carlos O'Donell 294851f3fa getcwd.3: Mention that "(unreachable)" is no longer returned for glibc >= 2.27.
With glibc fix 52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94 for
CVE-2018-1000001 (Sourceware BZ #22679) the implementation in the
just released glibc 2.27 has been changed such that instead of
returning "(unreachable)" the implementation now returns ENOENT
as it would have if the current directory had been unlinked.

I see that in 2015 the quirk was documented in commit
a2ac97c78b, and this is no longer
true with glibc 2.27, but may continue to be true in other C libraries,
so I reference NOTES from the paragraph in the central text.

Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:44:51 +02:00
Michael Kerrisk 46dc0687e4 membarrier.2: wfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:37:28 +02:00
Michael Kerrisk 1afb17b76e membarrier.2: ffix code example
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:33:51 +02:00
Michael Kerrisk d8b2fd50e1 membarrier.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:33:51 +02:00
Michael Kerrisk e8edc8917c membarrier.2: Some wording improvements
I'll pass these to Mathieu Desnoyers for checking

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:32:51 +02:00
Michael Kerrisk 13d4ca14fa membarrier.2: Minor tweaks to Mathieu Desnoyers' patch
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:12:18 +02:00
Michael Kerrisk 26fac2d02f membarrier.2: Add kernel version for MEMBARRIER_CMD_QUERY and MEMBARRIER_CMD_SHARED
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:06:30 +02:00
Michael Kerrisk 7fb5be1530 membarrier.2: Minor tweaks to MEMBARRIER_CMD_SHARED text
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:06:30 +02:00
Michael Kerrisk 988a9c360d membarrier.2: tfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:06:30 +02:00
Michael Kerrisk 8fb5a3b5b2 membarrier.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:06:30 +02:00
Michael Kerrisk 8d23228ca6 membarrier.2: srcfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:06:30 +02:00
Mathieu Desnoyers f5a563c0c4 membarrier.2: Document new membarrier commands introduced in Linux 4.16
Document the following membarrier commands introduced in
Linux 4.16:

    MEMBARRIER_CMD_GLOBAL_EXPEDITED
        (the old enum label MEMBARRIER_CMD_SHARED is now an
        alias to preserve header backward compatibility)
    MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED
    MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
    MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Michael Kerrisk <mtk.manpages@gmail.com>
CC: Ingo Molnar <mingo@redhat.com>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 13:06:24 +02:00
Michael Kerrisk 2f72816f86 io_submit.2: Add kernel version numbers for various 'aio_rw_flags' flags
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 11:19:39 +02:00
Michael Kerrisk 21487837da readv.2: wfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 11:10:41 +02:00
Michael Kerrisk df5507b137 readv.2: Remove redundant sentence
The sentence is out of place, and probably doesn't really add to
the understanding already provided by the rest of the text

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 11:09:33 +02:00
Michael Kerrisk a6b64be7b1 readv.2: srcfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 11:09:23 +02:00
Michael Kerrisk 9d2d82ffe2 io_submit.2: Place 'aio_rw_flags' in alphabetical order
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 11:08:22 +02:00
Michael Kerrisk c00234733f io_submit.2: srcfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 11:06:12 +02:00
Jürg Billeter 7ac27e31b0 readv.2, io_submit.2: Document RWF_APPEND added in Linux 4.16
Signed-off-by: Jürg Billeter <j@bitron.ch>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:59:43 +02:00
Michael Kerrisk 7934bcdfdc unix.7: ERRORS: add EBADF for sending closed file descriptor with SCM_RIGHTS
As noted by Rusty Russell:

I was really surprised that sendmsg() returned EBADF on a valid fd;
turns out I was using sendmsg with SCM_RIGHTS to send a closed fd,
which gives EBADF (see test program below).

But this is only obliquely referenced in unix(7):

       SCM_RIGHTS
              Send or receive a set  of  open  file  descriptors
              from  another  process.  The data portion contains
              an integer array of  the  file  descriptors.   The
              passed file descriptors behave as though they have
              been created with dup(2).

EBADF is not mentioned in the unix(7) ERRORS (it's mentioned in
dup(2)).

int fdpass_send(int sockout, int fd)
{
	/* From the cmsg(3) manpage: */
	struct msghdr msg = { 0 };
	struct cmsghdr *cmsg;
	struct iovec iov;
	char c = 0;
	union {         /* Ancillary data buffer, wrapped in a union
			   in order to ensure it is suitably aligned */
		char buf[CMSG_SPACE(sizeof(fd))];
		struct cmsghdr align;
	} u;

	msg.msg_control = u.buf;
	msg.msg_controllen = sizeof(u.buf);
	memset(&u, 0, sizeof(u));
	cmsg = CMSG_FIRSTHDR(&msg);
	cmsg->cmsg_level = SOL_SOCKET;
	cmsg->cmsg_type = SCM_RIGHTS;
	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
	memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));

	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	msg.msg_flags = 0;

	/* Keith Packard reports that 0-length sends don't work, so we
	 * always send 1 byte. */
	iov.iov_base = &c;
	iov.iov_len = 1;

	return sendmsg(sockout, &msg, 0);
}

int fdpass_recv(int sockin)
{
	/* From the cmsg(3) manpage: */
	struct msghdr msg = { 0 };
	struct cmsghdr *cmsg;
	struct iovec iov;
	int fd;
	char c;
	union {         /* Ancillary data buffer, wrapped in a union
			   in order to ensure it is suitably aligned */
		char buf[CMSG_SPACE(sizeof(fd))];
		struct cmsghdr align;
	} u;

	msg.msg_control = u.buf;
	msg.msg_controllen = sizeof(u.buf);

	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	msg.msg_iov = &iov;
	msg.msg_iovlen = 1;
	msg.msg_flags = 0;

	iov.iov_base = &c;
	iov.iov_len = 1;

	if (recvmsg(sockin, &msg, 0) < 0)
		return -1;

	cmsg = CMSG_FIRSTHDR(&msg);
        if (!cmsg
	    || cmsg->cmsg_len != CMSG_LEN(sizeof(fd))
	    || cmsg->cmsg_level != SOL_SOCKET
	    || cmsg->cmsg_type != SCM_RIGHTS) {
		errno = -EINVAL;
		return -1;
	}

	memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd));
	return fd;
}

static void child(int sockfd)
{
	int newfd = fdpass_recv(sockfd);
	assert(newfd < 0);
	exit(0);
}

int main(void)
{
	int sv[2];
	int pid, ret;

	assert(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);

	pid = fork();
	if (pid == 0) {
		close(sv[1]);
		child(sv[0]);
	}

	close(sv[0]);
	ret = fdpass_send(sv[1], sv[0]);
	printf("fdpass of bad fd return %i (%s)\n", ret, strerror(errno));
	return 0;
}

Reported-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:55:29 +02:00
Michael Kerrisk d3e7786def unix.7: wfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:42:34 +02:00
Michael Kerrisk 6170a241ea perf_event_open.2: Minor tweak to Song Liu's kprobe/uprobe patch: fix kernel version
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:24:19 +02:00
Michael Kerrisk c87e72a27c perf_event_open.2: Minor tweaks to Song Liu's patch
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:24:19 +02:00
Song Liu 7d8449ba19 perf_event_open.2: Add type kprobe and uprobe
Two new types kprobe and uprobe are being added to
perf_event_open(), which allow creating kprobe or
uprobe with perf_event_open. This patch adds
information about these types.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:24:19 +02:00
Michael Kerrisk 95b9ecbf9d mmap.2: Explicitly mention MAP_FIXED_NOREPLACE in EEXIST description
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:08:17 +02:00
Michael Kerrisk 421508eba8 mmap.2: Minor wording fix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk a7a21482a1 mmap.2: Add a little historical detail on the obsolete MAP_DENYWRITE
In Linux 2..0, do_mmap() had the following check:

                if (flags & MAP_DENYWRITE) {
                        if (file->f_inode->i_writecount > 0)
                                return -ETXTBSY;
                }

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk 0113b28739 mmap.2: Minor rewording of MAP_FIXED text
The paragraph break-up of the existing text was
somewhat unnatural.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk 73cb50e21b mmap.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk 3a548c59d9 mmap.2: Minor tweaks to Michal Hocko's patch
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk 509935b7de mmap.2: tfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk 007d7833b0 mmap.2: srcfix: rewrap source lines
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michael Kerrisk 228d889fc7 mmap.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:03:04 +02:00
Michal Hocko c6a51c0645 mmap.2: Document new MAP_FIXED_NOREPLACE flag
4.17+ kernels offer a new MAP_FIXED_NOREPLACE flag which allows
the caller to atomically probe for a given address range.

[wording heavily updated by John Hubbard]

Cowritten-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 10:02:58 +02:00
Konstantin Grinemayer 04c8a02088 keyring.7: wfix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-04-12 08:46:42 +02:00