Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3665038lfo; Mon, 23 May 2022 10:45:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDiTuggS7g5fpdllMjPS2uHtB0ly/+/hrNtpdKyHKKSRuIuYx+h/fTJAnYioiXsXgFcb6n X-Received: by 2002:a05:6a00:2442:b0:4fd:8b00:d2f with SMTP id d2-20020a056a00244200b004fd8b000d2fmr24452444pfj.39.1653327945970; Mon, 23 May 2022 10:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653327945; cv=none; d=google.com; s=arc-20160816; b=bFgL3lWnPMVFGIGLxlUHy/zcVZUJVOq/dKzQiIpavpAJ2r/0tME4qzW/ICBfF9OkJd plICHbcfFZ57MpHQcqDz5qftfLVPKddSXpj9xCQdy1ni4321I3BuxkjvgfCPfwwSjJtx cvnCZVDOuNluYLq+tw5v2P8FPPIpo3hDF+dUqGpzZGWnJnhRXz+w+kd5w5hkjoRfoL1X TWhDTlQP0WOUOfs5rBdgbEgG3ineOAANjjfi+Oc/og+Xxj9NpOlD0k9PK48tmCA/lFDi FFDjsP2wM9+5oBpJRxBr0Py9x0t+w7KcJmmvsmGCsNbZo8JPjJF1GK+IsWg85w3gnVBL Al6A== 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=2gOX4iGI/6D/v9fOTtxT/sEqvyDLpgLmAryjFFrvskY=; b=IKXSlHSI1pP+Q5S0U0shYj2R5MzDdJ9MSiaxyZHrOX1vR/XOWLWBbp3PgrQS51Qwar pUApNE0UBaosPnXLDVRgHUecntNoAjo4E+F7faF4ZaRozN54993xwexaMmMOZeN7FudQ 9kDKcevbiRlfj/18jPDRcloMhNWtXnKAqfOno0jP8RhLTDXSJI1jLywfFstoJPp8zG1m 0HwBI98Tx1reZXHZTQIkDJE1bb5qapVWT0G3T3s7UmtjPXtXchUXO7k8yIhFFM9HHHaj db9UnN/ldCKVF2hK0kVBcL4mc5F7PX3+laTGKvcqe41dswBX5NajZbaUrNUBp4Pd1/me DIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HsuZBP40; 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 r3-20020a17090a454300b001e04960ab84si4755243pjm.131.2022.05.23.10.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:45:45 -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=HsuZBP40; 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 485CCD412C; Mon, 23 May 2022 10:45:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244060AbiEWRnU (ORCPT + 99 others); Mon, 23 May 2022 13:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242619AbiEWR1t (ORCPT ); Mon, 23 May 2022 13:27:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FEA1814A8; Mon, 23 May 2022 10:23:43 -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 dfw.source.kernel.org (Postfix) with ESMTPS id F24C861523; Mon, 23 May 2022 17:13:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0989C385A9; Mon, 23 May 2022 17:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326008; bh=EzwhwizX+Oc7mpCro2d+6Hzgld2XnK+PrPAtrQpl7UI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HsuZBP40IhysrV0wMcmitjvUQBzN8v0Sth7bKJToMTJWodCtn7hVeIuMBBWkxbuGp zfCYWNcrhTj0l+Qs04ioakKWXBmnqbKJNk6m/J+8oDEnaDWELxJAX7fCUnHx5FlPLW dIUal5wYggovoNJvEfyHcJUJWT48TY4JotAmpGDg= 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 39/68] net: vmxnet3: fix possible NULL pointer dereference in vmxnet3_rq_cleanup() Date: Mon, 23 May 2022 19:05:06 +0200 Message-Id: <20220523165809.048498932@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 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 b71a019e9867..609f65530b9b 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