Skip to content

Commit bc707f1

Browse files
sinkapqmonnet
authored andcommitted
bpf: Implement signature verification for BPF programs
This patch extends the BPF_PROG_LOAD command by adding three new fields to `union bpf_attr` in the user-space API: - signature: A pointer to the signature blob. - signature_size: The size of the signature blob. - keyring_id: The serial number of a loaded kernel keyring (e.g., the user or session keyring) containing the trusted public keys. When a BPF program is loaded with a signature, the kernel: 1. Retrieves the trusted keyring using the provided `keyring_id`. 2. Verifies the supplied signature against the BPF program's instruction buffer. 3. If the signature is valid and was generated by a key in the trusted keyring, the program load proceeds. 4. If no signature is provided, the load proceeds as before, allowing for backward compatibility. LSMs can chose to restrict unsigned programs and implement a security policy. 5. If signature verification fails for any reason, the program is not loaded. Tested-by: [email protected] Signed-off-by: KP Singh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 8ed27e2 commit bc707f1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,16 @@ union bpf_attr {
16111611
* continuous.
16121612
*/
16131613
__u32 fd_array_cnt;
1614+
/* Pointer to a buffer containing the signature of the BPF
1615+
* program.
1616+
*/
1617+
__aligned_u64 signature;
1618+
/* Size of the signature buffer in bytes. */
1619+
__u32 signature_size;
1620+
/* ID of the kernel keyring to be used for signature
1621+
* verification.
1622+
*/
1623+
__s32 keyring_id;
16141624
};
16151625

16161626
struct { /* anonymous struct used by BPF_OBJ_* commands */

0 commit comments

Comments
 (0)