Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <jpeglib.h>
#include <setjmp.h>
// Structure to hold decoder state
struct decoder_state {
struct jpeg_decompress_struct* info;
struct jpeg_error_mgr* err;
@ARISTODE
ARISTODE / corrupted-idx-nvme-c3.c
Created October 7, 2024 05:46
Corrupted array index nvme case 3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
// Define __user macro (in userspace, this doesn't have a special meaning)
#define __user
// Dummy functions to simulate kernel functions
static void might_fault(void) {
@ARISTODE
ARISTODE / corrupted-buf-idx-mgag200.c
Created October 7, 2024 05:39
corrupted buffer index mgag200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
// Dummy structures to represent kernel structures
struct device {
// Simplified device structure
int dummy;
};
@ARISTODE
ARISTODE / alias.ll
Created April 8, 2023 20:19
Alias.ll
This file has been truncated, but you can view the full file.
; ModuleID = 'alias.bc'
source_filename = "llvm-link"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, %struct._IO_codecvt*, %struct._IO_wide_data*, %struct._IO_FILE*, i8*, i64, i32, [20 x i8] }
%struct._IO_marker = type opaque
%struct._IO_codecvt = type opaque
%struct._IO_wide_data = type opaque
%struct.KlvTag_t = type { i8, i32, i8*, %struct.KlvTag_t* }
@ARISTODE
ARISTODE / KernelAllocExample
Created March 30, 2023 15:02
Kernel Alloc API Example
Call Path: napi_gro_receive->dev_gro_receive->napi_gro_complete->netif_receive_skb_internal->__netif_receive_skb->__netif_receive_skb_core->skb_vlan_untag->pskb_may_pull.2063->__pskb_pull_tail->pskb_expand_head->__kmalloc_reserve
- kernel func (napi_gro_receive) | allocator (__kmalloc_reserve) | driver call site (ixgbe_rx_skb) - %17 = call i32 @napi_gro_receive(%struct.napi_struct* %15, %struct.sk_buff* %16) #11, !dbg !281511
Call Path: netif_receive_skb->netif_receive_skb_internal->__netif_receive_skb->__netif_receive_skb_core->skb_vlan_untag->pskb_may_pull.2063->__pskb_pull_tail->pskb_expand_head->__kmalloc_reserve
- kernel func (netif_receive_skb) | allocator (__kmalloc_reserve) | driver call site (ixgbe_rx_skb) - %12 = call i32 @netif_receive_skb(%struct.sk_buff* %11) #11, !dbg !281507
Call Path: netif_set_xps_queue->kzalloc.1679
- kernel func (netif_set_xps_queue) | allocator (kzalloc.1679) | driver call site (ixgbe_configure_tx_ring) - %170 = call i32 @netif_set_xps_queue(%struct.net_device* %16
char *mg_json_get_str(struct mg_str json, const char *path) {
int n, toklen;
char *result = NULL;
if ((n = mg_json_get(json.ptr, (int) json.len, path, &toklen)) >= 0 &&
json.ptr[n] == '"') {
if ((result = (char *) calloc(1, (size_t) toklen)) != NULL &&
!json_unescape(json.ptr + n + 1, (size_t) (toklen - 2), result,
(size_t) toklen)) {
free(result);
result = NULL;
@ARISTODE
ARISTODE / benchmarks.txt
Created December 5, 2021 20:37
benchmark list #ksplit
net_ethernet/dummy
net_ethernet/ixgbe
net_ethernet/alx
block/null_blk
edac/skx_edac
edac/sb_edac
arch_x86/msr
can-raw
md/dm-zero
hwmon/acpi_power_meter
@ARISTODE
ARISTODE / run_benchmarks.sh
Last active December 5, 2021 20:37
Run Benchmarks Script #ksplit #bash
#!/bin/bash
input="/local/device/bc-files/benchmarks"
bc_files_dir="/local/device/bc-files/"
while IFS= read -r line
do
bench_dir="${bc_files_dir}/${line}"
pushd ${bench_dir} > /dev/null
bench_name="${PWD##*/}"
bool isDIStructType(DIType *dt)
{
if (dt == nullptr)
return false;
return (dt->getTag() == dwarf::DW_TAG_structure_type);
}
void getFieldNames(DIType *dt)
{
// check if dt is of struct type
std::string getArgName(Argument& arg, std::vector<DbgDeclareInst*> dbgInstList)
{
Function *F = arg.getParent();
for (auto I : dbgInstList)
{
if (auto dbi = dyn_cast<DbgDeclareInst>(I))
if (auto DLV = dyn_cast<DILocalVariable>(dbi->getVariable()))
if (DLV->getArg() == arg.getArgNo() + 1
&& !DLV->getName().empty()
&& DLV->getScope()->getSubprogram() == F->getSubprogram())