Skip to content

Commit

Permalink
BACKPORT: treewide: Fix function prototypes for module_param_call()
Browse files Browse the repository at this point in the history
Several function prototypes for the set/get functions defined by
module_param_call() have a slightly wrong argument types. This fixes
those in an effort to clean up the calls when running under type-enforced
compiler instrumentation for CFI. This is the result of running the
following semantic patch:

@match_module_param_call_function@
declarer name module_param_call;
identifier _name, _set_func, _get_func;
expression _arg, _mode;
@@

 module_param_call(_name, _set_func, _get_func, _arg, _mode);

@fix_set_prototype
 depends on match_module_param_call_function@
identifier match_module_param_call_function._set_func;
identifier _val, _param;
type _val_type, _param_type;
@@

 int _set_func(
-_val_type _val
+const char * _val
 ,
-_param_type _param
+const struct kernel_param * _param
 ) { ... }

@fix_get_prototype
 depends on match_module_param_call_function@
identifier match_module_param_call_function._get_func;
identifier _val, _param;
type _val_type, _param_type;
@@

 int _get_func(
-_val_type _val
+char * _val
 ,
-_param_type _param
+const struct kernel_param * _param
 ) { ... }

Two additional by-hand changes are included for places where the above
Coccinelle script didn't notice them:

	drivers/platform/x86/thinkpad_acpi.c
	fs/lockd/svc.c

Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Jessica Yu <[email protected]>

Bug: 67506682
Change-Id: I2c9c0ee8ed28065e63270a52c155e5e7d2791295
(cherry picked from commit e4dca7b7aa08b22893c45485d222b5807c1375ae)
Signed-off-by: Sami Tolvanen <[email protected]>
(cherry picked from commit 24da2c84bd7dcdf2b56fa8d3b2f833656ee60a01)
Signed-off-by: Dan Aloni <[email protected]>
Signed-off-by: Davide Garberi <[email protected]>
  • Loading branch information
