Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp666122pxb; Tue, 5 Apr 2022 17:57:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrW9i89lfxjke2HViGomki/viKdNzyqBeI0nkLBzf4J1mcT/UDxHXXPONWmL0MAx/BNsDj X-Received: by 2002:a17:907:6e08:b0:6e7:f074:e41d with SMTP id sd8-20020a1709076e0800b006e7f074e41dmr5909447ejc.164.1649206673140; Tue, 05 Apr 2022 17:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206673; cv=none; d=google.com; s=arc-20160816; b=PHfX27u3m3d/u1yO8Bla+xI9xvfonyLGG0eJMZN0SMYveUfN85bFPpKER/IOkc6BGY oVqIPekxK1zAQ8Dep9utmEUC7H2fO2yiesD9+ldW4t5I5meAAqqm01Zv7/yuYDj+c2/9 sqqk1EaHwWSGCoavD9kcq//tjs3D5GNyMLoOYZmLHY/lHO8KtPtvmza33W2pmzFqT3/U yWYBggceTb26RGTosYgoYR0lwCGx57Q/MJY7+sSaRlQOH1c6nwC/zXEV+dCThTLUlH5O JJWyMDHks3/JrlrBv4HsGgiukwsDSnaXtfw70p4J9lXLue9nuEUARKjoOK6WUbtN3ccn kIQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uietf5HmBIlQ3u5XQUNi4RvP104wbIhrk8oAAdWJsYs=; b=vvKsKJWJEtODbgrD7FTP2yIyXPKgDSXFcIJcHfoQTz3yfAc2G1Ze8MlgWBRToAwmOl 2ogppAJUdgN36nxvoPGMGb3+s3zVOqhqyWSQeSlm3hWVUWFRWicmoYjEhmflpJVJjeFR haVt0hKfpu0Y21urlHr3bo7ShL1FqsnYcGhwtyGkmvrOplkNuvzOgIjslArfMo4OpgRx 911dmQnCVoPksJRy697lv4xBFIDvGdN3qA7xmGOVwN/hhMZsum84HDkfVOEyfJ3kq4yQ d8EbA/m8nMTm+60zcZVOozAH8A/ZZbiD6ul+tNlSZXu/7VRw8hqkXgrypqQJI7fnaK27 EF1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VUR8F+03; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r5-20020a17090638c500b006df76385eeasi10151014ejd.906.2022.04.05.17.57.26; Tue, 05 Apr 2022 17:57:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VUR8F+03; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235724AbiDEIAM (ORCPT + 99 others); Tue, 5 Apr 2022 04:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232222AbiDEHqY (ORCPT ); Tue, 5 Apr 2022 03:46:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C5CD91575; Tue, 5 Apr 2022 00:41:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ABF0E616BF; Tue, 5 Apr 2022 07:41:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3288C340EE; Tue, 5 Apr 2022 07:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144510; bh=KyZf93NRYG3rY0HD/xfdlLYH1p0gb15sYRO1eP/35AE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VUR8F+03vVpsyc8a6swCv75CLTrszGQBG7OnyxUVyFG08DVPTCN4uhRtaF7Kk4gS2 L9N5mND3GNvTQM4eilgsE7182OoFqxT7fLGz2abt1bov1a/ARzQOMrldCDzYhIyQ5k KIIpMV1YvzuK7eFaAf0rrEEqDX1ar0+ZKQQuh3y4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Marc Kleine-Budde Subject: [PATCH 5.17 0071/1126] can: m_can: m_can_tx_handler(): fix use after free of skb Date: Tue, 5 Apr 2022 09:13:38 +0200 Message-Id: <20220405070409.653874727@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Kleine-Budde commit 2e8e79c416aae1de224c0f1860f2e3350fa171f8 upstream. can_put_echo_skb() will clone skb then free the skb. Move the can_put_echo_skb() for the m_can version 3.0.x directly before the start of the xmit in hardware, similar to the 3.1.x branch. Fixes: 80646733f11c ("can: m_can: update to support CAN FD features") Link: https://lore.kernel.org/all/20220317081305.739554-1-mkl@pengutronix.de Cc: stable@vger.kernel.org Reported-by: Hangyu Hua Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/m_can/m_can.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -1637,8 +1637,6 @@ static netdev_tx_t m_can_tx_handler(stru if (err) goto out_fail; - can_put_echo_skb(skb, dev, 0, 0); - if (cdev->can.ctrlmode & CAN_CTRLMODE_FD) { cccr = m_can_read(cdev, M_CAN_CCCR); cccr &= ~CCCR_CMR_MASK; @@ -1655,6 +1653,9 @@ static netdev_tx_t m_can_tx_handler(stru m_can_write(cdev, M_CAN_CCCR, cccr); } m_can_write(cdev, M_CAN_TXBTIE, 0x1); + + can_put_echo_skb(skb, dev, 0, 0); + m_can_write(cdev, M_CAN_TXBAR, 0x1); /* End of xmit function for version 3.0.x */ } else {