]> git.baikalelectronics.ru Git - kernel.git/commit
net: dsa: fix a crash if ->get_sset_count() fails
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 8 May 2021 13:30:35 +0000 (16:30 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 10 May 2021 21:31:27 +0000 (14:31 -0700)
commitd121d0f146c87c9af52f6054d0870ee0daa4f1fc
treedf38f4b1df1fadbf42b81a615c1f9d4e08a55406
parent3ac4fd9fb2b28ca18018fe7631aa957192cf66a2
net: dsa: fix a crash if ->get_sset_count() fails

If ds->ops->get_sset_count() fails then it "count" is a negative error
code such as -EOPNOTSUPP.  Because "i" is an unsigned int, the negative
error code is type promoted to a very high value and the loop will
corrupt memory until the system crashes.

Fix this by checking for error codes and changing the type of "i" to
just int.

Fixes: 08bd6238a547 ("net: dsa: Provide CPU port statistics to master netdev")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/master.c