kees authored and chrmhoffmann committed Nov 15, 2022
1 parent 15364fe commit 55b75ea
Show file tree
Hide file tree
Showing 46 changed files with 96 additions and 80 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/pseries/cmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ static void cmm_exit(void)
* Return value:
* 0 on success / other on failure
**/
static int cmm_set_disable(const char *val, struct kernel_param *kp)
static int cmm_set_disable(const char *val, const struct kernel_param *kp)
{
int disable = simple_strtoul(val, NULL, 10);

Expand Down
2 changes: 1 addition & 1 deletion arch/s390/oprofile/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum __force_cpu_type {
};
static int force_cpu_type;

static int set_cpu_type(const char *str, struct kernel_param *kp)
static int set_cpu_type(const char *str, const struct kernel_param *kp)
{
if (!strcmp(str, "timer")) {
force_cpu_type = timer;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/oprofile/nmi_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ enum __force_cpu_type {

static int force_cpu_type;

static int set_cpu_type(const char *str, struct kernel_param *kp)
static int set_cpu_type(const char *str, const struct kernel_param *kp)
{
if (!strcmp(str, "timer")) {
force_cpu_type = timer;
Expand Down
6 changes: 4 additions & 2 deletions drivers/acpi/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,8 @@ int __init acpi_ec_ecdt_probe(void)
return -ENODEV;
}

static int param_set_event_clearing(const char *val, struct kernel_param *kp)
static int param_set_event_clearing(const char *val,
const struct kernel_param *kp)
{
int result = 0;

Expand All @@ -1626,7 +1627,8 @@ static int param_set_event_clearing(const char *val, struct kernel_param *kp)
return result;
}

static int param_get_event_clearing(char *buffer, struct kernel_param *kp)
static int param_get_event_clearing(char *buffer,
const struct kernel_param *kp)
{
switch (ec_event_clearing) {
case ACPI_EC_EVT_TIMING_STATUS:
Expand Down
8 changes: 5 additions & 3 deletions drivers/acpi/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ module_param_cb(trace_method_name, &param_ops_trace_method, &trace_method_name,
module_param_cb(trace_debug_layer, &param_ops_trace_attrib, &acpi_gbl_trace_dbg_layer, 0644);
module_param_cb(trace_debug_level, &param_ops_trace_attrib, &acpi_gbl_trace_dbg_level, 0644);

static int param_set_trace_state(const char *val, struct kernel_param *kp)
static int param_set_trace_state(const char *val,
const struct kernel_param *kp)
{
acpi_status status;
const char *method = trace_method_name;
Expand Down Expand Up @@ -263,7 +264,7 @@ static int param_set_trace_state(const char *val, struct kernel_param *kp)
return 0;
}

static int param_get_trace_state(char *buffer, struct kernel_param *kp)
static int param_get_trace_state(char *buffer, const struct kernel_param *kp)
{
if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED))
return sprintf(buffer, "disable");
Expand Down Expand Up @@ -292,7 +293,8 @@ MODULE_PARM_DESC(aml_debug_output,
"To enable/disable the ACPI Debug Object output.");

/* /sys/module/acpi/parameters/acpica_version */
static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
static int param_get_acpica_version(char *buffer,
const struct kernel_param *kp)
{
int result;

Expand Down
2 changes: 1 addition & 1 deletion drivers/android/binder.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
static int binder_stop_on_user_error;

static int binder_set_stop_on_user_error(const char *val,
struct kernel_param *kp)
const struct kernel_param *kp)
{
int ret;

Expand Down
2 changes: 1 addition & 1 deletion drivers/char/ipmi/ipmi_poweroff.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void (*specific_poweroff_func)(ipmi_user_t user);
/* Holds the old poweroff function so we can restore it on removal. */
static void (*old_poweroff_func)(void);

static int set_param_ifnum(const char *val, struct kernel_param *kp)
static int set_param_ifnum(const char *val, const struct kernel_param *kp)
{
int rv = param_set_int(val, kp);
if (rv)
Expand Down
4 changes: 2 additions & 2 deletions drivers/char/ipmi/ipmi_si_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ static unsigned int num_slave_addrs;
#define IPMI_MEM_ADDR_SPACE 1
static char *addr_space_to_str[] = { "i/o", "mem" };

static int hotmod_handler(const char *val, struct kernel_param *kp);
static int hotmod_handler(const char *val, const struct kernel_param *kp);

module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200);
MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See"
Expand Down Expand Up @@ -1814,7 +1814,7 @@ static struct smi_info *smi_info_alloc(void)
return info;
}

static int hotmod_handler(const char *val, struct kernel_param *kp)
static int hotmod_handler(const char *val, const struct kernel_param *kp)
{
char *str = kstrdup(val, GFP_KERNEL);
int rv;
Expand Down
2 changes: 1 addition & 1 deletion drivers/edac/edac_mc_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ unsigned int edac_mc_get_poll_msec(void)
return edac_mc_poll_msec;
}

static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
static int edac_set_poll_msec(const char *val, const struct kernel_param *kp)
{
unsigned int i;
int ret;
Expand Down
3 changes: 2 additions & 1 deletion drivers/edac/edac_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

#ifdef CONFIG_EDAC_DEBUG

static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
static int edac_set_debug_level(const char *buf,
const struct kernel_param *kp)
{
unsigned long val;
int ret;
Expand Down
3 changes: 2 additions & 1 deletion drivers/hid/hid-magicmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module_param(emulate_scroll_wheel, bool, 0644);
MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");

static unsigned int scroll_speed = 32;
static int param_set_scroll_speed(const char *val, struct kernel_param *kp) {
static int param_set_scroll_speed(const char *val,
const struct kernel_param *kp) {
unsigned long speed;
if (!val || kstrtoul(val, 0, &speed) || speed > 63)
return -EINVAL;
Expand Down
10 changes: 6 additions & 4 deletions drivers/hwtracing/coresight/coresight-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#include <trace/events/exception.h>

static int event_abort_enable;
static int event_abort_set(const char *val, struct kernel_param *kp);
static int event_abort_set(const char *val, const struct kernel_param *kp);
module_param_call(event_abort_enable, event_abort_set, param_get_int,
&event_abort_enable, 0644);

static int event_abort_early_panic = 1;
static int event_abort_on_panic_set(const char *val, struct kernel_param *kp);
static int event_abort_on_panic_set(const char *val,
const struct kernel_param *kp);
module_param_call(event_abort_early_panic, event_abort_on_panic_set,
param_get_int, &event_abort_early_panic, 0644);

Expand Down Expand Up @@ -96,7 +97,7 @@ static void event_abort_unregister(void)
unregister_trace_unhandled_abort(event_abort_unhandled_abort, NULL);
}

static int event_abort_set(const char *val, struct kernel_param *kp)
static int event_abort_set(const char *val, const struct kernel_param *kp)
{
int ret;

Expand All @@ -114,7 +115,8 @@ static int event_abort_set(const char *val, struct kernel_param *kp)
return ret;
}

static int event_abort_on_panic_set(const char *val, struct kernel_param *kp)
static int event_abort_on_panic_set(const char *val,
const struct kernel_param *kp)
{
int ret;

Expand Down
4 changes: 2 additions & 2 deletions drivers/ide/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ struct chs_geom {
static unsigned int ide_disks;
static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];

static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
static int ide_set_disk_chs(const char *str, const struct kernel_param *kp)
{
int a, b, c = 0, h = 0, s = 0, i, j = 1;

Expand Down Expand Up @@ -328,7 +328,7 @@ static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)

static unsigned int ide_ignore_cable;

static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
static int ide_set_ignore_cable(const char *s, const struct kernel_param *kp)
{
int i, j = 1;

Expand Down
4 changes: 2 additions & 2 deletions drivers/infiniband/hw/qib/qib_iba7322.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static struct kparam_string kp_txselect = {
.string = txselect_list,
.maxlen = MAX_ATTEN_LEN
};
static int setup_txselect(const char *, struct kernel_param *);
static int setup_txselect(const char *, const struct kernel_param *);
module_param_call(txselect, setup_txselect, param_get_string,
&kp_txselect, S_IWUSR | S_IRUGO);
MODULE_PARM_DESC(txselect,
Expand Down Expand Up @@ -6194,7 +6194,7 @@ static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
}

/* handle the txselect parameter changing */
static int setup_txselect(const char *str, struct kernel_param *kp)
static int setup_txselect(const char *str, const struct kernel_param *kp)
{
struct qib_devdata *dd;
unsigned long val;
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/ulp/srpt/ib_srpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module_param(srpt_srq_size, int, 0444);
MODULE_PARM_DESC(srpt_srq_size,
"Shared receive queue (SRQ) size.");

static int srpt_get_u64_x(char *buffer, struct kernel_param *kp)
static int srpt_get_u64_x(char *buffer, const struct kernel_param *kp)
{
return sprintf(buffer, "0x%016llx", *(u64 *)kp->arg);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/hardware/mISDN/avmfritz.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ _set_debug(struct fritzcard *card)
}

static int
set_debug(const char *val, struct kernel_param *kp)
set_debug(const char *val, const struct kernel_param *kp)
{
int ret;
struct fritzcard *card;
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/hardware/mISDN/mISDNinfineon.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ _set_debug(struct inf_hw *card)
}

static int
set_debug(const char *val, struct kernel_param *kp)
set_debug(const char *val, const struct kernel_param *kp)
{
int ret;
struct inf_hw *card;
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/hardware/mISDN/netjet.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ _set_debug(struct tiger_hw *card)
}

static int
set_debug(const char *val, struct kernel_param *kp)
set_debug(const char *val, const struct kernel_param *kp)
{
int ret;
struct tiger_hw *card;
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/hardware/mISDN/speedfax.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ _set_debug(struct sfax_hw *card)
}

static int
set_debug(const char *val, struct kernel_param *kp)
set_debug(const char *val, const struct kernel_param *kp)
{
int ret;
struct sfax_hw *card;
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/hardware/mISDN/w6692.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ _set_debug(struct w6692_hw *card)
}

static int
set_debug(const char *val, struct kernel_param *kp)
set_debug(const char *val, const struct kernel_param *kp)
{
int ret;
struct w6692_hw *card;
Expand Down
6 changes: 3 additions & 3 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -5100,7 +5100,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
return NULL;
}

static int add_named_array(const char *val, struct kernel_param *kp)
static int add_named_array(const char *val, const struct kernel_param *kp)
{
/* val must be "md_*" where * is not all digits.
* We allocate an array with a large free minor number, and
Expand Down Expand Up @@ -9330,11 +9330,11 @@ static __exit void md_exit(void)
subsys_initcall(md_init);
module_exit(md_exit)

static int get_ro(char *buffer, struct kernel_param *kp)
static int get_ro(char *buffer, const struct kernel_param *kp)
{
return sprintf(buffer, "%d", start_readonly);
}
static int set_ro(const char *val, struct kernel_param *kp)
static int set_ro(const char *val, const struct kernel_param *kp)
{
return kstrtouint(val, 10, (unsigned int *)&start_readonly);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/media/usb/uvc/uvc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2202,15 +2202,15 @@ static int uvc_reset_resume(struct usb_interface *intf)
* Module parameters
*/

static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
static int uvc_clock_param_get(char *buffer, const struct kernel_param *kp)
{
if (uvc_clock_param == CLOCK_MONOTONIC)
return sprintf(buffer, "CLOCK_MONOTONIC");
else
return sprintf(buffer, "CLOCK_REALTIME");
}

static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
static int uvc_clock_param_set(const char *val, const struct kernel_param *kp)
{
if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
val += strlen("clock_");
Expand Down
4 changes: 2 additions & 2 deletions drivers/message/fusion/mptbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module_param(mpt_channel_mapping, int, 0);
MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");

static int mpt_debug_level;
static int mpt_set_debug_level(const char *val, struct kernel_param *kp);
static int mpt_set_debug_level(const char *val, const struct kernel_param *kp);
module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
&mpt_debug_level, 0600);
MODULE_PARM_DESC(mpt_debug_level,
Expand Down Expand Up @@ -242,7 +242,7 @@ pci_enable_io_access(struct pci_dev *pdev)
pci_write_config_word(pdev, PCI_COMMAND, command_reg);
}

static int mpt_set_debug_level(const char *val, struct kernel_param *kp)
static int mpt_set_debug_level(const char *val, const struct kernel_param *kp)
{
int ret = param_set_int(val, kp);
MPT_ADAPTER *ioc;
Expand Down
3 changes: 2 additions & 1 deletion drivers/misc/kgdbts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,8 @@ static void kgdbts_put_char(u8 chr)
ts.run_test(0, chr);
}

static int param_set_kgdbts_var(const char *kmessage, struct kernel_param *kp)
static int param_set_kgdbts_var(const char *kmessage,
const struct kernel_param *kp)
{
size_t len = strlen(kmessage);

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/devices/block2mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static int block2mtd_setup2(const char *val)
}


static int block2mtd_setup(const char *val, struct kernel_param *kp)
static int block2mtd_setup(const char *val, const struct kernel_param *kp)
{
#ifdef MODULE
return block2mtd_setup2(val);
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/devices/phram.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static int phram_setup(const char *val)
return ret;
}

static int phram_param_call(const char *val, struct kernel_param *kp)
static int phram_param_call(const char *val, const struct kernel_param *kp)
{
#ifdef MODULE
return phram_setup(val);
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/ubi/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ static int __init bytes_str_to_int(const char *str)
* This function returns zero in case of success and a negative error code in
* case of error.
*/
static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
static int __init ubi_mtd_param_parse(const char *val, const struct kernel_param *kp)
{
int i, len;
struct mtd_dev_param *p;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/wcnss/wcnss_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ EXPORT_SYMBOL(wcnss_get_wlan_mac_address);
static int enable_wcnss_suspend_notify;

static int enable_wcnss_suspend_notify_set(const char *val,
struct kernel_param *kp)
const struct kernel_param *kp)
{
int ret;

Expand Down
5 changes: 3 additions & 2 deletions drivers/pci/pcie/aspm.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@ void pci_disable_link_state(struct pci_dev *pdev, int state)
}
EXPORT_SYMBOL(pci_disable_link_state);

static int pcie_aspm_set_policy(const char *val, struct kernel_param *kp)
static int pcie_aspm_set_policy(const char *val,
const struct kernel_param *kp)
{
int i;
struct pcie_link_state *link;
Expand All @@ -799,7 +800,7 @@ static int pcie_aspm_set_policy(const char *val, struct kernel_param *kp)
return 0;
}

static int pcie_aspm_get_policy(char *buffer, struct kernel_param *kp)
static int pcie_aspm_get_policy(char *buffer, const struct kernel_param *kp)
{
int i, cnt = 0;
for (i = 0; i < ARRAY_SIZE(policy_str); i++)
Expand Down
2 changes: 1 addition & 1 deletion drivers/platform/x86/thinkpad_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -9247,7 +9247,7 @@ static struct ibm_init_struct ibms_init[] __initdata = {
},
};

static int __init set_ibm_param(const char *val, struct kernel_param *kp)
static int __init set_ibm_param(const char *val, const struct kernel_param *kp)
{
unsigned int i;
struct ibm_struct *ibm;
Expand Down
Loading

0 comments on commit 55b75ea

Please sign in to comment.