mctp i2c: Fix potential use-after-free
authorMatt Johnston <matt@codeconstruct.com.au>
Fri, 25 Feb 2022 05:39:37 +0000 (13:39 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 26 Feb 2022 06:23:29 +0000 (22:23 -0800)
The skb is handed off to netif_rx() which may free it.
Found by Smatch.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/mctp/mctp-i2c.c

index 365c3df..470682c 100644 (file)
@@ -338,7 +338,7 @@ static int mctp_i2c_recv(struct mctp_i2c_dev *midev)
 
        if (status == NET_RX_SUCCESS) {
                ndev->stats.rx_packets++;
-               ndev->stats.rx_bytes += skb->len;
+               ndev->stats.rx_bytes += recvlen;
        } else {
                ndev->stats.rx_dropped++;
        }