Skip to content

Commit 55e8532

Browse files
committed
lsm: move the bpf hook comments to security/security.c
This patch relocates the LSM hook function comments to the function definitions, in keeping with the current kernel conventions. This should make the hook descriptions more easily discoverable and easier to maintain. While formatting changes have been done to better fit the kernel-doc style, content changes have been kept to a minimum and limited to text which was obviously incorrect and/or outdated. It is expected the future patches will improve the quality of the function header comments. Acked-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent b14faf9 commit 55e8532

2 files changed

Lines changed: 65 additions & 36 deletions

File tree

include/linux/lsm_hooks.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -190,42 +190,6 @@
190190
* @key: The key to watch.
191191
* Return 0 if permission is granted.
192192
*
193-
* Security hooks for using the eBPF maps and programs functionalities through
194-
* eBPF syscalls.
195-
*
196-
* @bpf:
197-
* Do a initial check for all bpf syscalls after the attribute is copied
198-
* into the kernel. The actual security module can implement their own
199-
* rules to check the specific cmd they need.
200-
* Return 0 if permission is granted.
201-
*
202-
* @bpf_map:
203-
* Do a check when the kernel generate and return a file descriptor for
204-
* eBPF maps.
205-
* @map: bpf map that we want to access.
206-
* @mask: the access flags.
207-
* Return 0 if permission is granted.
208-
*
209-
* @bpf_prog:
210-
* Do a check when the kernel generate and return a file descriptor for
211-
* eBPF programs.
212-
* @prog: bpf prog that userspace want to use.
213-
* Return 0 if permission is granted.
214-
*
215-
* @bpf_map_alloc_security:
216-
* Initialize the security field inside bpf map.
217-
* Return 0 on success, error on failure.
218-
*
219-
* @bpf_map_free_security:
220-
* Clean up the security information stored inside bpf map.
221-
*
222-
* @bpf_prog_alloc_security:
223-
* Initialize the security field inside bpf program.
224-
* Return 0 on success, error on failure.
225-
*
226-
* @bpf_prog_free_security:
227-
* Clean up the security information stored inside bpf prog.
228-
*
229193
* @locked_down:
230194
* Determine whether a kernel feature that potentially enables arbitrary
231195
* code execution in kernel space should be permitted.

security/security.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4825,30 +4825,95 @@ int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule)
48254825
#endif /* CONFIG_AUDIT */
48264826

48274827
#ifdef CONFIG_BPF_SYSCALL
4828+
/**
4829+
* security_bpf() - Check if the bpf syscall operation is allowed
4830+
* @cmd: command
4831+
* @attr: bpf attribute
4832+
* @size: size
4833+
*
4834+
* Do a initial check for all bpf syscalls after the attribute is copied into
4835+
* the kernel. The actual security module can implement their own rules to
4836+
* check the specific cmd they need.
4837+
*
4838+
* Return: Returns 0 if permission is granted.
4839+
*/
48284840
int security_bpf(int cmd, union bpf_attr *attr, unsigned int size)
48294841
{
48304842
return call_int_hook(bpf, 0, cmd, attr, size);
48314843
}
4844+
4845+
/**
4846+
* security_bpf_map() - Check if access to a bpf map is allowed
4847+
* @map: bpf map
4848+
* @fmode: mode
4849+
*
4850+
* Do a check when the kernel generates and returns a file descriptor for eBPF
4851+
* maps.
4852+
*
4853+
* Return: Returns 0 if permission is granted.
4854+
*/
48324855
int security_bpf_map(struct bpf_map *map, fmode_t fmode)
48334856
{
48344857
return call_int_hook(bpf_map, 0, map, fmode);
48354858
}
4859+
4860+
/**
4861+
* security_bpf_prog() - Check if access to a bpf program is allowed
4862+
* @prog: bpf program
4863+
*
4864+
* Do a check when the kernel generates and returns a file descriptor for eBPF
4865+
* programs.
4866+
*
4867+
* Return: Returns 0 if permission is granted.
4868+
*/
48364869
int security_bpf_prog(struct bpf_prog *prog)
48374870
{
48384871
return call_int_hook(bpf_prog, 0, prog);
48394872
}
4873+
4874+
/**
4875+
* security_bpf_map_alloc() - Allocate a bpf map LSM blob
4876+
* @map: bpf map
4877+
*
4878+
* Initialize the security field inside bpf map.
4879+
*
4880+
* Return: Returns 0 on success, error on failure.
4881+
*/
48404882
int security_bpf_map_alloc(struct bpf_map *map)
48414883
{
48424884
return call_int_hook(bpf_map_alloc_security, 0, map);
48434885
}
4886+
4887+
/**
4888+
* security_bpf_prog_alloc() - Allocate a bpf program LSM blob
4889+
* @aux: bpf program aux info struct
4890+
*
4891+
* Initialize the security field inside bpf program.
4892+
*
4893+
* Return: Returns 0 on success, error on failure.
4894+
*/
48444895
int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
48454896
{
48464897
return call_int_hook(bpf_prog_alloc_security, 0, aux);
48474898
}
4899+
4900+
/**
4901+
* security_bpf_map_free() - Free a bpf map's LSM blob
4902+
* @map: bpf map
4903+
*
4904+
* Clean up the security information stored inside bpf map.
4905+
*/
48484906
void security_bpf_map_free(struct bpf_map *map)
48494907
{
48504908
call_void_hook(bpf_map_free_security, map);
48514909
}
4910+
4911+
/**
4912+
* security_bpf_prog_free() - Free a bpf program's LSM blob
4913+
* @aux: bpf program aux info struct
4914+
*
4915+
* Clean up the security information stored inside bpf prog.
4916+
*/
48524917
void security_bpf_prog_free(struct bpf_prog_aux *aux)
48534918
{
48544919
call_void_hook(bpf_prog_free_security, aux);

0 commit comments

Comments
 (0)