Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp623307pxb; Tue, 5 Apr 2022 16:18:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTPLVvNSo2/KO43wfScmlN5TxfFooa7ptBLgwu2htisNi6j7TzB4LslGRrSoMOcldUo7QE X-Received: by 2002:a17:902:d506:b0:156:b9f5:647c with SMTP id b6-20020a170902d50600b00156b9f5647cmr5848235plg.17.1649200684645; Tue, 05 Apr 2022 16:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649200684; cv=none; d=google.com; s=arc-20160816; b=nJKp/bJYMBwOQwORz6nRL10q0CgaMN84EQxsJ+v01juwk8kKjvw2Q88sYUY0WV/yAq 4wFnm2aXvDpMe6Wp0Jk1l4o0FCW5fytIha7J5UMa68kmw2Up/wW2CuvwcjgmXQYYDAxf GtPtrV68orVz/XUxZteODlASl/cjjXZKPFnsHucI1lFPrBXegg+G19o1GcQxiYEDyVVW Y1XkWmEXqGasnlsjL7n6ZTkHoUKsaD5nmavbDHd47txQiq28tl29UE5YY7PeoSwgnlUb 9pldwgqFN9gLRD1Db68dHXik4rBj+DNOgbDH0xqLygy7Q1fYm0B0MGq1VrONsNfJKTlT kPrg== 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=Tpvobk/lCnbkNdFUxhdExzgPDciF5usfqKTmcx4w9Yk=; b=PcmMUdIoCgORLnlHd7F0G2GY0SKeTBUhneIKDmbSx9Vzik/8b7X0RS16qYMMeUskq/ RlfhRcI+Bn3LTtvELR9LyraVj8+6KQmROFDciZI3pxrAvMrBj5JmgIXBb0Nxmn7kBS0a XEeN1PBBfw8qdFZltg9INSQF/VSNH9nO+d1hmiyjs8PwQSMflTOJevWASGDSc9vrqG5j rqwKIykO8i1f1y7KR4oHRp4MUxn/FBozUCAfmT5ZOqzWCbROoj1RHBLMWkZ/BN+jocT3 Zux0UY4R+uit88MriIQZegmzdKgMBMzM9KNJGLyHyrVzVkT4RxYqCVQuj61P3QaL9clo ZUWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v2XvMjAZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r127-20020a632b85000000b003816043f13dsi14459124pgr.818.2022.04.05.16.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:18:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v2XvMjAZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 126AC19E394; Tue, 5 Apr 2022 16:02:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350303AbiDELDw (ORCPT + 99 others); Tue, 5 Apr 2022 07:03:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237368AbiDEIly (ORCPT ); Tue, 5 Apr 2022 04:41:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C72F0E; Tue, 5 Apr 2022 01:34:34 -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 ams.source.kernel.org (Postfix) with ESMTPS id DAF83B81B13; Tue, 5 Apr 2022 08:34:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 452D1C385A1; Tue, 5 Apr 2022 08:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147671; bh=7QIPirzYhAIxU7aqcCIeNw5pvLy/gyhtOOVlcBUUafE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v2XvMjAZv6BhiGvJLVhb9xdWR5JXjX8N0CUS2GrEi1EcP4bpD1P9J8Fy7neXOkWGG 5PeMkYW0lc+Om5BMaoEZlsdpYDlUEailkzDLnIWCPh8g2FrUh4SkD2wqs2GLtSxoGw UwUm0zZ/7qLPG/Anlqk5mOyJ+DpQEWNP3y6v8NNA= 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.16 0081/1017] can: m_can: m_can_tx_handler(): fix use after free of skb Date: Tue, 5 Apr 2022 09:16:34 +0200 Message-Id: <20220405070356.595452482@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 @@ -1633,8 +1633,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; @@ -1651,6 +1649,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 {