Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3682023lfo; Mon, 23 May 2022 11:16:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqagAqhb+XLAop1ZURFrfwGUFToxPhkoXSdeEanwpA+2nlv7dY0EEybuqbbPZK3UqerFc8 X-Received: by 2002:a17:902:d716:b0:15f:179c:9817 with SMTP id w22-20020a170902d71600b0015f179c9817mr23637492ply.150.1653329802872; Mon, 23 May 2022 11:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653329802; cv=none; d=google.com; s=arc-20160816; b=U+BEnbPYoAwR5O/AKICaK7+yKkyNke/4aYjZOPLTnD9GCwxzOSzS6sbnSDoYoljGCB sjrCfO/ORWtge7zCEmp/rLjPg5gqklTm7nQnCoeAcW4DPIT+UoFoJ2OSjK5hI0Cila7z h4pB0m9VW0wYavpXVIdKJAAKFXekhoKrRmM9WdGpMrtTnMlx62jl9cctbUHGp89D2a4o OklTJ69IJwv6SuHjqaavmsi/66EBNCpwdXDrSqiP4mWoZAkiMjjpdITt4u8Khtqd0xXO ASAjgWdXsbOdYZKMFxOYEy2sz273q2XwPyY70/9Rp8hbVMlh2uLcZlx+8lBLhMZct9vZ LM2Q== 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=513wEmKLfBfiZ6yivR89Vp1dCiO+zDAYBilhccbfv3Q=; b=qJgwSEhhPcSeebEHBkfyqoF5vSOaR3/1cVSSu5oxZbktSs2v9suKOv8TgxOWbSeJj7 wgVKZfa1iocsPNIJstHwwETOj5z3VZop4E2RKvk/ujm5tWZvKD7s57DLVhtTPMAjVxAa 5vJcFpdZsuUDkFMrtyqVle6vQp1YkqwFOxMx40y4yTkE9SBH2zFvVSpf0Z7DErRqbk8Y qgP4s9siJoQPVITGscAx2xZg+hGD/5lJFRb4JoiHaU/ZTJkF6PvHkNL1Hc1CD04bucoi JckcTR7PPAoYFWO29wnCBd7L7j6nHSLnvSfaa8tgCMJIjCWJGL6rGM51vXu9E3meRnrY nkYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="EDT8/poG"; 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 b4-20020a056a000cc400b00512e59d9bf9si818084pfv.296.2022.05.23.11.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:16:42 -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="EDT8/poG"; 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 3F1599CF34; Mon, 23 May 2022 11:15:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245706AbiEWSIK (ORCPT + 99 others); Mon, 23 May 2022 14:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244233AbiEWRi7 (ORCPT ); Mon, 23 May 2022 13:38:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B33B79AE63; Mon, 23 May 2022 10:33:33 -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 D95D4B8120C; Mon, 23 May 2022 17:30:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39D91C34115; Mon, 23 May 2022 17:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653327046; bh=zxsQAHXdmuoDKua+gg1TS6/rAecG9TTZfkoQ7w4L2sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EDT8/poGN0Z1fDiHyhRig91ecRwgfJLRIjlnJqh0FZr6FPnhTPAkVcfl2xNU4aS38 Wz5Z/tBACFGquK9dxoq52/m5nvbDbE2xHmSxzGK8bd7VDsx7Zs92k7fnOXY1fTTUZq OjjXlS1j9Mm+y/0JrDivW38ABU+cI8E1SK/hQBAo= 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.17 094/158] net: vmxnet3: fix possible NULL pointer dereference in vmxnet3_rq_cleanup() Date: Mon, 23 May 2022 19:04:11 +0200 Message-Id: <20220523165846.847254158@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165830.581652127@linuxfoundation.org> References: <20220523165830.581652127@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 1154f1884212..93e8d119d45f 100644 --- a/drivers/net/vmxnet3/vmxnet3_drv.c +++ b/drivers/net/vmxnet3/vmxnet3_drv.c @@ -1668,6 +1668,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