Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp170415rwj; Sat, 29 Oct 2022 00:54:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Y/K+eBOwmG0Gv2I80LEAmk6CvtqjAZN/ojChCH3Oxf6RkChbTrIgYi85m9h4LEnNm9Am7 X-Received: by 2002:a63:e211:0:b0:43b:f03e:3cc5 with SMTP id q17-20020a63e211000000b0043bf03e3cc5mr3153863pgh.256.1667030079449; Sat, 29 Oct 2022 00:54:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667030079; cv=none; d=google.com; s=arc-20160816; b=GQRtbsOcdAhJlc/at333EjQJ2eA+nRPqxHyx0Jz1ttPZNDBuf76drvLfzv2ZKLbJxQ +vEx90COPxwjeJ3Z7c3UGaZp6sxl2dqlWqDAjNplm3QDvOrCnu1CkvYiQWyGDR1n15W9 mm20yL9rmRNAShYfdqHVdMLmIAkajtG8B27z0grioWDaqt65Deg5iqvXr8PHNgtHKskA jPYYOFAaTi3xIAR+1RPnBGPgsgN6d3lJkHthbdIYSyK2YjeYC+daikINy7WofrzsZF41 gtLI3tgOTN89qwxBgEcFt9gchSGpegd8oBt6+uEcKEtHE6kc3ui4dhiNoqt2NXtP/vLx LmKw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=K2PKafCEYXHMfQ1Jc/mijsgMNFcp0Mg3fqjNMpvECbI=; b=meOL0/KLAWOocV3sIKz6jfhRXD/7xxkokgMoFhb5/dneL+u0EB/XqwVMYbnz0TbCDd sBSDxq1gpSOMDDwSq9diwpqiqsjs0tRXuUUCT0MtD/Ji3xwmkUFRFGyeYRWRu7t7FGaS pyRG9RKy6vDZp/9ZMCpzZRxS9ArIJ2oq2howmjfbHk1+nTCr4nK/+UIkUJNIuKNOp++D Cg78h9L/3gsGrh52Mte42LZszpnlb9Oc73LW+lFxiEaCjA7sKrPS+BBu3QMIZAlsKUE6 3v1uGn267ksmA6veXHag8jpZKTOsX/W+nUKjBiJNG/D0MgzKV2PozeUUgrD5o1fnvLuP GGzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=FMEoRNbD; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020aa78c08000000b00565e95c6dcdsi1026298pfd.356.2022.10.29.00.54.28; Sat, 29 Oct 2022 00:54:39 -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=@163.com header.s=s110527 header.b=FMEoRNbD; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbiJ2Hrg (ORCPT + 99 others); Sat, 29 Oct 2022 03:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJ2Hre (ORCPT ); Sat, 29 Oct 2022 03:47:34 -0400 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C5C0DB8C0D for ; Sat, 29 Oct 2022 00:47:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=K2PKa fCEYXHMfQ1Jc/mijsgMNFcp0Mg3fqjNMpvECbI=; b=FMEoRNbDFET3f1Gmh/iC8 MzOuoi8D2ngIRNibx9WNxR2+HU20n3rDX9YrLVjNmg6aQuahtKhAmMHSnU0ZlekO Jz2V1pTeS3Zxa2UGvA3LmLtNkRq9+jA9BCGLWUokmpm/a+PasfqRar473kYDQf5X 5enOQWFq/D+ycL3OPXITG0= Received: from localhost.localdomain (unknown [111.206.145.21]) by smtp3 (Coremail) with SMTP id G9xpCgDH1S1w2lxjInYWpQ--.13602S2; Sat, 29 Oct 2022 15:46:56 +0800 (CST) From: Zheng Wang To: nouveau@lists.freedesktop.org Cc: bskeggs@redhat.com, kherbst@redhat.com, lyude@redhat.com, airlied@gmail.com, hackerzheng666@gmail.com, alex000young@gmail.com, security@kernel.org, daniel@ffwll.ch, Julia.Lawall@inria.fr, linux-kernel@vger.kernel.org, Zheng Wang Subject: [PATCH] drm/nouveau/mmu: fix use-after-free bug in nvkm_vmm_pfn_map Date: Sat, 29 Oct 2022 15:46:54 +0800 Message-Id: <20221029074654.203153-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: G9xpCgDH1S1w2lxjInYWpQ--.13602S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Wr1xAr1UXF4kZr4fAw17trb_yoWDGrb_uF 1rXrnxWr95CryDWws8ZF43AFy2gan7ZFs2q3WSy3sxtasrXrsxWr9xZrn5W3s8AF1xKFyD G3WkXr1FqrnrWjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRKVbytUUUUU== X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQhCpU1aEDXIgKgAAsP X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 If it failed in kzalloc, vma will be freed in nvkm_vmm_node_merge. The later use of vma will casue use after free. Reported-by: Zheng Wang Reported-by: Zhuorao Yang Fix it by returning to upper caller as soon as error occurs. Signed-off-by: Zheng Wang --- drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c index ae793f400ba1..04befd28f80b 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c @@ -1272,8 +1272,7 @@ nvkm_vmm_pfn_map(struct nvkm_vmm *vmm, u8 shift, u64 addr, u64 size, u64 *pfn) page - vmm->func->page, map); if (WARN_ON(!tmp)) { - ret = -ENOMEM; - goto next; + return -ENOMEM; } if ((tmp->mapped = map)) -- 2.25.1