Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1143931pxv; Fri, 9 Jul 2021 19:24:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGdDH6A3ctXikLU0ZNPuCXJcVwq6pc3RmwTgzSewLFFm/iK/ScZxXgNLeRHnRQaloQVGyx X-Received: by 2002:a17:906:c49:: with SMTP id t9mr13189618ejf.405.1625883844510; Fri, 09 Jul 2021 19:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883844; cv=none; d=google.com; s=arc-20160816; b=Hom36ZbyqVRCt5Ky7U8o/9Z95clAcwTQYZ1zBme8ot9e0t0RnbjK67lggBdPb9Wz/D 4Gd4Q8Ua1fzMF7nGs9pBN+VSEOwfrAv+wEIOTv3SMB/1fV9jXlbQZwO2noxnWQiN3TQv BV29o1m5Xdrrwqt7SKiAZrBCIbS+kZiyk/DTdG+6uzE7MA9QCfHBPRbwZASJP8kaTDdA ygi9NTj7S+byRR5ReDT5WwU2L8H7fq2vdex9QHc403jumNaW66sWzobRm33LFhzl0uxx 1xwaD7cRbCgEDBx0B2uFII87GsByQBN++fvEK1zP5PLC1WC56EbBsaD9FPqYGcuSFrDC EZqQ== 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=pNdu3k1oF30DXwkf8XJL9vq+jtOFrQfrLc3RYA43JBAy/IrVkUZy2kV6xGm/4cnwTs cARfEc6iWtZ5+rg8BxAetwx8p24uAKHbfuyDRIGFfsPnsy4Ewn7z7QphvmY+CcovTyYS NruK1iHkMQ5t2lr/PmoQevXAu8hHHR7zFBKjPD1nwoXFyqgU2iSkoKeItIHIrjvKbmAP FkSJbf0k0WyeUWMu8Yntbi2+7hWqfopiiaHrwXDYg8ez5vIRHK/3KO721qPD4HvkvQBa 6E1cL3TpELaC3UFUYchUsneMpFlQVwTLX4jMEIBuXqEBZ+BXWn3ga5p2kxBgIzqY9anT l+MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eyFl5hIU; 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 n8si9358590edr.350.2021.07.09.19.23.40; Fri, 09 Jul 2021 19:24:04 -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=eyFl5hIU; 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 S232553AbhGJCZM (ORCPT + 99 others); Fri, 9 Jul 2021 22:25:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:41714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231883AbhGJCY4 (ORCPT ); Fri, 9 Jul 2021 22:24:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1723F613D9; Sat, 10 Jul 2021 02:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883732; bh=4DYIJkBBNEgbBtLUIK/WIpKbeZB5/9WqbXBS6E8Bh54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eyFl5hIUXi0DZdsiGwDLVOoQ2mi0YkGgdCEBrhtATSxK0Jw/PyRKHY5VRMdn18NJ2 Ur71vyL6l3blM2lYjeXONBXdy1LoGEO69l0the5eQLnMbvyVjqgHsllbieDuGvNfj5 MxPwH9cnAwKNg90aGzBJeXF2K0xOJ6D6ZlKwXdURHL65jUdUwSU7yQnu5OsUqtZk0y 50JaeLh2eMC/JhlUFx9+KOPVE2y1yjXmrlui7/3reSr3TM1iriUA1Uk4AJQ9vExRyW QVFHQx+/fx76McAOI91X6DMQW013s9YtwZYCY0dUooogjd+/is497S9w255huOtkl6 gHhaKOcIfrwqQ== 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.12 012/104] misc/libmasm/module: Fix two use after free in ibmasm_init_one Date: Fri, 9 Jul 2021 22:20:24 -0400 Message-Id: <20210710022156.3168825-12-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-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