Skip to content

Commit 742b994

Browse files
committed
lsm: move the xfrm 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 ac318ae commit 742b994

2 files changed

Lines changed: 103 additions & 73 deletions

File tree

include/linux/lsm_hooks.h

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -32,79 +32,6 @@
3232
/**
3333
* union security_list_options - Linux Security Module hook function list
3434
*
35-
* Security hooks for XFRM operations.
36-
*
37-
* @xfrm_policy_alloc_security:
38-
* @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy
39-
* Database used by the XFRM system.
40-
* @sec_ctx contains the security context information being provided by
41-
* the user-level policy update program (e.g., setkey).
42-
* @gfp is to specify the context for the allocation.
43-
* Allocate a security structure to the xp->security field; the security
44-
* field is initialized to NULL when the xfrm_policy is allocated.
45-
* Return 0 if operation was successful (memory to allocate, legal
46-
* context).
47-
* @xfrm_policy_clone_security:
48-
* @old_ctx contains an existing xfrm_sec_ctx.
49-
* @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
50-
* Allocate a security structure in new_ctxp that contains the
51-
* information from the old_ctx structure.
52-
* Return 0 if operation was successful (memory to allocate).
53-
* @xfrm_policy_free_security:
54-
* @ctx contains the xfrm_sec_ctx.
55-
* Deallocate xp->security.
56-
* @xfrm_policy_delete_security:
57-
* @ctx contains the xfrm_sec_ctx.
58-
* Authorize deletion of xp->security.
59-
* Return 0 if permission is granted.
60-
* @xfrm_state_alloc:
61-
* @x contains the xfrm_state being added to the Security Association
62-
* Database by the XFRM system.
63-
* @sec_ctx contains the security context information being provided by
64-
* the user-level SA generation program (e.g., setkey or racoon).
65-
* Allocate a security structure to the x->security field; the security
66-
* field is initialized to NULL when the xfrm_state is allocated. Set the
67-
* context to correspond to sec_ctx. Return 0 if operation was successful
68-
* (memory to allocate, legal context).
69-
* @xfrm_state_alloc_acquire:
70-
* @x contains the xfrm_state being added to the Security Association
71-
* Database by the XFRM system.
72-
* @polsec contains the policy's security context.
73-
* @secid contains the secid from which to take the mls portion of the
74-
* context.
75-
* Allocate a security structure to the x->security field; the security
76-
* field is initialized to NULL when the xfrm_state is allocated. Set the
77-
* context to correspond to secid. Return 0 if operation was successful
78-
* (memory to allocate, legal context).
79-
* @xfrm_state_free_security:
80-
* @x contains the xfrm_state.
81-
* Deallocate x->security.
82-
* @xfrm_state_delete_security:
83-
* @x contains the xfrm_state.
84-
* Authorize deletion of x->security.
85-
* Return 0 if permission is granted.
86-
* @xfrm_policy_lookup:
87-
* @ctx contains the xfrm_sec_ctx for which the access control is being
88-
* checked.
89-
* @fl_secid contains the flow security label that is used to authorize
90-
* access to the policy xp.
91-
* @dir contains the direction of the flow (input or output).
92-
* Check permission when a flow selects a xfrm_policy for processing
93-
* XFRMs on a packet. The hook is called when selecting either a
94-
* per-socket policy or a generic xfrm policy.
95-
* Return 0 if permission is granted, -ESRCH otherwise, or -errno
96-
* on other errors.
97-
* @xfrm_state_pol_flow_match:
98-
* @x contains the state to match.
99-
* @xp contains the policy to check for a match.
100-
* @flic contains the flowi_common struct to check for a match.
101-
* Return 1 if there is a match.
102-
* @xfrm_decode_session:
103-
* @skb points to skb to decode.
104-
* @secid points to the flow key secid to set.
105-
* @ckall says if all xfrms used should be checked for same secid.
106-
* Return 0 if ckall is zero or all xfrms used have the same secid.
107-
*
10835
* Security hooks affecting all Key Management operations
10936
*
11037
* @key_alloc:

security/security.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4269,6 +4269,17 @@ EXPORT_SYMBOL(security_ib_free_security);
42694269

42704270
#ifdef CONFIG_SECURITY_NETWORK_XFRM
42714271

4272+
/**
4273+
* security_xfrm_policy_alloc() - Allocate a xfrm policy LSM blob
4274+
* @ctxp: xfrm security context being added to the SPD
4275+
* @sec_ctx: security label provided by userspace
4276+
* @gfp: gfp flags
4277+
*
4278+
* Allocate a security structure to the xp->security field; the security field
4279+
* is initialized to NULL when the xfrm_policy is allocated.
4280+
*
4281+
* Return: Return 0 if operation was successful.
4282+
*/
42724283
int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
42734284
struct xfrm_user_sec_ctx *sec_ctx,
42744285
gfp_t gfp)
@@ -4277,52 +4288,135 @@ int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp,
42774288
}
42784289
EXPORT_SYMBOL(security_xfrm_policy_alloc);
42794290

4291+
/**
4292+
* security_xfrm_policy_clone() - Clone xfrm policy LSM state
4293+
* @old_ctx: xfrm security context
4294+
* @new_ctxp: target xfrm security context
4295+
*
4296+
* Allocate a security structure in new_ctxp that contains the information from
4297+
* the old_ctx structure.
4298+
*
4299+
* Return: Return 0 if operation was successful.
4300+
*/
42804301
int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx,
42814302
struct xfrm_sec_ctx **new_ctxp)
42824303
{
42834304
return call_int_hook(xfrm_policy_clone_security, 0, old_ctx, new_ctxp);
42844305
}
42854306

