Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4371251imw; Tue, 19 Jul 2022 05:31:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vyNabfE/crXgUQEaWGRCxsTQKq1ZZnA6mOpLYAnf+edzTZ7ANngPeNvID9UsQ4DmKOLfoD X-Received: by 2002:a05:6402:1e95:b0:437:ce7f:e17a with SMTP id f21-20020a0564021e9500b00437ce7fe17amr42601190edf.169.1658233912360; Tue, 19 Jul 2022 05:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233912; cv=none; d=google.com; s=arc-20160816; b=LxQigNGl+BsRoUcfdHJZXF/P2yfGASTSN/FkaoC5vlcHfNFpvvM6Muu60iMZ5vSs7C IYa9+Tw/TLQxAThorHJPXGogOFtx0bELHD33eDI5wx3+oFYAKU3pTdpRmneYJCZdQiWF /uZtxXtzHeUeYctsvg+/RjMNOB8nhYu6kbnSOjuskcrAdHZMxs67W81HLT3uOzvOkDAa A+Hh+iOGOIUeQkJFzYV/qcOR6An6UO2IzLTaVm+vRCOCWzpr2Zasgomt7l+kCLxKA2rO lMYvLCXS47NwZy0i6Z2lvhQ1HlP+VR4fBToxyu2I9JnGiVTd34bxyHy5c5eu+Js2OVt7 XCKg== 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=NDuiZVXX3R8GxLXjOjZ81vzbnWTZIdUBpCV8JidU87s=; b=H2Ui86OHDogDgAsREV58q/tQpuUNnHr3WCCgR9x+CISobUasWCm9qHNFR64IzOJmi7 PdVcxZQfUoa7G8WdpjVCkSoeMm9dw/YmZOq/0yvQ9fCQqYu+V10haoLxZKLi7qTxzFTs HBgQeM+w2qRHCz+Vfgotmwo1J5L2DXOfRdqQ/dElCiQI6h0AAOJyL+b9tolP8Jq/EVGd HhYRn/wLFzAwyI7jaSItuJMH6XZia+kXQXYFh2xyPvJ6JaVjawWRwLngFjEWru96ZW3K PxZUZ3JyZPf4SjA/H1j+hArEHJclMhnEdK5uOlX/pIOFVBGMcM4Eb1yOZ1oqVV4t/4b/ +NTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=elyxIlc4; 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 hc34-20020a17090716a200b0072edc70deb2si13938262ejc.624.2022.07.19.05.31.27; Tue, 19 Jul 2022 05:31:52 -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=elyxIlc4; 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 S238384AbiGSMHd (ORCPT + 99 others); Tue, 19 Jul 2022 08:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238374AbiGSMGp (ORCPT ); Tue, 19 Jul 2022 08:06:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FFCF4E608; Tue, 19 Jul 2022 05:01:07 -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 5A04CB81B2C; Tue, 19 Jul 2022 12:01:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B02B5C341C6; Tue, 19 Jul 2022 12:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232064; bh=/yrqfbRHLXgoUsJxyTlMWBqWwlFgWKUfcpZ8NX38z74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=elyxIlc4x5o7qBqXJmbW/2WOKW0QQh69eeIycVzRoJWh67OFTGUICXvVF1eSThXFz aiIljCqAa1oVbo/JQbLVbCbj66o2HkuS1Fl5cI9VVnLgXEFeZOtNCXs0OM4BtoDhqO vIZMYdvYE4vFn5zpY+3ULAr7mmyRayAmTIxh691c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Marc Kleine-Budde , Sudip Mukherjee Subject: [PATCH 4.19 48/48] can: m_can: m_can_tx_handler(): fix use after free of skb Date: Tue, 19 Jul 2022 13:54:25 +0200 Message-Id: <20220719114524.075476331@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114518.915546280@linuxfoundation.org> References: <20220719114518.915546280@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.8 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 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 [sudip: adjust context] Signed-off-by: Sudip Mukherjee 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 @@ -1438,8 +1438,6 @@ static netdev_tx_t m_can_start_xmit(stru M_CAN_FIFO_DATA(i / 4), *(u32 *)(cf->data + i)); - can_put_echo_skb(skb, dev, 0); - if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { cccr = m_can_read(priv, M_CAN_CCCR); cccr &= ~(CCCR_CMR_MASK << CCCR_CMR_SHIFT); @@ -1456,6 +1454,9 @@ static netdev_tx_t m_can_start_xmit(stru m_can_write(priv, M_CAN_CCCR, cccr); } m_can_write(priv, M_CAN_TXBTIE, 0x1); + + can_put_echo_skb(skb, dev, 0); + m_can_write(priv, M_CAN_TXBAR, 0x1); /* End of xmit function for version 3.0.x */ } else {