Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2119667ioo; Mon, 23 May 2022 10:29:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/Yne4hAjvvLeZ0lhMAvbQGcLJZkCFAqboY1DgAqdvflTJKeZau/NaB+3qmFW7WmWXpBq/ X-Received: by 2002:a65:558e:0:b0:3f3:936a:7c1d with SMTP id j14-20020a65558e000000b003f3936a7c1dmr21521051pgs.600.1653326941810; Mon, 23 May 2022 10:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653326941; cv=none; d=google.com; s=arc-20160816; b=JKARbn+pP4w0oh9Ap6siVTj6dUZaRqOv0ixBQdW+ogLUIEWaLKHjxxe6aBXhGViVPO 1qtBJIK95bDCSd8qfkPwOfrRMzOQtXwM2f+m+KPHR2NAUaLoWW6rQIIfuUFAJrJV1poJ /PfxAA8MEOhRVK4WOwxVtHFUzOiRm7wjHH/I1CiMudSg5PC1txKfwUll06QIdLaAOMo2 YRZFqdF1wXnh/utcNNTyztxKMotUMsWhr2pudkqbOBOvBf86QDZ1tkQBjGWxPm9/kP5x aej5vIp2iOKv5aV3fYVadVg1vyoWeLiLV3gxGAoCD5TSnQJqLg9ViyI4u2P2EPjofcav ukdw== 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=Dra+OUDv8fkhsHgIZROBEVerjX5KPLeDi3CgXl8qrOY=; b=owQnU8VtLVr8463BYSxBnQya+8Ue7N3F2hep6wmtDkbkBb0+nx+tKO5x/Q3MeY0gpS OBPF1uTa6KAT8zubJORrsPmvz32rCTE06oEJFvlJu6dQiawAPqTTZ7PIOP4gp232+z3D Mk9pCyZ71GWMMdjP65uIGzjEYSdzMGLqKnXHeDQUYFVf92mtjOk1a6lh7MHXed8agk1X VJ8A/EFKNvftSQd2TIBQv2x0du+gvzXFaKwy0fUZ1mREhiuc/idOlU6bxfaQT9uavuBM tmVQQbO9VvT+bRRHO9TJE99QVjatsvASPhXSbDItXt3oANiz75doI591dyxSQpMYnpBs caFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J+RKUMKs; 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 s18-20020a656452000000b003f2470e2702si10538597pgv.594.2022.05.23.10.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:29:01 -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=J+RKUMKs; 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 C5D6D82172; Mon, 23 May 2022 10:28:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240087AbiEWRZS (ORCPT + 99 others); Mon, 23 May 2022 13:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240686AbiEWRQk (ORCPT ); Mon, 23 May 2022 13:16:40 -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 72150252A8; Mon, 23 May 2022 10:16:23 -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 7FAD3B8120F; Mon, 23 May 2022 17:13:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D18EBC385A9; Mon, 23 May 2022 17:13:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326005; bh=SwZZ1wBIYlC9EHPI5vWZ3DJXkxhGGuW+aePkTfWxLZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+RKUMKsXpocYWY+mkTzl6qUGpmWScxclvUHPVr3BgzsLrW8Wr9LxR4ouTl+L5Ukd JAWUAw2O5AgCtd5EvyQypDJktE+xpMbqr/gOiSoje3ks4gl2eP3qfAnnSVzqJsrJvv eFG1qeGfygZxxbz/t+b7DivoXYAJU0dV0b2DWslM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TOTE Robot , Zixuan Fu , Paolo Abeni , Sasha Levin Subject: [PATCH 5.4 38/68] net: vmxnet3: fix possible use-after-free bugs in vmxnet3_rq_alloc_rx_buf() Date: Mon, 23 May 2022 19:05:05 +0200 Message-Id: <20220523165808.887724578@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@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.6 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=unavailable 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: Zixuan Fu [ Upstream commit 9e7fef9521e73ca8afd7da9e58c14654b02dfad8 ] In vmxnet3_rq_alloc_rx_buf(), when dma_map_single() fails, rbi->skb is freed immediately. Similarly, in another branch, when dma_map_page() fails, rbi->page is also freed. In the two cases, vmxnet3_rq_alloc_rx_buf() returns an error to its callers vmxnet3_rq_init() -> vmxnet3_rq_init_all() -> vmxnet3_activate_dev(). Then vmxnet3_activate_dev() calls vmxnet3_rq_cleanup_all() in error handling code, and rbi->skb or rbi->page are freed again in vmxnet3_rq_cleanup_all(), causing use-after-free bugs. To fix these possible bugs, rbi->skb and rbi->page should be cleared after they are freed. The error log in our fault-injection testing is shown as follows: [ 14.319016] BUG: KASAN: use-after-free in consume_skb+0x2f/0x150 ... [ 14.321586] Call Trace: ... [ 14.325357] consume_skb+0x2f/0x150 [ 14.325671] vmxnet3_rq_cleanup_all+0x33a/0x4e0 [vmxnet3] [ 14.326150] vmxnet3_activate_dev+0xb9d/0x2ca0 [vmxnet3] [ 14.326616] vmxnet3_open+0x387/0x470 [vmxnet3] ... [ 14.361675] Allocated by task 351: ... [ 14.362688] __netdev_alloc_skb+0x1b3/0x6f0 [ 14.362960] vmxnet3_rq_alloc_rx_buf+0x1b0/0x8d0 [vmxnet3] [ 14.363317] vmxnet3_activate_dev+0x3e3/0x2ca0 [vmxnet3] [ 14.363661] vmxnet3_open+0x387/0x470 [vmxnet3] ... [ 14.367309] [ 14.367412] Freed by task 351: ... [ 14.368932] __dev_kfree_skb_any+0xd2/0xe0 [ 14.369193] vmxnet3_rq_alloc_rx_buf+0x71e/0x8d0 [vmxnet3] [ 14.369544] vmxnet3_activate_dev+0x3e3/0x2ca0 [vmxnet3] [ 14.369883] vmxnet3_open+0x387/0x470 [vmxnet3] [ 14.370174] __dev_open+0x28a/0x420 [ 14.370399] __dev_change_flags+0x192/0x590 [ 14.370667] dev_change_flags+0x7a/0x180 [ 14.370919] do_setlink+0xb28/0x3570 [ 14.371150] rtnl_newlink+0x1160/0x1740 [ 14.371399] rtnetlink_rcv_msg+0x5bf/0xa50 [ 14.371661] netlink_rcv_skb+0x1cd/0x3e0 [ 14.371913] netlink_unicast+0x5dc/0x840 [ 14.372169] netlink_sendmsg+0x856/0xc40 [ 14.372420] ____sys_sendmsg+0x8a7/0x8d0 [ 14.372673] __sys_sendmsg+0x1c2/0x270 [ 14.372914] do_syscall_64+0x41/0x90 [ 14.373145] entry_SYSCALL_64_after_hwframe+0x44/0xae ... Fixes: 5738a09d58d5a ("vmxnet3: fix checks for dma mapping errors") Reported-by: TOTE Robot Signed-off-by: Zixuan Fu Link: https://lore.kernel.org/r/20220514050656.2636588-1-r33s3n6@gmail.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/vmxnet3/vmxnet3_drv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index cf090f88dac0..b71a019e9867 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -595,6 +595,7 @@ vmxnet3_rq_alloc_rx_buf(struct vmxnet3_rx_queue *rq, u32 ring_idx, if (dma_mapping_error(&adapter->pdev->dev, rbi->dma_addr)) { dev_kfree_skb_any(rbi->skb); + rbi->skb = NULL; rq->stats.rx_buf_alloc_failure++; break; } @@ -619,6 +620,7 @@ vmxnet3_rq_alloc_rx_buf(struct vmxnet3_rx_queue *rq, u32 ring_idx, if (dma_mapping_error(&adapter->pdev->dev, rbi->dma_addr)) { put_page(rbi->page); + rbi->page = NULL; rq->stats.rx_buf_alloc_failure++; break; } -- 2.35.1