Skip to content

Commit

Permalink
sysctl: constify the ctl_table argument of proc_handlers
Browse files Browse the repository at this point in the history
This is counterpart to Linux commit:

commit 78eb4ea25cd5fdbdae7eb9fdf87b99195ff67508
Author: Joel Granados <[email protected]>
Date:   Wed Jul 24 20:59:29 2024 +0200

    sysctl: treewide: constify the ctl_table argument of proc_handlers

    const qualify the struct ctl_table argument in the proc_handler function
    signatures. This is a prerequisite to moving the static ctl_table
    structs into .rodata data which will ensure that proc_handler function
    pointers cannot be modified.

Fixes #349
  • Loading branch information
solardiz committed Aug 6, 2024
1 parent 2bf9cf0 commit b144a0e
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions src/modules/comm_channel/p_comm_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,51 +90,57 @@ static int p_profile_enforce_min = 0;
static int p_profile_enforce_max = 9;


static int p_sysctl_kint_validate(struct ctl_table *p_table, int p_write,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,11,0)
#define P_STRUCT_CTL_TABLE const struct ctl_table
#else
#define P_STRUCT_CTL_TABLE struct ctl_table
#endif

static int p_sysctl_kint_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_kint_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_kint_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_pint_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_pint_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_pint_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_pint_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_interval(struct ctl_table *p_table, int p_write,
static int p_sysctl_interval(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_block_modules(struct ctl_table *p_table, int p_write,
static int p_sysctl_block_modules(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_log_level(struct ctl_table *p_table, int p_write,
static int p_sysctl_log_level(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_trigger(struct ctl_table *p_table, int p_write,
static int p_sysctl_trigger(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
#ifdef P_LKRG_UNHIDE
static int p_sysctl_hide(struct ctl_table *p_table, int p_write,
static int p_sysctl_hide(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
#endif
static int p_sysctl_heartbeat(struct ctl_table *p_table, int p_write,
static int p_sysctl_heartbeat(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
#if defined(CONFIG_X86)
static int p_sysctl_smep_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_smep_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_smep_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_smep_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_smap_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_smap_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_smap_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_smap_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
#endif
static int p_sysctl_umh_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_umh_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_umh_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_umh_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_msr_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_msr_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_pcfi_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_pcfi_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_pcfi_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_pcfi_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_profile_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_profile_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);
static int p_sysctl_profile_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_profile_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos);


Expand Down Expand Up @@ -335,15 +341,15 @@ struct ctl_table p_lkrg_sysctl_table[] = {
/*
* Empty element at the end of array was required when register_sysctl() was a
* function. It's no longer required when it became a macro in 2023, and it's
* disallowed after further changes in 2024.
* disallowed after further changes in 2024 (starting with 6.11-rc kernels).
*/
#ifndef register_sysctl
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,11,0)
{ }
#endif
};


static int p_sysctl_kint_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_kint_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -376,7 +382,7 @@ static int p_sysctl_kint_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_kint_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_kint_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -411,7 +417,7 @@ static int p_sysctl_kint_enforce(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_pint_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_pint_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -438,7 +444,7 @@ static int p_sysctl_pint_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_pint_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_pint_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -465,7 +471,7 @@ static int p_sysctl_pint_enforce(struct ctl_table *p_table, int p_write,
}


static int p_sysctl_interval(struct ctl_table *p_table, int p_write,
static int p_sysctl_interval(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {
int p_ret;
unsigned int p_tmp;
Expand All @@ -483,7 +489,7 @@ static int p_sysctl_interval(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_block_modules(struct ctl_table *p_table, int p_write,
static int p_sysctl_block_modules(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -503,7 +509,7 @@ static int p_sysctl_block_modules(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_log_level(struct ctl_table *p_table, int p_write,
static int p_sysctl_log_level(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {
int p_ret;
unsigned int p_log_level_old;
Expand Down Expand Up @@ -539,7 +545,7 @@ static int p_sysctl_log_level(struct ctl_table *p_table, int p_write,
}


static int p_sysctl_trigger(struct ctl_table *p_table, int p_write,
static int p_sysctl_trigger(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -558,7 +564,7 @@ static int p_sysctl_trigger(struct ctl_table *p_table, int p_write,
}

#ifdef P_LKRG_UNHIDE
static int p_sysctl_hide(struct ctl_table *p_table, int p_write,
static int p_sysctl_hide(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -581,7 +587,7 @@ static int p_sysctl_hide(struct ctl_table *p_table, int p_write,
}
#endif

static int p_sysctl_heartbeat(struct ctl_table *p_table, int p_write,
static int p_sysctl_heartbeat(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -602,7 +608,7 @@ static int p_sysctl_heartbeat(struct ctl_table *p_table, int p_write,
}

#if defined(CONFIG_X86)
static int p_sysctl_smep_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_smep_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -633,7 +639,7 @@ static int p_sysctl_smep_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_smep_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_smep_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -667,7 +673,7 @@ static int p_sysctl_smep_enforce(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_smap_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_smap_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -698,7 +704,7 @@ static int p_sysctl_smap_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_smap_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_smap_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -733,7 +739,7 @@ static int p_sysctl_smap_enforce(struct ctl_table *p_table, int p_write,
}
#endif

static int p_sysctl_umh_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_umh_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -759,7 +765,7 @@ static int p_sysctl_umh_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_umh_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_umh_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -785,7 +791,7 @@ static int p_sysctl_umh_enforce(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_msr_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_msr_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -820,7 +826,7 @@ static int p_sysctl_msr_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_pcfi_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_pcfi_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -846,7 +852,7 @@ static int p_sysctl_pcfi_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_pcfi_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_pcfi_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand All @@ -872,7 +878,7 @@ static int p_sysctl_pcfi_enforce(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_profile_validate(struct ctl_table *p_table, int p_write,
static int p_sysctl_profile_validate(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down Expand Up @@ -1115,7 +1121,7 @@ static int p_sysctl_profile_validate(struct ctl_table *p_table, int p_write,
return p_ret;
}

static int p_sysctl_profile_enforce(struct ctl_table *p_table, int p_write,
static int p_sysctl_profile_enforce(P_STRUCT_CTL_TABLE *p_table, int p_write,
void __user *p_buffer, size_t *p_len, loff_t *p_pos) {

int p_ret;
Expand Down

0 comments on commit b144a0e

Please sign in to comment.