Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3406425rwa; Tue, 23 Aug 2022 04:22:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6SdlJ4rZRLIhFv82PdOnimyicXRqh13dYdq8bsW5sWq/S6QJ9gHmR/t0Sni9c33e3DXzdj X-Received: by 2002:a05:6a00:1910:b0:52f:13d7:44c4 with SMTP id y16-20020a056a00191000b0052f13d744c4mr24234345pfi.32.1661253727977; Tue, 23 Aug 2022 04:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253727; cv=none; d=google.com; s=arc-20160816; b=JhcvAMrlsr3y6UUrP1FTBPtxtU94w8BovRQtjkJkbzL7R+YwVSNiO85wzHJCFigc3n Db7fk3aSlTEUcOwLtUkjxvMj0RweWxeNuuvneTSUBe96beLqbUDkDD8DPYhHJyZ8fIOh Dhbc9mjOy3jBXc6BK6Yp7BPbwhj+sqjybDKH0Wkt//rI2Qm5H3tyX+Qs/zOE3uC6XZ1J sVWQbKoAQlNOG+WJXBcaHKJtZd7JwllyGghh3IElqRhqlSQYZBOeeCODPOYQvBlIoxBG mw9jGj7vGfnmTTPDz0nCBxYKa79sdnoTy2n5J52HFIQliNVXtCh3Ab6bTLkE1uzYtvOg i8ZA== 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=U2x7E8tUNhVVAhtE0uqvNSpWfA1kg02L6h0X4GGZ4EU=; b=ImnASuyggL6qs+Qe3yPAI/pdSy0N3N7qRrqKlS68/rzlVH6EJUjfn+ATO3G8A9Mxx6 CHyHVGDtnmkOFM62iKd3nfaL+sw6aQQhHE0AtPA2gnw1aYR/u7yK4Lt2rigTk2mE8i+i 3EAAzZ8ZlN24wJ5jEtJL6XqsxgcOTzocIZaFb9QctlLEOVJfyGXBQw4Icn1T9DQFSw50 Y2YcxCv45oLWkSigJrp5Wjd2/XcnFuyyI6nINK3k4N4C8gSsf9lfpsgmnh+DXfBqfZ+z Dtz4Ee/60Ysr1W4dGV+CgwmNZfz8Qk2bZBdqimlR1e+RYiporjzi5VWpkiKsrocwxSRv 4D7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Sr9tz+qU; 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 h123-20020a636c81000000b0041c86b0597dsi15307869pgc.594.2022.08.23.04.21.56; Tue, 23 Aug 2022 04:22:07 -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=Sr9tz+qU; 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 S240828AbiHWJsP (ORCPT + 99 others); Tue, 23 Aug 2022 05:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352120AbiHWJp5 (ORCPT ); Tue, 23 Aug 2022 05:45:57 -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 B179F1183A; Tue, 23 Aug 2022 01:43:27 -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 4A971B81C55; Tue, 23 Aug 2022 08:43:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E102C433C1; Tue, 23 Aug 2022 08:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244206; bh=N33/0tyB2ogA33cfEjn1YFSkrKBa93ZvpLZceAjDIK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sr9tz+qURkG9hb7xT/xhgJTzfxslxPgwJHq4Ovsch+RuMxWX+2MJYFqxnwQpbAe+g PUCzBJN9tBiCoy8fHZWzKo7niJZlUJ7LZr8W14T4wbS7aqzQHDG4pyCRRLdflnS4qv 7+cT487EAC4VcB0Lp0pP201dCfIcVRpRW4gGErxY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xuan Zhuo , Jason Wang , "David S. Miller" Subject: [PATCH 5.15 056/244] virtio_net: fix memory leak inside XPD_TX with mergeable Date: Tue, 23 Aug 2022 10:23:35 +0200 Message-Id: <20220823080100.932689364@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: Xuan Zhuo commit 7a542bee27c6a57e45c33cbbdc963325fd6493af upstream. When we call xdp_convert_buff_to_frame() to get xdpf, if it returns NULL, we should check if xdp_page was allocated by xdp_linearize_page(). If it is newly allocated, it should be freed here alone. Just like any other "goto err_xdp". Fixes: 44fa2dbd4759 ("xdp: transition into using xdp_frame for ndo_xdp_xmit") Signed-off-by: Xuan Zhuo Acked-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/virtio_net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1017,8 +1017,11 @@ static struct sk_buff *receive_mergeable case XDP_TX: stats->xdp_tx++; xdpf = xdp_convert_buff_to_frame(&xdp); - if (unlikely(!xdpf)) + if (unlikely(!xdpf)) { + if (unlikely(xdp_page != page)) + put_page(xdp_page); goto err_xdp; + } err = virtnet_xdp_xmit(dev, 1, &xdpf, 0); if (unlikely(!err)) { xdp_return_frame_rx_napi(xdpf);