Skip to content

Commit

Permalink
net: netxen: correct sysfs bin attribute return code
Browse files Browse the repository at this point in the history
If read() syscall requests unexpected number of bytes from "dimm" binary
attribute file, return EINVAL instead of EPERM.

At the same time pin down sysfs file size to the fixed
sizeof(struct netxen_dimm_cfg), which allows to exploit some missing
sanity checks from kernfs (file boundary checks vs offset etc.)

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vladimir Zapolskiy authored and David S. Miller committed May 27, 2015
1 parent 082739a commit 748a729
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3025,9 +3025,9 @@ netxen_sysfs_read_dimm(struct file *filp, struct kobject *kobj,
u8 dw, rows, cols, banks, ranks;
u32 val;

if (size != sizeof(struct netxen_dimm_cfg)) {
if (size < attr->size) {
netdev_err(netdev, "Invalid size\n");
return -1;
return -EINVAL;
}

memset(&dimm, 0, sizeof(struct netxen_dimm_cfg));
Expand Down Expand Up @@ -3137,7 +3137,7 @@ netxen_sysfs_read_dimm(struct file *filp, struct kobject *kobj,

static struct bin_attribute bin_attr_dimm = {
.attr = { .name = "dimm", .mode = (S_IRUGO | S_IWUSR) },
.size = 0,
.size = sizeof(struct netxen_dimm_cfg),
.read = netxen_sysfs_read_dimm,
};

Expand Down

0 comments on commit 748a729

Please sign in to comment.