security/selinux/netlabel.c
Source file repositories/reference/linux-study-clean/security/selinux/netlabel.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/netlabel.c- Extension
.c- Size
- 16481 bytes
- Lines
- 620
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/rcupdate.hlinux/gfp.hlinux/ip.hlinux/ipv6.hlinux/lsm_hooks.hnet/sock.hnet/netlabel.hnet/ip.hnet/ipv6.hobjsec.hsecurity.hnetlabel.h
Detected Declarations
function selinux_netlbl_sidlookup_cachedfunction selinux_netlbl_cache_invalidatefunction avc_has_permfunction selinux_netlbl_sk_security_freefunction selinux_netlbl_sk_security_resetfunction selinux_netlbl_skbuff_getsidfunction selinux_netlbl_skbuff_setsidfunction selinux_netlbl_sctp_assoc_requestfunction netlbl_conn_setattrfunction selinux_netlbl_inet_conn_requestfunction selinux_netlbl_inet_conn_requestfunction acceptfunction selinux_netlbl_socket_post_createfunction selinux_netlbl_sock_rcv_skbfunction selinux_netlbl_socket_setsockoptfunction selinux_netlbl_socket_setsockoptfunction selinux_netlbl_socket_connect_helperfunction selinux_netlbl_socket_connect_lockedfunction selinux_netlbl_socket_connect
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* SELinux NetLabel Support
*
* This file provides the necessary glue to tie NetLabel into the SELinux
* subsystem.
*
* Author: Paul Moore <paul@paul-moore.com>
*/
/*
* (c) Copyright Hewlett-Packard Development Company, L.P., 2007, 2008
*/
#include <linux/spinlock.h>
#include <linux/rcupdate.h>
#include <linux/gfp.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/lsm_hooks.h>
#include <net/sock.h>
#include <net/netlabel.h>
#include <net/ip.h>
#include <net/ipv6.h>
#include "objsec.h"
#include "security.h"
#include "netlabel.h"
/**
* selinux_netlbl_sidlookup_cached - Cache a SID lookup
* @skb: the packet
* @family: the packet's address family
* @secattr: the NetLabel security attributes
* @sid: the SID
*
* Description:
* Query the SELinux security server to lookup the correct SID for the given
* security attributes. If the query is successful, cache the result to speed
* up future lookups. Returns zero on success, negative values on failure.
*
*/
static int selinux_netlbl_sidlookup_cached(struct sk_buff *skb,
u16 family,
struct netlbl_lsm_secattr *secattr,
u32 *sid)
{
int rc;
rc = security_netlbl_secattr_to_sid(secattr, sid);
if (rc == 0 &&
(secattr->flags & NETLBL_SECATTR_CACHEABLE) &&
(secattr->flags & NETLBL_SECATTR_CACHE))
netlbl_cache_add(skb, family, secattr);
return rc;
}
/**
* selinux_netlbl_sock_genattr - Generate the NetLabel socket secattr
* @sk: the socket
*
* Description:
* Generate the NetLabel security attributes for a socket, making full use of
* the socket's attribute cache. Returns a pointer to the security attributes
* on success, or an ERR_PTR on failure.
*
*/
static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk)
{
int rc;
struct sk_security_struct *sksec = selinux_sock(sk);
struct netlbl_lsm_secattr *secattr;
if (sksec->nlbl_secattr != NULL)
return sksec->nlbl_secattr;
secattr = netlbl_secattr_alloc(GFP_ATOMIC);
if (secattr == NULL)
return ERR_PTR(-ENOMEM);
rc = security_netlbl_sid_to_secattr(sksec->sid, secattr);
if (rc != 0) {
netlbl_secattr_free(secattr);
return ERR_PTR(rc);
}
sksec->nlbl_secattr = secattr;
return secattr;
}
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/rcupdate.h`, `linux/gfp.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/lsm_hooks.h`, `net/sock.h`, `net/netlabel.h`.
- Detected declarations: `function selinux_netlbl_sidlookup_cached`, `function selinux_netlbl_cache_invalidate`, `function avc_has_perm`, `function selinux_netlbl_sk_security_free`, `function selinux_netlbl_sk_security_reset`, `function selinux_netlbl_skbuff_getsid`, `function selinux_netlbl_skbuff_setsid`, `function selinux_netlbl_sctp_assoc_request`, `function netlbl_conn_setattr`, `function selinux_netlbl_inet_conn_request`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.