Skip to content

Commit ee9c5cf

Browse files
Ben Hutchingsdavem330
authored andcommitted
niu: Fix kernel buffer overflow for ETHTOOL_GRXCLSRLALL
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>
1 parent 6523ce1 commit ee9c5cf

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

drivers/net/niu.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,32 +7272,28 @@ static int niu_get_ethtool_tcam_all(struct niu *np,
72727272
struct niu_parent *parent = np->parent;
72737273
struct niu_tcam_entry *tp;
72747274
int i, idx, cnt;
7275-
u16 n_entries;
72767275
unsigned long flags;
7277-
7276+
int ret = 0;
72787277

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

72827281
niu_lock_parent(np, flags);
7283-
n_entries = nfc->rule_cnt;
72847282
for (cnt = 0, i = 0; i < nfc->data; i++) {
72857283
idx = tcam_get_index(np, i);
72867284
tp = &parent->tcam[idx];
72877285
if (!tp->valid)
72887286
continue;
7287+
if (cnt == nfc->rule_cnt) {
7288+
ret = -EMSGSIZE;
7289+
break;
7290+
}
72897291
rule_locs[cnt] = i;
72907292
cnt++;
72917293
}
72927294
niu_unlock_parent(np, flags);
72937295

7294-
if (n_entries != cnt) {
7295-
/* print warning, this should not happen */
7296-
netdev_info(np->dev, "niu%d: In %s(): n_entries[%d] != cnt[%d]!!!\n",
7297-
np->parent->index, __func__, n_entries, cnt);
7298-
}
7299-
7300-
return 0;
7296+
return ret;
73017297
}
73027298

73037299
static int niu_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,

0 commit comments

Comments
 (0)