Skip to content

Commit

Permalink
sysfs: add struct file* to bin_attr callbacks
Browse files Browse the repository at this point in the history
This allows bin_attr->read,write,mmap callbacks to check file specific data
(such as inode owner) as part of any privilege validation.

Signed-off-by: Chris Wright <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
chriswright authored and gregkh committed May 21, 2010
1 parent 68d75ed commit 2c3c8be
Show file tree
Hide file tree
Showing 52 changed files with 220 additions and 149 deletions.
8 changes: 5 additions & 3 deletions arch/alpha/kernel/pci-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ static int __pci_mmap_fits(struct pci_dev *pdev, int num,

/**
* pci_mmap_resource - map a PCI resource into user memory space
* @filp: open sysfs file
* @kobj: kobject for mapping
* @attr: struct bin_attribute for the file being mapped
* @vma: struct vm_area_struct passed into the mmap
* @sparse: address space type
*
* Use the bus mapping routines to map a PCI resource into userspace.
*/
static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
static int pci_mmap_resource(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
struct vm_area_struct *vma, int sparse)
{
struct pci_dev *pdev = to_pci_dev(container_of(kobj,
Expand Down Expand Up @@ -89,14 +91,14 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
return hose_mmap_page_range(pdev->sysdata, vma, mmap_type, sparse);
}

static int pci_mmap_resource_sparse(struct kobject *kobj,
static int pci_mmap_resource_sparse(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
struct vm_area_struct *vma)
{
return pci_mmap_resource(kobj, attr, vma, 1);
}

static int pci_mmap_resource_dense(struct kobject *kobj,
static int pci_mmap_resource_dense(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
struct vm_area_struct *vma)
{
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/txx9/generic/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ struct txx9_sramc_sysdev {
void __iomem *base;
};

static ssize_t txx9_sram_read(struct kobject *kobj,
static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
Expand All @@ -920,7 +920,7 @@ static ssize_t txx9_sram_read(struct kobject *kobj,
return size;
}

static ssize_t txx9_sram_write(struct kobject *kobj,
static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/sysdev/mv64x60_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define MV64X60_VAL_LEN_MAX 11
#define MV64X60_PCICFG_CPCI_HOTSWAP 0x68

static ssize_t mv64x60_hs_reg_read(struct kobject *kobj,
static ssize_t mv64x60_hs_reg_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t off, size_t count)
{
Expand All @@ -45,7 +45,7 @@ static ssize_t mv64x60_hs_reg_read(struct kobject *kobj,
return sprintf(buf, "0x%08x\n", v);
}

static ssize_t mv64x60_hs_reg_write(struct kobject *kobj,
static ssize_t mv64x60_hs_reg_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t off, size_t count)
{
Expand Down
14 changes: 8 additions & 6 deletions arch/s390/kernel/ipl.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ static ssize_t sys_ipl_device_show(struct kobject *kobj,
static struct kobj_attribute sys_ipl_device_attr =
__ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);

static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t off, size_t count)
{
return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
IPL_PARMBLOCK_SIZE);
Expand All @@ -419,8 +420,9 @@ static struct bin_attribute ipl_parameter_attr = {
.read = &ipl_parameter_read,
};

static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t off, size_t count)
{
unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
Expand Down Expand Up @@ -694,7 +696,7 @@ static struct kobj_attribute sys_reipl_ccw_vmparm_attr =

/* FCP reipl device attributes */

static ssize_t reipl_fcp_scpdata_read(struct kobject *kobj,
static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
Expand All @@ -704,7 +706,7 @@ static ssize_t reipl_fcp_scpdata_read(struct kobject *kobj,
return memory_read_from_buffer(buf, count, &off, scp_data, size);
}

static ssize_t reipl_fcp_scpdata_write(struct kobject *kobj,
static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct acpi_table_attr {
struct list_head node;
};

static ssize_t acpi_table_show(struct kobject *kobj,
static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buf,
loff_t offset, size_t count)
{
Expand Down
11 changes: 7 additions & 4 deletions drivers/base/firmware_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ static ssize_t firmware_loading_store(struct device *dev,
static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);

static ssize_t
firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buffer, loff_t offset, size_t count)
firmware_data_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buffer, loff_t offset,
size_t count)
{
struct device *dev = to_dev(kobj);
struct firmware_priv *fw_priv = dev_get_drvdata(dev);
Expand Down Expand Up @@ -362,6 +363,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)

/**
* firmware_data_write - write method for firmware
* @filp: open sysfs file
* @kobj: kobject for the device
* @bin_attr: bin_attr structure
* @buffer: buffer being written
Expand All @@ -372,8 +374,9 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
* the driver as a firmware image.
**/
static ssize_t
firmware_data_write(struct kobject *kobj, struct bin_attribute *bin_attr,
char *buffer, loff_t offset, size_t count)
firmware_data_write(struct file* filp, struct kobject *kobj,
struct bin_attribute *bin_attr, char *buffer,
loff_t offset, size_t count)
{
struct device *dev = to_dev(kobj);
struct firmware_priv *fw_priv = dev_get_drvdata(dev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/firmware/dcdbas.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
return count;
}

static ssize_t smi_data_read(struct kobject *kobj,
static ssize_t smi_data_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t count)
{
Expand All @@ -162,7 +162,7 @@ static ssize_t smi_data_read(struct kobject *kobj,
return ret;
}

static ssize_t smi_data_write(struct kobject *kobj,
static ssize_t smi_data_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t count)
{
Expand Down
10 changes: 5 additions & 5 deletions drivers/firmware/dell_rbu.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
rbu_data.image_update_buffer, rbu_data.bios_image_size);
}

static ssize_t read_rbu_data(struct kobject *kobj,
static ssize_t read_rbu_data(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t count)
{
Expand Down Expand Up @@ -576,7 +576,7 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
release_firmware(fw);
}

static ssize_t read_rbu_image_type(struct kobject *kobj,
static ssize_t read_rbu_image_type(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t count)
{
Expand All @@ -586,7 +586,7 @@ static ssize_t read_rbu_image_type(struct kobject *kobj,
return size;
}

static ssize_t write_rbu_image_type(struct kobject *kobj,
static ssize_t write_rbu_image_type(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t count)
{
Expand Down Expand Up @@ -647,7 +647,7 @@ static ssize_t write_rbu_image_type(struct kobject *kobj,
return rc;
}

static ssize_t read_rbu_packet_size(struct kobject *kobj,
static ssize_t read_rbu_packet_size(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t count)
{
Expand All @@ -660,7 +660,7 @@ static ssize_t read_rbu_packet_size(struct kobject *kobj,
return size;
}

static ssize_t write_rbu_packet_size(struct kobject *kobj,
static ssize_t write_rbu_packet_size(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buffer, loff_t pos, size_t count)
{
Expand Down
4 changes: 2 additions & 2 deletions drivers/firmware/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ efivar_unregister(struct efivar_entry *var)
}


static ssize_t efivar_create(struct kobject *kobj,
static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t count)
{
Expand Down Expand Up @@ -461,7 +461,7 @@ static ssize_t efivar_create(struct kobject *kobj,
return count;
}

static ssize_t efivar_delete(struct kobject *kobj,
static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t count)
{
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/drm_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ static ssize_t enabled_show(struct device *device,
"disabled");
}

static ssize_t edid_show(struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
static ssize_t edid_show(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t off,
size_t count)
{
struct device *connector_dev = container_of(kobj, struct device, kobj);
struct drm_connector *connector = to_drm_connector(connector_dev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/misc/c2port/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ static ssize_t __c2port_read_flash_data(struct c2port_device *dev,
return nread;
}

static ssize_t c2port_read_flash_data(struct kobject *kobj,
static ssize_t c2port_read_flash_data(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buffer, loff_t offset, size_t count)
{
Expand Down Expand Up @@ -824,7 +824,7 @@ static ssize_t __c2port_write_flash_data(struct c2port_device *dev,
return nwrite;
}

static ssize_t c2port_write_flash_data(struct kobject *kobj,
static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buffer, loff_t offset, size_t count)
{
Expand Down
6 changes: 4 additions & 2 deletions drivers/misc/ds1682.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ static const struct attribute_group ds1682_group = {
/*
* User data attribute
*/
static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *attr,
static ssize_t ds1682_eeprom_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct i2c_client *client = kobj_to_i2c_client(kobj);
Expand All @@ -163,7 +164,8 @@ static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *at
return count;
}

static ssize_t ds1682_eeprom_write(struct kobject *kobj, struct bin_attribute *attr,
static ssize_t ds1682_eeprom_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct i2c_client *client = kobj_to_i2c_client(kobj);
Expand Down
6 changes: 4 additions & 2 deletions drivers/misc/eeprom/at24.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ static ssize_t at24_read(struct at24_data *at24,
return retval;
}

static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr,
static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct at24_data *at24;
Expand Down Expand Up @@ -395,7 +396,8 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
return retval;
}

static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr,
static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct at24_data *at24;
Expand Down
6 changes: 4 additions & 2 deletions drivers/misc/eeprom/at25.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ at25_ee_read(
}

static ssize_t
at25_bin_read(struct kobject *kobj, struct bin_attribute *bin_attr,
at25_bin_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct device *dev;
Expand Down Expand Up @@ -253,7 +254,8 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
}

static ssize_t
at25_bin_write(struct kobject *kobj, struct bin_attribute *bin_attr,
at25_bin_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct device *dev;
Expand Down
3 changes: 2 additions & 1 deletion drivers/misc/eeprom/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
mutex_unlock(&data->update_lock);
}

static ssize_t eeprom_read(struct kobject *kobj, struct bin_attribute *bin_attr,
static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj));
Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/eeprom/max6875.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
mutex_unlock(&data->update_lock);
}

static ssize_t max6875_read(struct kobject *kobj,
static ssize_t max6875_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
Expand Down
11 changes: 7 additions & 4 deletions drivers/net/netxen/netxen_nic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,8 @@ netxen_sysfs_validate_crb(struct netxen_adapter *adapter,
}

static ssize_t
netxen_sysfs_read_crb(struct kobject *kobj, struct bin_attribute *attr,
netxen_sysfs_read_crb(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
struct device *dev = container_of(kobj, struct device, kobj);
Expand All @@ -2587,7 +2588,8 @@ netxen_sysfs_read_crb(struct kobject *kobj, struct bin_attribute *attr,
}

static ssize_t
netxen_sysfs_write_crb(struct kobject *kobj, struct bin_attribute *attr,
netxen_sysfs_write_crb(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
struct device *dev = container_of(kobj, struct device, kobj);
Expand Down Expand Up @@ -2627,7 +2629,8 @@ netxen_sysfs_validate_mem(struct netxen_adapter *adapter,
}

static ssize_t
netxen_sysfs_read_mem(struct kobject *kobj, struct bin_attribute *attr,
netxen_sysfs_read_mem(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
struct device *dev = container_of(kobj, struct device, kobj);
Expand All @@ -2647,7 +2650,7 @@ netxen_sysfs_read_mem(struct kobject *kobj, struct bin_attribute *attr,
return size;
}

static ssize_t netxen_sysfs_write_mem(struct kobject *kobj,
static ssize_t netxen_sysfs_write_mem(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t offset, size_t size)
{
Expand Down
Loading

0 comments on commit 2c3c8be

Please sign in to comment.