4307+
/**
4308+
* security_xfrm_policy_free() - Free a xfrm security context
4309+
* @ctx: xfrm security context
4310+
*
4311+
* Free LSM resources associated with @ctx.
4312+
*/
42864313
void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
42874314
{
42884315
call_void_hook(xfrm_policy_free_security, ctx);
42894316
}
42904317
EXPORT_SYMBOL(security_xfrm_policy_free);
42914318

4319+
/**
4320+
* security_xfrm_policy_delete() - Check if deleting a xfrm policy is allowed
4321+
* @ctx: xfrm security context
4322+
*
4323+
* Authorize deletion of a SPD entry.
4324+
*
4325+
* Return: Returns 0 if permission is granted.
4326+
*/
42924327
int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
42934328
{
42944329
return call_int_hook(xfrm_policy_delete_security, 0, ctx);
42954330
}
42964331

4332+
/**
4333+
* security_xfrm_state_alloc() - Allocate a xfrm state LSM blob
4334+
* @x: xfrm state being added to the SAD
4335+
* @sec_ctx: security label provided by userspace
4336+
*
4337+
* Allocate a security structure to the @x->security field; the security field
4338+
* is initialized to NULL when the xfrm_state is allocated. Set the context to
4339+
* correspond to @sec_ctx.
4340+
*
4341+
* Return: Return 0 if operation was successful.
4342+
*/
42974343
int security_xfrm_state_alloc(struct xfrm_state *x,
42984344
struct xfrm_user_sec_ctx *sec_ctx)
42994345
{
43004346
return call_int_hook(xfrm_state_alloc, 0, x, sec_ctx);
43014347
}
43024348
EXPORT_SYMBOL(security_xfrm_state_alloc);
43034349

4350+
/**
4351+
* security_xfrm_state_alloc_acquire() - Allocate a xfrm state LSM blob
4352+
* @x: xfrm state being added to the SAD
4353+
* @polsec: associated policy's security context
4354+
* @secid: secid from the flow
4355+
*
4356+
* Allocate a security structure to the x->security field; the security field
4357+
* is initialized to NULL when the xfrm_state is allocated. Set the context to
4358+
* correspond to secid.
4359+
*
4360+
* Return: Returns 0 if operation was successful.
4361+
*/
43044362
int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
43054363
struct xfrm_sec_ctx *polsec, u32 secid)
43064364
{
43074365
return call_int_hook(xfrm_state_alloc_acquire, 0, x, polsec, secid);
43084366
}
43094367

4368+
/**
4369+
* security_xfrm_state_delete() - Check if deleting a xfrm state is allowed
4370+
* @x: xfrm state
4371+
*
4372+
* Authorize deletion of x->security.
4373+
*
4374+
* Return: Returns 0 if permission is granted.
4375+
*/
43104376
int security_xfrm_state_delete(struct xfrm_state *x)
43114377
{
43124378
return call_int_hook(xfrm_state_delete_security, 0, x);
43134379
}
43144380
EXPORT_SYMBOL(security_xfrm_state_delete);
43154381

4382+
/**
4383+
* security_xfrm_state_free() - Free a xfrm state
4384+
* @x: xfrm state
4385+
*
4386+
* Deallocate x->security.
4387+
*/
43164388
void security_xfrm_state_free(struct xfrm_state *x)
43174389
{
43184390
call_void_hook(xfrm_state_free_security, x);
43194391
}
43204392

4393+
/**
4394+
* security_xfrm_policy_lookup() - Check if using a xfrm policy is allowed
4395+
* @ctx: target xfrm security context
4396+
* @fl_secid: flow secid used to authorize access
4397+
*
4398+
* Check permission when a flow selects a xfrm_policy for processing XFRMs on a
4399+
* packet. The hook is called when selecting either a per-socket policy or a
4400+
* generic xfrm policy.
4401+
*
4402+
* Return: Return 0 if permission is granted, -ESRCH otherwise, or -errno on
4403+
* other errors.
4404+
*/
43214405
int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid)
43224406
{
43234407
return call_int_hook(xfrm_policy_lookup, 0, ctx, fl_secid);
43244408
}
43254409

4410+
/**
4411+
* security_xfrm_state_pol_flow_match() - Check for a xfrm match
4412+
* @x: xfrm state to match
4413+
* @xp xfrm policy to check for a match
4414+
* @flic: flow to check for a match.
4415+
*
4416+
* Check @xp and @flic for a match with @x.
4417+
*
4418+
* Return: Returns 1 if there is a match.
4419+
*/
43264420
int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
43274421
struct xfrm_policy *xp,
43284422
const struct flowi_common *flic)
@@ -4347,6 +4441,15 @@ int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
43474441
return rc;
43484442
}
43494443

4444+
/**
4445+
* security_xfrm_decode_session() - Determine the xfrm secid for a packet
4446+
* @skb: xfrm packet
4447+
* @secid: secid
4448+
*
4449+
* Decode the packet in @skb and return the security label in @secid.
4450+
*
4451+
* Return: Return 0 if all xfrms used have the same secid.
4452+
*/
43504453
int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
43514454
{
43524455
return call_int_hook(xfrm_decode_session, 0, skb, secid, 1);

0 commit comments

Comments
 (0)