From patchwork Wed May 25 21:00:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1635659 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=Pmu2Ik30; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L7k5G3zXWz9sGF for ; Thu, 26 May 2022 07:01:38 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nty8L-0002jT-15; Wed, 25 May 2022 21:01:33 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nty8J-0002hF-29 for kernel-team@lists.ubuntu.com; Wed, 25 May 2022 21:01:31 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B307E3F1C1 for ; Wed, 25 May 2022 21:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1653512490; bh=TJ26xfJeC+VaVaNq1skJtjswA4eP409h+6EoYQGO9+c=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pmu2Ik30KQLYJbhIXt5s4mu2rM4yQSey3c8xeNaFXvY36gZfGVD0grWf/w5ZzFJxn TkvKP3YuI/DKwhU4mIvYglgXmz9fQxKjrz7bgg8i/bTNvTHSp4cmp/tXotH78WokWV 9p1yrOVwvZSaU/46HiL/mYPatDJ1rxrohLzndGaPHvhd7VOgyvIT4hBnXoKZM25Br+ eGUSjrPbSUvgHLNHx5Q81aX8hsppxkxMKeHacjOTJJUmyppSalQUFNhUxk07qG28xN C/U7WX2kiZr2kTxKq0CUTJRXZqJ8Kj2aMmOmaDTNQzUdy3hFCrNiZ4oqf3O+Sp7tWl 6MFnlxwgCGKRw== Received: by mail-ed1-f70.google.com with SMTP id j22-20020aa7ca56000000b0042bd3527f2aso553266edt.0 for ; Wed, 25 May 2022 14:01:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TJ26xfJeC+VaVaNq1skJtjswA4eP409h+6EoYQGO9+c=; b=o6Vr4hlJVnbSPGjA0j/jc0AAy1BGfEVVB/4R1M5Hpw96UYWKTpEUEtKjDmInK5DA6z onqhpl1WfZjaPfNTkfwRluv0Teph2KoFhS1NYRFzRG1ldL/9clAauhj0JmBeMVLtuoqe vCx4DtTeD22C1IEfhfs2BszoN426kzruBZ77lSUJBZ6/TxOF6Ijzrxu+ckCwi+W88i2U sQTw/3c/BMB7XICZkkp85RQS4d1Mwcygr1PwOmtKX7vNn/zkCj4rciv0FjZY3JYLv0r+ q6nhzn3xiylnMhcG6qgvFl7P5S2xnKJYrey/+4co+MPmKeiomifwwJH5i2aFh+Qt9IMv Jmag== X-Gm-Message-State: AOAM533YI55wTlNYFfCHUwV93Sa8pYsSaTKVxZypJDlMvzz9vTAiYJb4 CLkjFaicLrzuWtExTA4siyVjpnzshdwL/OxEPIq6rhYf44KlqcB4bHXaHRfQR2YDOlMHMELiotX lyFoaGRLuFbOcFF05SoDBG41Khf9pyTMsy5WeJUXpMg== X-Received: by 2002:a17:907:7b9f:b0:6ff:f87:f534 with SMTP id ne31-20020a1709077b9f00b006ff0f87f534mr5030036ejc.114.1653512490135; Wed, 25 May 2022 14:01:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuGx9MsJ/qC3a4wEzvbR2VwOUcJWlZuMmjxDCJzHVY03L9PhdZ4kltuuZoUUpkqmJtNO9FgA== X-Received: by 2002:a17:907:7b9f:b0:6ff:f87:f534 with SMTP id ne31-20020a1709077b9f00b006ff0f87f534mr5030024ejc.114.1653512489907; Wed, 25 May 2022 14:01:29 -0700 (PDT) Received: from localhost.localdomain ([176.218.65.129]) by smtp.gmail.com with ESMTPSA id z23-20020a1709060f1700b006f3ef214dd1sm8398403eji.55.2022.05.25.14.01.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 14:01:28 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Jammy] can: usb_8dev: usb_8dev_start_xmit(): fix double dev_kfree_skb() in error path Date: Thu, 26 May 2022 00:00:50 +0300 Message-Id: <20220525210050.1038369-6-cengiz.can@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220525210050.1038369-1-cengiz.can@canonical.com> References: <20220525210050.1038369-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Hangyu Hua There is no need to call dev_kfree_skb() when usb_submit_urb() fails because can_put_echo_skb() deletes original skb and can_free_echo_skb() deletes the cloned skb. Fixes: 0024d8ad1639 ("can: usb_8dev: Add support for USB2CAN interface from 8 devices") Link: https://lore.kernel.org/all/20220311080614.45229-1-hbh25y@gmail.com Cc: stable@vger.kernel.org Signed-off-by: Hangyu Hua Signed-off-by: Marc Kleine-Budde (cherry picked from commit 3d3925ff6433f98992685a9679613a2cc97f3ce2) CVE-2022-28388 Signed-off-by: Cengiz Can --- drivers/net/can/usb/usb_8dev.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c index d1b83bd1b3cb..d4c8f934a1ce 100644 --- a/drivers/net/can/usb/usb_8dev.c +++ b/drivers/net/can/usb/usb_8dev.c @@ -670,9 +670,20 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, atomic_inc(&priv->active_tx_urbs); err = usb_submit_urb(urb, GFP_ATOMIC); - if (unlikely(err)) - goto failed; - else if (atomic_read(&priv->active_tx_urbs) >= MAX_TX_URBS) + if (unlikely(err)) { + can_free_echo_skb(netdev, context->echo_index, NULL); + + usb_unanchor_urb(urb); + usb_free_coherent(priv->udev, size, buf, urb->transfer_dma); + + atomic_dec(&priv->active_tx_urbs); + + if (err == -ENODEV) + netif_device_detach(netdev); + else + netdev_warn(netdev, "failed tx_urb %d\n", err); + stats->tx_dropped++; + } else if (atomic_read(&priv->active_tx_urbs) >= MAX_TX_URBS) /* Slow down tx path */ netif_stop_queue(netdev); @@ -691,19 +702,6 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, return NETDEV_TX_BUSY; -failed: - can_free_echo_skb(netdev, context->echo_index, NULL); - - usb_unanchor_urb(urb); - usb_free_coherent(priv->udev, size, buf, urb->transfer_dma); - - atomic_dec(&priv->active_tx_urbs); - - if (err == -ENODEV) - netif_device_detach(netdev); - else - netdev_warn(netdev, "failed tx_urb %d\n", err); - nomembuf: usb_free_urb(urb);