Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2111060ioo; Mon, 23 May 2022 10:16:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+imuWnS8KoqYx8DQmnfbi/JMsTSacAtITv5xTiEnYQ/+6pe8pkEHm4LB4prd7wuo2kTu4 X-Received: by 2002:a17:90b:1c8f:b0:1b8:c6dc:ca61 with SMTP id oo15-20020a17090b1c8f00b001b8c6dcca61mr36135pjb.13.1653326217994; Mon, 23 May 2022 10:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653326217; cv=none; d=google.com; s=arc-20160816; b=WRS5M6w1UwY8b2dPBy6DRexkwld17fBG2Gjnlub5xOORm0LdTye5AmnbrYnUZm+2rt K9Zg4lufZOtWsktNxbNCQ6MdmuTbgI052Cqx9+ZFB9uyzRRF3b2hBMbUhOH9vve+/oTL xXPFYifhbiK6+6fHFlcSY11OwL8Os+Jq5ZUcshrl/8cRzU7ZByVk1poD68tEE1enfoq/ pNdgG7FRX9Seqlrz7ULvTeFPdP4qTZgZPireIc+IOoAnr3qZU5uoVqOgQVYLabVsfbZx px9fZhGVYdicfBccFGIiVWQJYl3gj8mv6AmK13KcrTZ+t8oM5qGT6Y7+KulPcvLAgQuM pCIg== 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=Tt2KoybTnp0eWfnXuWR0y7fapYy7ypbgnQOHAmR69UQ=; b=WdZWgs4qMsetRTvCB6kiA6RNKN4VS8G4HHFTIrYXFgBmSn7wn/bygx/p1/oW1TH0A4 uVob/zdVVebi96+pdNQeAVDn48xCnUYd/TwFEEiYuWF0lBbnq272RPQCrvwyl1iTcDWZ e9HwKradxd7ecdDITzdNrVyk4plgw3c4tI/UkeeWVjv8YAIZfBiUwvk9k04qBoHMV8nI quMdOejN2oU2BCwBuDgO+dBoBcyiW6uh0Yp3sAnNnO9Waxa1823fP+a6sSrgKKfDVLS6 hWh85VPxLoyT5EXTnppciW4CknPbPavDDf7ndrtnxQHGRPdNtXer3TBs9DIfgR0298ZG sOBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GOn1DBM9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id g1-20020a056a001a0100b004fa3a8dff62si15909273pfv.25.2022.05.23.10.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:16:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GOn1DBM9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 E32366D4EB; Mon, 23 May 2022 10:15:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239799AbiEWRNC (ORCPT + 99 others); Mon, 23 May 2022 13:13:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239797AbiEWRKt (ORCPT ); Mon, 23 May 2022 13:10:49 -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 5B9646C0C2; Mon, 23 May 2022 10:10:30 -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 D267FB811FF; Mon, 23 May 2022 17:10:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2863EC385A9; Mon, 23 May 2022 17:10:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325828; bh=dyxp/OnlY0m1FU8iZJRv1ipNM6H0VBNRarR2JtfRlCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GOn1DBM9irUNQ9kB/mySd8xMSEKXHpcjWt9NZYB+S/j4y6AubRpbqfFTCfElKV/hl rzfkyRti2QKgoDHs5ckW+io/0XkT3rGjFssWaqpAWgxZosTOtEPDGN6n53AZQHlD45 RqCb8RKZWaxIblpMrugVzpgR4uacZb+KS+M9dcd8= 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 4.19 24/44] net: vmxnet3: fix possible NULL pointer dereference in vmxnet3_rq_cleanup() Date: Mon, 23 May 2022 19:05:08 +0200 Message-Id: <20220523165757.555117477@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165752.797318097@linuxfoundation.org> References: <20220523165752.797318097@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 edf410cb74dc612fd47ef5be319c5a0bcd6e6ccd ] In vmxnet3_rq_create(), when dma_alloc_coherent() fails, vmxnet3_rq_destroy() is called. It sets rq->rx_ring[i].base to NULL. Then vmxnet3_rq_create() returns an error to its callers mxnet3_rq_create_all() -> vmxnet3_change_mtu(). Then vmxnet3_change_mtu() calls vmxnet3_force_close() -> dev_close() in error handling code. And the driver calls vmxnet3_close() -> vmxnet3_quiesce_dev() -> vmxnet3_rq_cleanup_all() -> vmxnet3_rq_cleanup(). In vmxnet3_rq_cleanup(), rq->rx_ring[ring_idx].base is accessed, but this variable is NULL, causing a NULL pointer dereference. To fix this possible bug, an if statement is added to check whether rq->rx_ring[0].base is NULL in vmxnet3_rq_cleanup() and exit early if so. The error log in our fault-injection testing is shown as follows: [ 65.220135] BUG: kernel NULL pointer dereference, address: 0000000000000008 ... [ 65.222633] RIP: 0010:vmxnet3_rq_cleanup_all+0x396/0x4e0 [vmxnet3] ... [ 65.227977] Call Trace: ... [ 65.228262] vmxnet3_quiesce_dev+0x80f/0x8a0 [vmxnet3] [ 65.228580] vmxnet3_close+0x2c4/0x3f0 [vmxnet3] [ 65.228866] __dev_close_many+0x288/0x350 [ 65.229607] dev_close_many+0xa4/0x480 [ 65.231124] dev_close+0x138/0x230 [ 65.231933] vmxnet3_force_close+0x1f0/0x240 [vmxnet3] [ 65.232248] vmxnet3_change_mtu+0x75d/0x920 [vmxnet3] ... Fixes: d1a890fa37f27 ("net: VMware virtual Ethernet NIC driver: vmxnet3") Reported-by: TOTE Robot Signed-off-by: Zixuan Fu Link: https://lore.kernel.org/r/20220514050711.2636709-1-r33s3n6@gmail.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/vmxnet3/vmxnet3_drv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c index 1df67c899d4f..a57ea3914968 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -1586,6 +1586,10 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, u32 i, ring_idx; struct Vmxnet3_RxDesc *rxd; + /* ring has already been cleaned up */ + if (!rq->rx_ring[0].base) + return; + for (ring_idx = 0; ring_idx < 2; ring_idx++) { for (i = 0; i < rq->rx_ring[ring_idx].size; i++) { #ifdef __BIG_ENDIAN_BITFIELD -- 2.35.1