Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3334819rwa; Tue, 23 Aug 2022 03:04:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ciecoDibCu6dzPnvhdsevDm5dxJKMJKSTv8ByWSXbumY1/+keFigzEwemOITY5UThj+wX X-Received: by 2002:a05:6402:3210:b0:43d:20bc:5e4 with SMTP id g16-20020a056402321000b0043d20bc05e4mr2986765eda.276.1661249068903; Tue, 23 Aug 2022 03:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661249068; cv=none; d=google.com; s=arc-20160816; b=t0eGAERoHa98UhNy+iDVB8FdqsKIJTJPrRWzMHnVQsyTQWTu6aIT1z2RyufTDvjV6S ztqJQbUhq5WnHRookydTYcJi9cuUWrZAmlDrIBHKn9QbCS+m49vWexIwXNN/TohoEnIL +0SwvLgykQXd58d6x6gogrbkPHKaQUIheZnSK+/yCv695rpdCYCvmHllaLfhrDi96KSp F6r7MO42Kjn9y8WKZgxymg1XkpiSRkienpB+WST/zq2fB0wrEPmful8odJ2sI3dzKfVy AGlCMU3gLqo8DS+KAhXKxngjXyb07cg66COQ27zjcLjdZBrrv+ac6cvFe7c6vrnSTJDP Xikg== 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=FvHHKfmB8ObbNoFL1aLNAr+2qokVwUEywl5zQ/4/Sno=; b=RYQsWBr09DfNBIys/pu3IeUBqDQxmnr+xM8pU8jiyFN3naLAdjX8PWSjV63s9wcCx3 FIgdIkYr6Ml8lM9oIEGY7sedKKkvgq3uLnQenS/PYwNtG1OySgfkAonkpEV8H8rXS+mz aSP3NSXcUnMd7SjwLAUaEOYJqUXr1JbTrSCKoAjaOX5j6zt60CfekMsOdGIxhdlZTtu8 7czOdCxlKdBbF/qJ/auhv4fOyZ5r6N13sP6TauyFeQuThi2iHbB/NvFlxPQVMliAnU3y yCFRxP3qQfES3GInrPC7yt8j064d33d3o1Gb04TcRlDkFixFEx9bHkAKDihV/P6jmiGk GlYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1K5vHnHx; 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 m14-20020a50998e000000b00445f2dfacaasi1496452edb.614.2022.08.23.03.04.01; Tue, 23 Aug 2022 03:04:28 -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=1K5vHnHx; 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 S239685AbiHWJuK (ORCPT + 99 others); Tue, 23 Aug 2022 05:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241743AbiHWJr7 (ORCPT ); Tue, 23 Aug 2022 05:47:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE509719AE; Tue, 23 Aug 2022 01:44: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 ams.source.kernel.org (Postfix) with ESMTPS id 95065B81C55; Tue, 23 Aug 2022 08:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECFC0C433C1; Tue, 23 Aug 2022 08:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244230; bh=6RUbOO660W57gg9vcDPO2ChUAqzUiVW0WI9kwpLZkTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1K5vHnHxCrg9U5yyxVxdJnRNNaiCSpDSJJpVU6Fxqaa8vluvUGjGDUGVm6+eLmGti rygEk7BH2upVm6Mk67Y8nBjWm6sf3RkdxvjM5GURo1KB93Tb6d8wIDdjkvZkEaSY+m BI61DGLkUyG94Njjbm01WyrqrztBx+WYv50TVZlM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksij Rempel , Fedor Pchelkin , Alexey Khoroshilov , Marc Kleine-Budde Subject: [PATCH 5.15 050/244] can: j1939: j1939_session_destroy(): fix memory leak of skbs Date: Tue, 23 Aug 2022 10:23:29 +0200 Message-Id: <20220823080100.737215509@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 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: Fedor Pchelkin commit 8c21c54a53ab21842f5050fa090f26b03c0313d6 upstream. We need to drop skb references taken in j1939_session_skb_queue() when destroying a session in j1939_session_destroy(). Otherwise those skbs would be lost. Link to Syzkaller info and repro: https://forge.ispras.ru/issues/11743. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. V1: https://lore.kernel.org/all/20220708175949.539064-1-pchelkin@ispras.ru Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Suggested-by: Oleksij Rempel Signed-off-by: Fedor Pchelkin Signed-off-by: Alexey Khoroshilov Acked-by: Oleksij Rempel Link: https://lore.kernel.org/all/20220805150216.66313-1-pchelkin@ispras.ru Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/j1939/transport.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -260,6 +260,8 @@ static void __j1939_session_drop(struct static void j1939_session_destroy(struct j1939_session *session) { + struct sk_buff *skb; + if (session->transmission) { if (session->err) j1939_sk_errqueue(session, J1939_ERRQUEUE_TX_ABORT); @@ -274,7 +276,11 @@ static void j1939_session_destroy(struct WARN_ON_ONCE(!list_empty(&session->sk_session_queue_entry)); WARN_ON_ONCE(!list_empty(&session->active_session_list_entry)); - skb_queue_purge(&session->skb_queue); + while ((skb = skb_dequeue(&session->skb_queue)) != NULL) { + /* drop ref taken in j1939_session_skb_queue() */ + skb_unref(skb); + kfree_skb(skb); + } __j1939_session_drop(session); j1939_priv_put(session->priv); kfree(session);