Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp653637pxb; Tue, 5 Apr 2022 17:26:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPWpvyzG2ILchulM3wsF+BnhiPMSzaZTrqAc57R4svFs5f255gdUs2UZ//ZX7RXpNCBiLo X-Received: by 2002:a05:6402:6da:b0:3fd:cacb:f4b2 with SMTP id n26-20020a05640206da00b003fdcacbf4b2mr6164524edy.332.1649204817975; Tue, 05 Apr 2022 17:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204817; cv=none; d=google.com; s=arc-20160816; b=yYIATiiDAFNg/F/j70AryHIR6uPQ0H1w6A8/B+WoyMJDeekneQhpLR6QmjwCNuCoZ3 MmWR7Fn0mqAj/hO7xlbxWupuHIzSmLejUOVTsWryHUiyeKLNxSWi+W3oZCHFZiqRRDkY C9vg+Aav48RVdLd6gd6Nd7EPS2ZQ/imDyE6JnvgjKZo9seZXjnDO7O/3jxTiI4I+bwsE 36inu+wq79G7YvyKyFgE5xCDawYLuHum+MzN+KwitXpTTu45feIYdOofyKxLQm9eRNze E2JhPoGH6Mgo1ibCb7X5zwVgh5csVO0LwUL/3CTyBDfNGlKxWzCw0eWoJLMIKQi1pwyg ItKA== 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=GjmVd2pbos6MQLcayFP9v0Xs6oH1B2sGO+cUcMkhV7I=; b=DfyYlhwqH+d8+QpP4iNnd8hcHZsuS7bpGM8X0RDctMbWRUkK6AlcjFFB5tmez1ILhi pGFvt75FHF/A+foZ68hA0vPitP3jDGlVoSgUAQjdRHsAJdHC3uKmBSU/oj1BTwx/6xoG Eh+w13J5AFPVCkHufOwMDZM01/TCGU8C6NHeu/VPJ/G70EZ4VT5x8aG3SM0ry9GvfO7p GQ+KowDfqaP6JMbFDNLtFt5kk1mVfkQaZ2OeV8HH3imLPgWzZG6X/GC5PRmLSi2W4y7t Rb9qBtkYKSlXSF0n8kvp0vkbMviR7l7lUJwNJomQqA+L8hdypQvagAIU5iQBdtfUFgw0 AEbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BBZ33/xb"; 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 y13-20020a1709063a8d00b006df76385bc8si10237589ejd.104.2022.04.05.17.26.31; Tue, 05 Apr 2022 17:26:57 -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="BBZ33/xb"; 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 S1384306AbiDEOR6 (ORCPT + 99 others); Tue, 5 Apr 2022 10:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239046AbiDEJdU (ORCPT ); Tue, 5 Apr 2022 05:33:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4824E240AD; Tue, 5 Apr 2022 02:21:45 -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 D98C061574; Tue, 5 Apr 2022 09:21:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2EABC385A2; Tue, 5 Apr 2022 09:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150504; bh=fGvT3tGIHLpDdwH/2c4w009hCnw9IdZ34aVTsfYVZjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBZ33/xbvpsFl03zWA8RhcEPYYbedXxljSUpBpFGgUQWPLHQHDQyuw21tOwwZ6oBh r4+4lasODEwgsfSgnR8+KPPKQHGyXZmLaxvddJRJvjQuceYBQnDjhyZwBiUCS8IAOI 2wNjPvicfSJuruzLzczryjPS5qik+sRJiQI/drpI= 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.15 078/913] can: m_can: m_can_tx_handler(): fix use after free of skb Date: Tue, 5 Apr 2022 09:19:00 +0200 Message-Id: <20220405070342.161958767@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 @@ -1640,8 +1640,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; @@ -1658,6 +1656,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 {