Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1145911pxv; Fri, 9 Jul 2021 19:28:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwX52WHDKxmMugxyvQ1zcu3hlulb6X3RZOk48WnLzv2rPkUAs52ZtQjGhVlmCPRry7lt93/ X-Received: by 2002:a05:6402:1d56:: with SMTP id dz22mr51400569edb.376.1625884113212; Fri, 09 Jul 2021 19:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884113; cv=none; d=google.com; s=arc-20160816; b=ahNlZXX+cGaBHTbktzFaDfxdZG3U+1S68l1XGt/E+XzrdllPC3mb5oBi899N7VlkFS 8gXK8LHiwGL7GPyN/rOjPR/el0GcA2PEO4sUuLf6+XhW/pb/eubELY+gpqp4xHd3kSCV jqfeOf1zP9OR9U337r4PyOQwsg4lwuf0KStHwcAWQScKI2Xl9gqlWXg5oBvQF7KXRhFo Wc892jy1XmrIJpZOtqJAoEixphcqqtV6T0xfvphjGUz32irqLjlofkXAg7Qv1vvEjt8l FhGIJQrms5+a2UTnsAAPKteYgboF4Jb/7FxTLqPbEvNupcoT3GrKxqRSB2FoYzd6N4f9 hTeg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pwrG2as4zStaDk4PrDsGjorxICULzhFlSqkyt5e+knM=; b=OnCKFsXEmR4C6/XzN1mKoUamqnqGQMeLHGTsuXWX9RFSViT0Js2pgLSdexC9csU4Iw cAULnsJd3u/48qZk2g7PMVfmkAawEogXJSgUIv7A/lDIh6fsZmgDjmBJcI0vWX6jfDpZ ePNaPapF1VrVtx7oli5W4o1dAoi354qGbuRcNm1OB9c0FXQ0saCOyyLjzdrXgYxcbV19 kW1ogSElNjXAQkmWiffB+lZwZeBKu87h8cPL8IUDAAbkkCexVN3t+8g8cCi5n2lOvygn olBPGZTcT9520PbXeTvtBfHR31gDkIzEy5dBy1sTuD/+5KB2Cij8Gc5zCNBXiz+lsX3V obxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RWtic0tq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l14si9411093eji.305.2021.07.09.19.28.09; Fri, 09 Jul 2021 19:28:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RWtic0tq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232735AbhGJCaA (ORCPT + 99 others); Fri, 9 Jul 2021 22:30:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233527AbhGJC1m (ORCPT ); Fri, 9 Jul 2021 22:27:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB50C613F0; Sat, 10 Jul 2021 02:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883883; bh=4DYIJkBBNEgbBtLUIK/WIpKbeZB5/9WqbXBS6E8Bh54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RWtic0tqHD5v9JvKJWM6dJDYH1M5i4Pr1rKs8Q02qcbJaBKGHO8T6ViH5MWrJN+rB yzWOmYTI0T6IFqdI/T4hHO/FAYNjyiRXLRfQueOPU9dpF1O41nGHPMrXt28rFIQ9LY KFMQJ89tW3KaUbiXG8NCSgzFy6FmAHPFy0Hb23BLvH8f6H3zo27ehuYSvZWMwnln6l I1eBMG4iuuXm3lRYxHjScvU0QZ66kSdlmnA7XcvvnWSC/0vM+RC867tmi0QrmQzVJc gype1Qf4/AVpVgGon92XanuWiZ3VMl9Hzz42lw6MvOw+69iV/54zWa3YXSnFutFq/U yu8gS3oXfZwKA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lv Yunlong , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 5.10 11/93] misc/libmasm/module: Fix two use after free in ibmasm_init_one Date: Fri, 9 Jul 2021 22:23:05 -0400 Message-Id: <20210710022428.3169839-11-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 7272b591c4cb9327c43443f67b8fbae7657dd9ae ] In ibmasm_init_one, it calls ibmasm_init_remote_input_dev(). Inside ibmasm_init_remote_input_dev, mouse_dev and keybd_dev are allocated by input_allocate_device(), and assigned to sp->remote.mouse_dev and sp->remote.keybd_dev respectively. In the err_free_devices error branch of ibmasm_init_one, mouse_dev and keybd_dev are freed by input_free_device(), and return error. Then the execution runs into error_send_message error branch of ibmasm_init_one, where ibmasm_free_remote_input_dev(sp) is called to unregister the freed sp->remote.mouse_dev and sp->remote.keybd_dev. My patch add a "error_init_remote" label to handle the error of ibmasm_init_remote_input_dev(), to avoid the uaf bugs. Signed-off-by: Lv Yunlong Link: https://lore.kernel.org/r/20210426170620.10546-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/ibmasm/module.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ibmasm/module.c b/drivers/misc/ibmasm/module.c index 4edad6c445d3..dc8a06c06c63 100644 --- a/drivers/misc/ibmasm/module.c +++ b/drivers/misc/ibmasm/module.c @@ -111,7 +111,7 @@ static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) result = ibmasm_init_remote_input_dev(sp); if (result) { dev_err(sp->dev, "Failed to initialize remote queue\n"); - goto error_send_message; + goto error_init_remote; } result = ibmasm_send_driver_vpd(sp); @@ -131,8 +131,9 @@ static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) return 0; error_send_message: - disable_sp_interrupts(sp->base_address); ibmasm_free_remote_input_dev(sp); +error_init_remote: + disable_sp_interrupts(sp->base_address); free_irq(sp->irq, (void *)sp); error_request_irq: iounmap(sp->base_address); -- 2.30.2