Skip to content

Commit d94cbde

Browse files
Byte-LabAlexei Starovoitov
authored andcommitted
bpf/docs: Document how nested trusted fields may be defined
A prior change defined a new BTF_TYPE_SAFE_NESTED macro in the verifier which allows developers to specify when a pointee field in a struct type should inherit its parent pointer's trusted status. This patch updates the kfuncs documentation to specify this macro and how it can be used. Signed-off-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230125143816.721952-7-void@manifault.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent bdbda39 commit d94cbde

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Documentation/bpf/kfuncs.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ KF_ACQUIRE and KF_RET_NULL flags.
167167
The KF_TRUSTED_ARGS flag is used for kfuncs taking pointer arguments. It
168168
indicates that the all pointer arguments are valid, and that all pointers to
169169
BTF objects have been passed in their unmodified form (that is, at a zero
170-
offset, and without having been obtained from walking another pointer).
170+
offset, and without having been obtained from walking another pointer, with one
171+
exception described below).
171172

172173
There are two types of pointers to kernel objects which are considered "valid":
173174

@@ -180,6 +181,25 @@ KF_TRUSTED_ARGS kfuncs, and may have a non-zero offset.
180181
The definition of "valid" pointers is subject to change at any time, and has
181182
absolutely no ABI stability guarantees.
182183

184+
As mentioned above, a nested pointer obtained from walking a trusted pointer is
185+
no longer trusted, with one exception. If a struct type has a field that is
186+
guaranteed to be valid as long as its parent pointer is trusted, the
187+
``BTF_TYPE_SAFE_NESTED`` macro can be used to express that to the verifier as
188+
follows:
189+
190+
.. code-block:: c
191+
192+
BTF_TYPE_SAFE_NESTED(struct task_struct) {
193+
const cpumask_t *cpus_ptr;
194+
};
195+
196+
In other words, you must:
197+
198+
1. Wrap the trusted pointer type in the ``BTF_TYPE_SAFE_NESTED`` macro.
199+
200+
2. Specify the type and name of the trusted nested field. This field must match
201+
the field in the original type definition exactly.
202+
183203
2.4.6 KF_SLEEPABLE flag
184204
-----------------------
185205

0 commit comments

Comments
 (0)