1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
.\" $OpenBSD: kbind.2,v 1.1 2015/08/25 19:58:04 guenther Exp $
.\"
.\" Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: August 25 2015 $
.Dt KBIND 2
.Os
.Sh NAME
.Nm kbind
.Nd update protected memory for lazy-binding
.Sh SYNOPSIS
.In sys/unistd.h
.Bd -literal
struct __kbind {
void *kb_addr;
size_t kb_size;
};
#define KBIND_BLOCK_MAX 2 /* powerpc, sparc, and sparc64 need 2 blocks */
#define KBIND_DATA_MAX 24 /* sparc64 needs 6, four-byte words */
.Ed
.Pp
.Ft int
.Fn kbind "const struct __kbind *param" "size_t psize" "int64_t cookie"
.Sh DESCRIPTION
The
.Nm
syscall updates the contents of one or more blocks of the process's memory
with the supplied replacement data.
This is used to efficiently and securely perform lazy-binding.
.Pp
.Fa param
points to an array of
.Vt __kbind
structures giving the addresses and lengths to update.
The last
.Vt __kbind
structure is immediately followed in the same order by the source
data for the blocks to copy.
.Fa psize
specifies the total length of the parameters: both the
.Vt __kbind
structures and the associated source data.
There may be at most
.Dv KBIND_BLOCK_MAX
.Vt __kbind
structures and each block may be at most
.Dv KBIND_DATA_MAX
bytes in size.
.Pp
.Nm
updates memory
.Do
as if
.Dc
the thread temporarily made the memory writable with
.Xr mprotect 2 .
If the process does not have write access to the underlying memory object,
.Nm
will fail without making the requested change.
.Pp
.Nm
is currently intended for use by
.Xr ld.so 1
only.
It is therefore not provided as a function and two security checks
are performed to bind it (pun intended) to its use in
.Xr ld.so 1 :
the first time
.Nm
is used, the kernel records both the text address of the call and
the value of the
.Fa cookie
argument.
If those values differ in a latter
.Nm
call, then the process is killed.
.Sh RETURN VALUES
.Rv -std
.Sh ERRORS
.Fn kbind
will fail if:
.Bl -tag -width Er
.It Bq Er ENOMEM
Cannot allocate memory when updating a copy-on-write page.
.It Bq Er EINVAL
The parameters are inconsistent or exceed
.Nm
limits.
.It Bq Er EFAULT
Part of the structures or additional data pointed to by
.Fa param
is outside the process's allocated address space,
or the underlying memory object is not writable.
.El
.Sh SEE ALSO
.Xr ld.so 1 ,
.Xr mprotect 2
.Sh STANDARDS
The
.Nm
syscall is specific to the
.Ox
dynamic linker and should not be used in portable applications.
.Sh HISTORY
The
.Nm
syscall appeared in
.Ox 5.8 .
|