// SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2024 Google LLC. //! Linux Security Modules (LSM). //! //! C header: [`include/linux/security.h`](srctree/include/linux/security.h). use crate::{ bindings, error::{to_result, Result}, }; /// A security context string. /// /// # Invariants /// /// The `ctx` field corresponds to a valid security context as returned by a successful call to /// `security_secid_to_secctx`, that has not yet been released by `security_release_secctx`. pub struct SecurityCtx { ctx: bindings::lsm_context, } impl SecurityCtx { /// Get the security context given its id. #[inline] pub fn from_secid(secid: u32) -> Result { // SAFETY: `struct lsm_context` can be initialized to all zeros. let mut ctx: bindings::lsm_context = unsafe { core::mem::zeroed() }; // SAFETY: Just a C FFI call. The pointer is valid for writes. to_result(unsafe { bindings::security_secid_to_secctx(secid, &mut ctx) })?; // INVARIANT: If the above call did not fail, then we have a valid security context. Ok(Self { ctx }) } /// Returns whether the security context is empty. #[inline] pub fn is_empty(&self) -> bool { self.ctx.len == 0 } /// Returns the length of this security context. #[inline] pub fn len(&self) -> usize { self.ctx.len as usize } /// Returns the bytes for this security context. #[inline] pub fn as_bytes(&self) -> &[u8] { let ptr = self.ctx.context; if ptr.is_null() { debug_assert_eq!(self.len(), 0); // We can't pass a null pointer to `slice::from_raw_parts` even if the length is zero. return &[]; } // SAFETY: The call to `security_secid_to_secctx` guarantees that the pointer is valid for // `self.len()` bytes. Furthermore, if the length is zero, then we have ensured that the // pointer is not null. unsafe { core::slice::from_raw_parts(ptr.cast(), self.len()) } } } impl Drop for SecurityCtx { #[inline] fn drop(&mut self) { // SAFETY: By the invariant of `Self`, this releases an lsm context that came from a // successful call to `security_secid_to_secctx` and has not yet been released. unsafe { bindings::security_release_secctx(&mut self.ctx) }; } } value='clearfog-4.12'>clearfog-4.12 Russell King's ARM Linux kernel treeRussell King
summaryrefslogtreecommitdiff
path: root/drivers/firmware/psci/psci.c
AgeCommit message (Expand)Author
2025-04-29firmware: psci: Fix refcount leak in psci_dt_initMiaoqian Lin
2024-10-31arm64: Use SYSTEM_OFF2 PSCI call to power off for hibernateDavid Woodhouse
2024-06-20firmware: psci: Fix return value from psci_system_suspend()Sudeep Holla
2023-04-14firmware/psci: demote suspend-mode warning to info levelJohan Hovold
2023-01-31cpuidle: drivers: firmware: psci: Dont instrument suspend codeMark Rutland
2023-01-31Merge tag 'v6.2-rc6' into sched/core, to pick up fixesIngo Molnar
2023-01-18cpuidle, arm64: Fix the ARM64 cpuidle logicPeter Zijlstra
2023-01-06firmware/psci: Don't register with debugfs if PSCI isn't availableMarc Zyngier
2022-10-06Merge tag 'arm-drivers-6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/...Linus Torvalds
2022-09-28firmware/psci: Add debugfs support to ease debuggingDmitry Baryshkov
2022-09-28firmware/psci: Print a warning if PSCI doesn't accept PC modeDmitry Baryshkov
2022-09-26treewide: Drop function_nocfiSami Tolvanen
2022-09-26psci: Fix the function type for psci_initcall_tSami Tolvanen
2021-07-06Merge tag 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-armLinus Torvalds
2021-06-17PSCI: Use cpuidle context helpers in psci_cpu_suspend_enter()Marc Zyngier
2021-06-13ARM: 9093/1: drivers: firmwapsci: Register with kernel restart handlerGuenter Roeck
2021-05-07Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm6...Linus Torvalds
2021-05-01Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvmLinus Torvalds
2021-04-29psci: Remove unneeded semicolonYang Li
2021-04-08psci: use function_nocfi for cpu_resumeSami Tolvanen
2021-03-31arm/arm64: Probe for the presence of KVM hypervisorWill Deacon
2020-12-04psci: Add accessor for psci_0_1_function_idsDavid Brazdil
2020-12-04psci: Replace psci_function_id array with a structDavid Brazdil
2020-12-04psci: Split functions to v0.1 and v0.2+ variantsDavid Brazdil
2020-12-04psci: Support psci_ops.get_version for v0.1David Brazdil
2020-09-22firmware: psci: Extend psci_set_osi_mode() to allow reset to PC modeUlf Hansson
2020-05-21firmware: smccc: Fix missing prototype warning for arm_smccc_version_initSudeep Holla
2020-05-20firmware: smccc: Refactor SMCCC specific bits into separate fileSudeep Holla
2020-05-20firmware: smccc: Drop smccc_version enum and use ARM_SMCCC_VERSION_1_x insteadSudeep Holla
2020-01-02firmware: psci: Export functions to manage the OSI modeUlf Hansson
2019-10-14firmware/psci: use common SMCCC_CONDUIT_*Mark Rutland
2019-10-14arm/arm64: smccc/psci: add arm_smccc_1_1_get_conduit()Mark Rutland
2019-08-09PSCI: cpuidle: Refactor CPU suspend power_state parameter handlingLorenzo Pieralisi
2019-08-09ARM: psci: cpuidle: Enable PSCI CPUidle driverLorenzo Pieralisi
2019-05-30treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174Thomas Gleixner
2019-04-16firmware/psci: add support for SYSTEM_RESET2Sudeep Holla
2019-04-12drivers: firmware: psci: Announce support for OS initiated suspend modeUlf Hansson
2019-04-12drivers: firmware: psci: Simplify error path of psci_dt_init()Ulf Hansson
2019-04-12drivers: firmware: psci: Split psci_dt_cpu_init_idle()Ulf Hansson
2019-04-12drivers: firmware: psci: Move psci to separate directoryUlf Hansson