Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1149925pxv; Fri, 9 Jul 2021 19:36:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTeEaYRj8KcEYpOGp3Asg9Yj6dwJDk56XaFa9RzSOeDwZCvUskGpLNxLyGXLDYDetlmL51 X-Received: by 2002:a17:906:2590:: with SMTP id m16mr40673395ejb.265.1625884598200; Fri, 09 Jul 2021 19:36:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884598; cv=none; d=google.com; s=arc-20160816; b=mDOC6VNKSnOs+EScha/ydavgcAJKIgwCIpE7nEJxCHqTu0iHQVZPM7h80cIiSe7ykK Cud3QzGb1c+SI+P6C7LnZp9tyrD1/aFgU7SJR53RNSPYP7DjDLJAPEgD221G62yjUR6P 8B9WR/gGDSLk+H5bH9JB5FKf4vCn6qfDLi1wBrl0n8gBPptWP3K2MzGX3qMDgk6jSmdv sSjsqUlReB78YzxRU2uV26EsONFmZxhf71snmPAebfzFxnCP4J2uhA4yOS2Wk0L0Lf0Q de1XS/0sijHnGBBUymVGbIUnV9p+9hOujDqPVhnJM4LGQoYwoCVDwxYjCJiLRdCLqZ1P ZjBQ== 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=HQjnyAiTDia9pDhTeWkuZCqqhOlfluZxRGBmvxgne6g=; b=DGq0DetGNAsT3LUra801g6zxnLrubSbSoRpSsYveHDbuliz1gCt4zcCh5nBfmTO573 giBAPe7QhtcOG356rKEc0nXVOB4gTldSmeEEYKWjukyZTPnQKJ5ECW6N3y20i4eTEbZC wgdiWhA7vRAsfqIkbl4/jM4Nz+iOCGUryFgn1POih8XYclsLCDXN3tvvmAUxW/ID7edG BvzQz7eJdbMVbrThwW0mufKPPQDHzeEAxUEnkSu2peXqnQ15ifhYm6HpdYnAgldraq2e 5Sfrs4bk775PamCSX7zgUoEt27GYtzcu34ZVb9fbccy/6wpwrTwyVt1f0IGmWMvAMdSw 3jeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jy1syUmQ; 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 w18si9111492edd.302.2021.07.09.19.36.15; Fri, 09 Jul 2021 19:36:38 -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=jy1syUmQ; 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 S234273AbhGJCiJ (ORCPT + 99 others); Fri, 9 Jul 2021 22:38:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:53324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235652AbhGJCe5 (ORCPT ); Fri, 9 Jul 2021 22:34:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7DCC613FC; Sat, 10 Jul 2021 02:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625884327; bh=WNLCTHcArbCKBQSrN3A9yasW6vH5jkHjhis2KN5BEow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jy1syUmQZYR8W+yXGUjvbS25JyOH1gZ2TBEDqf2qpkuai0WhgvMXNSbVFyoAKkq6s tsFR6qO/c/gJFQ39+hUGtgztYLDC7pAjTRQu4EVKvpTcYsDnj7kikG0k0fZcfLqWto 6zApKPr3875e39n/wjsoKajROV17c/TkzuJmWUb5sjIxW6fI67QS8z/R8/kdCzfCLB hCO7CDCO41q6JtDdTTnGyrzCR493l8rShHYPV2qSN+VBtOjpP4/x5OoMcSPaotUtoT cJWFUyAMGaPLwurqNwalcHXPO9WgS2dnzAAXRapKE6lU/7rCB+9PjQsEC2dII7cXVF NVSTmuHaTTrBw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lv Yunlong , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.19 02/39] misc/libmasm/module: Fix two use after free in ibmasm_init_one Date: Fri, 9 Jul 2021 22:31:27 -0400 Message-Id: <20210710023204.3171428-2-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710023204.3171428-1-sashal@kernel.org> References: <20210710023204.3171428-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 e914b8c80943..9f8344169845 100644 --- a/drivers/misc/ibmasm/module.c +++ b/drivers/misc/ibmasm/module.c @@ -125,7 +125,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); @@ -145,8 +145,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