Skip to content

Instantly share code, notes, and snippets.

View mbs0221's full-sized avatar
🏠
Working

Benshan Mei mbs0221

🏠
Working
View GitHub Profile
@mbs0221
mbs0221 / my_app.c
Last active August 22, 2023 08:05
linux-security-modules
// 下面是一个基于进程名和文件名实现特定进程可以访问特定文件的LSM示例代码
#include <linux/lsm_hooks.h>
#include <linux/path.h>
#include <linux/dcache.h>
#include <linux/namei.h>
// 定义允许访问文件的进程名称
static char *allowed_process_name = "my_app";
// 定义需要保护的文件路径
static char *file_path = "path/to/protected/file";
@mbs0221
mbs0221 / va2pa.c
Last active July 29, 2023 14:27
va2pa.c
static unsigned long vaddr2paddr(unsigned long vaddr)
{
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd;
pte_t *pte;
unsigned long paddr = 0;
unsigned long page_addr = 0;
unsigned long page_offset = 0;
@mbs0221
mbs0221 / endian.c
Last active July 11, 2023 15:48
endian.c
#include <stdio.h>
int main(int argc, char *argv[])
{
union w {
int a;
char b;
} c;
c.a = 1;
@mbs0221
mbs0221 / intel-tsx.c
Last active November 20, 2023 17:01
simple Intel TSX example
#include <stdio.h>
#include <immintrin.h>
int main() {
unsigned int balance = 100;
unsigned int withdrawal = 50;
// 开始事务
if (_xbegin() == _XBEGIN_STARTED) {
// 在事务中执行操作
@mbs0221
mbs0221 / simple_socket_example.c
Created April 14, 2023 15:14 — forked from browny/simple_socket_example.c
simple socket example in C
/* --- Usage --- */
g++ server.c -o server
g++ client.c -o client
./server
./client 127.0.0.1
/* --- server.c --- */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@mbs0221
mbs0221 / cissp_notes.md
Created May 25, 2022 16:36 — forked from penafieljlm/cissp_notes.md
Personal CISSP Study Notes

CISSP Notes

CIA Triad

  • Confidentiality
    • Resources should be protected from unauthorized access
    • Prioritized by governments
    • Concepts
      • Sensitivity
        • How harmful is disclosure
  • Discretion
@mbs0221
mbs0221 / tsx.cpp
Created May 12, 2022 11:42 — forked from JimChengLin/tsx.cpp
Intel TSX simple benchmark
#include <atomic>
#include <chrono>
#include <immintrin.h>
#include <iostream>
#include <thread>
struct Node {
Node * prev{};
Node * next{};
};
@mbs0221
mbs0221 / check_cet_supported.c
Created May 12, 2022 11:28 — forked from kohnakagawa/check_cet_supported.c
Checks whether your cpu supports Intel CET or not (Linux).
#include <stdio.h>
#include <cpuid.h>
#include <stdint.h>
int cpu_supports_cet_shadow_stack() {
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
__cpuid_count(7, 0, eax, ebx, ecx, edx);
return (ecx & (1 << 7)) != 0;
}