Skip to content

Commit

Permalink
niu: Fix kernel buffer overflow for ETHTOOL_GRXCLSRLALL
Browse files Browse the repository at this point in the history
commit ee9c5cf upstream.

niu_get_ethtool_tcam_all() assumes that its output buffer is the right
size, and warns before returning if it is not.  However, the output
buffer size is under user control and ETHTOOL_GRXCLSRLALL is an
unprivileged ethtool command.  Therefore this is at least a local
denial-of-service vulnerability.

Change it to check before writing each entry and to return an error if
the buffer is already full.

Compile-tested only.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
  • Loading branch information
Ben Hutchings authored and Paul Gortmaker committed Apr 17, 2011
1 parent 40b77a7 commit 6a6c24b
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions drivers/net/niu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7263,32 +7263,28 @@ static int niu_get_ethtool_tcam_all(struct niu *np,
struct niu_parent *parent = np->parent;
struct niu_tcam_entry *tp;
int i, idx, cnt;
u16 n_entries;
unsigned long flags;

int ret = 0;

/* put the tcam size here */
nfc->data = tcam_get_size(np);

niu_lock_parent(np, flags);
n_entries = nfc->rule_cnt;
for (cnt = 0, i = 0; i < nfc->data; i++) {
idx = tcam_get_index(np, i);
tp = &parent->tcam[idx];
if (!tp->valid)
continue;
if (cnt == nfc->rule_cnt) {
ret = -EMSGSIZE;
break;
}
rule_locs[cnt] = i;
cnt++;
}
niu_unlock_parent(np, flags);

if (n_entries != cnt) {
/* print warning, this should not happen */
netdev_info(np->dev, "niu%d: In %s(): n_entries[%d] != cnt[%d]!!!\n",
np->parent->index, __func__, n_entries, cnt);
}

return 0;
return ret;
}

static int niu_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Expand Down

0 comments on commit 6a6c24b

Please sign in to comment.